Mostly about my amusement

Year: 2010 (page 5 of 13)

Easy Twitter Button for WordPress

Twitter announced their own Tweet Button and have provided a page for creating a button on your web site. You enter some info and you get the HTML code to add.

Extending WordPress has always been easy. You can add what you want via a plugin, or you can put the functionality into your theme’s function.php file.

I wanted to play around with adding this to my blog, so I went to their page and created my button. I then used the generated code as a template for what I wanted to do.

There is no way I’m savvy enough to write a plugin, but adding a filter to my theme’s function.php file is within my reach.

This is from an idea I got when I read WP Beginner’s post on how to add post thumbnails to your RSS feed. I used his code to do this.

function tweet_button($content) {
        global $post;
        // Your Twitter ID goes here
        $twitterid = 'jan_dembowski';
        $tweetbutton = '<div class="tweet-button">';
        $tweetbutton = $tweetbutton . '<a href="http://twitter.com/share" class="twitter-share-button" data-url="' . get_permalink() .'" data-text="' . get_the_title() .'" data-count="horizontal" data-via="' . $twitterid . '">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
        $tweetbutton = $tweetbutton . '</div>';
        // $content = $content . $tweetbutton;
        $content = $tweetbutton . $content;
        return $content;
        }
add_filter('the_content', 'tweet_button');

You can download the code via this text file link.

It’s not exactly user friendly, but it gets the job done. I wrapped it in a <div> so I can style it later. If you want the button at the end instead of the beginning, then comment out line 9 and un-comment out line 8.

It’s a fun hack for me and I am sure that soon there will be a plugin to do this. If you do decide to do this then make sure you backup your theme’s function.php file. Any typo’s or mistakes will make your WordPress blog stop working.

Coraline child theme

Have I mentioned how easy it is to use WordPress child themes? I can’t stress it enough, never modify a WordPress theme. Create a child theme instead.

I just converted a blog from an old outdated Cutline theme to a SVN copy of Coraline.  This is the WordPress.COM replacement for the Cutline theme.  The old theme bugged me for a few reasons, mainly it was the lack of basic features such as Gravatar support. I had meant to clean it up but never got around to it.

It took me less than an hour to make the switch. I retrieved a copy of Coraline like so

$ cd wp-content/themes
$ svn co http://svn.automattic.com/wpcom-themes/coraline coraline

This keeps an unmodified copy of the Coraline theme.  Once it’s in the WordPress.ORG website, I’ll replace it with that copy.

All I had to do was create a separate directory and create a style.css file with the following:

/**
 * Theme Name: Coraline for Stefan's Stuff
 * Description: Jan Dembowski's Coraline Child Theme
 * Version: 1.0
 * Template: coraline
 */

@import url("../coraline/style.css");

/* =Asides
---------------- */

.home #content .aside {
 border-left: 1px solid red;
}

The old asides had a slightly different styling.  I made copies of the header.php and footer.php files into my child theme directory and added an archives.php template. I modified one line in each of the copies.

I tossed in a rotate.php script and copies of the random banner images and I was all set. I did need to resize the old banner images from a width of 970 to 990 but that was it.

Child Themes are cool and once again I can keep the parent theme up to date without worrying about my changes.

Android or iPhone 4?

Do I get an Android phone or an iPhone 4? I’m in no rush to get a new phone but I do periodically suffer from phone envy.

I am a fan of easy-to-use technology. I currently own an iPhone 3G with iOS 4.0.1 installed. My phone has been jailbroken not because I have a “SOFTWARE MUST BE FREE!!!1!” itch, but because I wanted to tweek my phone in ways that Apple doesn’t support for my hardware.

Cool Applications, not so cool app store

One of my favorite apps on my iPhone is Camera+. It lets me take photos, make adjustments, and share those photos online. All within the app and very easily.

The Camera+ developers came up with the idea of modifying the volume up button to be used as a shutter button. This re-mapping of the button would only be done while the user is in the app. It’s a great idea and makes using Camera+ easier.  But the idea was rejected by the app store, so the developers created a back door to enable that setting.

That’s a sensible work around because the app store was apparently afraid that re-mapping the volume up key while in the Camera+ app would create confusion. Since the end-user would have to access a specific application URL, they would have to know what they were doing.

But as expected the Camera+ app has been removed from the app store. Rules are rules, especially when they are arbitrary, imaginary, mostly made up, and not published.

Do I really want to continue using a product that fosters an environment like this? I know that the Android Market Place has it’s pitfalls too but the Apple App store is driven by incompetence.

Android is becoming more cool

I know two people who have Android phones from Verizon.  The first phone I’ve seen is the HTC Incredible.  The UI is easy to use and makes the experience fun.

The other phone is the Droid X.  The display portion alone feels like it’s bigger than my iPhone 3G.  It’s not a small phone in comparison but the display is fantastic. It’s not as slick as an HTC phone but it is close.

How would a Gorilla design a better Gorilla?

I’ve also seen the iPhone 4.  The display is phenomenal but it’s essentially a better iPhone 3GS. It’s more resolution, more memory, faster CPU.  But it’s still an iPhone and I already have an inferior version right now.

Why just get a better version of the iPhone 3G? Why not get a new phone and try out the other guys? If Camera+ existed for the Android phone, that would go a long way to hastening my decision.

iPhone 3G slowness

Within days of my putting on iOS 4.0.1 onto my iPhone 3G, the phone started to crawl. Playing music was painful and using applications became a joke. For example doing anything with Camera+ (a very cool photo app BTW) would take minutes when it used to take seconds. Downgrading to 3.1.3 caused my apps to become responsive.

Last Wednesday I installed iOS 4.0.1 and did not restore my backup. I factory defaulted the phone and when it was plugged into my PC, I treated it like a new phone. This meant I had to copy my song library, apps, etc. from scratch. I recovered my contacts easily enough because I use Google Sync.

Next up I went into my iPhone’s settings app and turned off all Spotlight searches. If I could disable Spotlight 100% I would do it; this is one feature that Apple should have left on design table.

I also jailbreak’ed my iPhone and made the following changes:

  1. I turned on SpringBoard’s image backgrounds.
  2. I enabled Multitasking.
  3. I turned on the percentage battery meter option.

Why not? I ended up turning off multitasking because while everything ran acceptably, when you are out of memory, apps would not start properly. The background image is not as fast as a 3GS but still usable and makes the phone more attractive.

To make my modifications, I installed iPhone Explorer on my PC to copy and modify a .plist file manually. This is not not the safest way to do it. In the Cydia app store is an application called Features (for iPhone 3G) that installs in WinterBoard.

So far the performance has been alright. If/when I get an iPhone 4 the display and speed will probably startle me.

Some imaginary files are alright

This is probably a case of my not reading the manual.

I use W3 Total Cache not because I get a ton of hits. I run it because it’s cool and interesting. With the current 0.9.1 version it suggests that you add to your .htaccess file a section to handle 404 for missing static files. So non-existent txt, css, jpg, etc. will just get the web server’s 404 page and save on CPU processing via WordPress PHP.

Sensible, but robots.txt  is an imaginary file for my WordPress blog.  Requests to that file get sent to index.php and the output is dynamically created. Without the exclusion, that file URL always gets 404’ed.

Easy to fix. Right above the W3TC lines just add these lines to your .htaccess file.

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^robots.txt index.php [L]
</IfModule>

The ReWriteCond is not really needed, I’m just putting it in to be complete. If a request comes in for robots.txt it will be sent to WordPress for handling.

Why would the Chinese do that?

Reading the NY Times Editorial this morning made me shake my head.

China, which has abetted its neighbor’s excesses for too long, needs to ensure that the North’s bluster is only bluster. And it needs to tone down its own.

via Editorial – North Korea’s Latest Tantrum – NYTimes.com.

The North Korean government has successfully turned the carrot and stick idea on its head. Kim Jong-Il has successfully become the James Bond villain and knows that he’ll get more food, more fuel, or just more money.

While the Chinese government may be embarrassed by their neighbor’s behavior, there is not much reason for them to flex their muscle. Stability in the region is important but while it is the U.S. interests that does not translate into the interests of the Chinese government.

I do agree that the Chinese government could get involved differently, I just don’t believe they’ll do so because the west wants them to.

Use WordPress child themes

Before WordPress 3.0 the default Kubrick theme was called, um, “Default”. In the support forums people would update to the latest and greatest WordPress version and become shocked when their edits to the Default theme were lost.

It’s part of the WordPress distribution. When you override the WordPress files, those get included as well. Now with 3.0 the Default theme is gone and replaced with Twenty Ten. People will still make the mistake and modify the theme directly.

It’s not necessary and by creating a few simple file and directories, using a child them on your own is easy.

I’m a fan of the Hybrid theme and have been using a child theme already. The Vigilance theme caught my eye and I thought I’d give it a try. It was even easier when I located their instructions on how to start off.

1. Start with a pristine copy

I downloaded a copy of Vigilance from the Theme Foundry website and extracted it to my wp-content/themes directory. The version on their website is 1.51 which is slightly more up to date than the version on WordPress.ORG’s site.

2. Create your child theme directory

In wp-content/themes I create a directory called mostlyharmless-vigilance and extracted the files from this zip file into it. This is outlined in The Theme Foundry’s instructions.

3. Modify the CSS on the child theme

In the child theme directory I modified the style.css and added  a few lines:

.center-ad { text-align: center; margin:10px 0 10px 0; }
ul li.widget ul li a {
 display: inline;
 padding: 0;
 background: none;
}
embed {
 background: #fff;
 border: 2px solid #eee;
 }
#wrapper {
 background-color: white;
 border: 1px solid #ccc;
 padding: 15px;
 margin: 25px;
 margin-left: auto;
 margin-right: auto;
 border-radius: 10px;
 -webkit-border-radius: 10px;
 -moz-border-radius: 10px;
}
body {
 background-color: #ecf1ef;
}

This was to do provide me a CSS class to

  1. Provide a class to center my 2 ads
  2. Modify how the sidebar links look
  3. Put a border around and embedded videos
  4. Mess with the wrapper ID
  5. And change the color of the body background.

Nothing dramatic and the rounded corners are very 2004.

4. Modify the child theme’s functions.php file

My child theme has one useful line in it like so


php
$GLOBALS['content_width'] = $content_width = 600;
?>

I use oembed to insert YouTube and Vimeo videos into my posts. By adding this line, the embeds become 600px wide when the content supports that.

5. Start modifying files (if you want to)

The Vigilance theme will display that posts featured image if it exists. I comment out that line in index.php to disable the from happening. I copied index.php from wp-content/vigilance into wp-content/mostlyharmless-vigilance and edited line 15

<div class="entry clear">
<?php if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail( array(250,9999), array( 'class' => 'alignleft' ) ); ?>

and commented out the if function.

<div class="entry clear">
<?php // if ( function_exists( 'add_theme_support' ) ) the_post_thumbnail( array(250,9999), array( 'class' => 'alignleft' ) ); ?>

Next I copied the header.php file into my child directory and modified the second line DOCTYPE from strict to transitional. Some plugins I use look better in transiti0nal.

Last, I made a copyof single.php and modified it to insert my second ad.

6. Upgrades wont worry me now

The whole point of this exercise was to make changes to the Vigilance theme while not touching the Vigilance theme’s files. When an update to the parent theme comes out, I won’t have to worry about what I’ve changed.  The three files I have modified are easily determined and simple for me to support.

If you only want change the CSS, then it’s even less work and you can skip step #5.

SNIPER: Ghost Warrior

I now have a game to replace the sniper FPS that I play the most.

The FPS Sniper Elite is one of my favorite all time PC video games. As a World War II American OSS sniper, you crawl around parts of Germany and execute missions.  These missions need to be performed covertly and mostly in silence. Unless you got them into a long killing field, simple numerical superiority meant that if a squad of Germans or Russians rushed you (the sniper) then you died.

It even had a follow the bullet camera mode for those really good shots, complete with a range indicator.

The game was great but it was obviously designed for an original XBox in 2005. The graphics are dated and the AI is repetitive. I’ve played it so often that I manage to quickly wipe out the enemies and accomplish the mission.

My buddy and fellow Sniper Elite fan recommend that I get SNIPER: Ghost Warrior. A quick visit to steam and the game was purchased and installed in no time.

It’s got everything I like about Sniper Elite but it’s a 2010 game taking place in South America. The graphics, sound, and missions are great fun. When you die you get to replay the mission and target the bad guys that you missed.

Here’s a scenario I just did.  To get to a light house I tried to crawl and make my way to my destination without engaging any enemy troops. After getting shot up and compromising the mission, I realized that troops were paired into 3 groups and I could kill them off without alerting anyone. Once I got to the lighthouse I was able to wrap up the mission.

I’ve only played it for  about 2 hours but I really like the game and should have it wrapped up in a couple of days.