Migrating image links in WordPress database

2010.05.05

I have been wanting to migrate the blog from kosertech.com/blog to the root of my domain at kosertech.com.  When I first installed wordpress it wasn’t something I thought I could build out a whole site with and I didn’t think it was really mature enough to rely on.  I had visions of building out a static site in the root of my domain and then leveraging wordpress for ongoing updates.

I think wordpress has come a long way since I originally installed it so I made the move over the last couple of days.  The only issue that was a little tricky to resolve was that all my uploaded images in old posts pointed to the old directory kosertech.com/blog/wp-content/uploads which is a problem as I wanted to do away with that directory since I was migrating everything from inside the blog directory up one level.

I did some digging in the wordpress database and determined that the post content is in the wp_posts table in the post_content column.  The basic job to do is find all occurences of “http://www.kosertech.com/blog/” and replace them with “http://www.kosertech.com/”.  I did some digging and found the REPLACE command that is basically like a string replace from most programming languages.  You supply it the source text (in this case the post_content database column), the text to replace and the replacement text and it goes to work.

You can wrap this all up into the following query replacing my urls with your own and run this directly against MySQL via command line client or through a utility such as phpMyAdmin.

UPDATE wp_posts SET post_content =

REPLACE( post_content, ‘http://www.kosertech.com/blog/’ , ‘http://www.kosertech.com/’);

That query should return the number of rows that we’re updated.  I recommend copying your wp_posts table to a temporary copy and trying the updated on the copy first, and as always backup your database prior to trying any of these things.

Categories : tips  tools

TTYtter group support library

2009.06.26

As referenced in my previous post I’m a pretty big fan of TTYtter.  I won’t go into it’s advantages here you can find that information in my previous post.  I follow quite a few people so one of the first things I did when I started using TTYtter was to write a group add on library for it.  The previous post and the TTYtter site have good information on how to enable these libraries and also how to write them.  This library is pretty good size and performs quite a few operations that I thought would be a good example for someone else looking to extend TTYtter for their own use.

Operations:

  1. Custom commands for handling groups
  2. Bookmark of tweet id for place tracking what already was evaluated
  3. Filtering based on dynamic lists of users
  4. Add users to groups from inside TTYtter
  5. Remove users from groups inside TTYtter
  6. Add users to multiple groups

The easiest way to get started is to install this and get it going.  Download the library from svn and modify the one configuration item at the top of the library to set the group file storage path.  Reference the library from your .ttytterc file or use the library command line switch.

Once loaded you might want to have a look at the command set supported out of the library, there is built in help accessible from within TTYtter

/grouphelp
Group commands are as follows.

/group [groupname]
display stored tweets from group

/groups
list the current groups on the filesystem

/grouplist [groupname]
list the members of group [groupname]

/groupadd [groupname] [username]
add [username] to group [groupname]

/groupdel [groupname] [username]
delete [username] from group [groupname]

At this point you can add some users to a group via something like the following command which adds myself to a group called coders.

TTYtter> /groupadd coders vkoser
User vkoser added to group coders
TTYtter>

Once you have some groups built up it’s really easy to view them in TTYtter by using the /group coders command to list the last 20 tweets from that group.  That’s reasonable if your activly using TTYtter but it’s much more useful to use something like GNU Screen to view multiple groups and assign one screen section per group.  I typically set mine up with split windows and a large scrollback buffer configuration which lets me scroll back through pages of information.

I hope someone can get some value out of this as a learning tool and possibly expand it for your own use.  It’s not overly error proof as an add on for my own use but it works pretty well.  If anyone would like to submit changes or enhancements to the library just send them over to me or contact me on twitter and I’ll see about getting them migrated into the library.

The current release can be gotten here [TTYtterGroups.pl] from the svn repository.

Categories : tips  tools
Tags :     

extending TTYtter

2009.06.15

One of my favorite twitter apps is @TTYtter and you can download it from floodgap.com.  It’s written by Cameron Kaiser aka @doctorlinguist on twitter.  Now before we get all crazy and discount TTYtter because it’s not a fancy graphical application with sliding panels and lots of things you can click you need to understand why this is a great tool.

  • Scriptable (make your own search/harvesting tool)
  • Schedulable (run it, grab search output dump to a file etc…)
  • Automate posting information (use it to tweet your coffee pot status etc…)
  • Extensible
  • Open Source
  • Easily runs on almost all varieties of Unix

There are many other features but if your prone to requiring a mouse to interact with a computer this might not be a good fit for you.  It’s the idea of extensibility that I’m going to discuss in this post.  TTYtter has a really nice way to extend it’s functionality or override it’s default behaviors.  One of the things I like most is the ability to just change how it behaves.  If your using an open source client you could just modify the source but then your stuck with what to do when there is an upgrade you have to integrate your changes into the new version if they weren’t something that was accepted back into the project distribution.  TTYtter uses a user defined library that is loaded from your own file.  You can specify a library at runtime that will be loaded with TTYtter that gives a user the opportunity through the use of a little perl to extend or alter the default behaviors.  The big win for this architecture is if a new version of TTYtter comes out it still just loads your custom user library and you get all your customizations with the new version.

I’ve recently fallen back in love with iChat on the mac after finding a nice plug-in that allowed a unified contacts list and I’ve grown used to the time stamp format.  I wanted to add this time stamp format into TTYtter.  There is a default provided time stamp option on TTYtter but it places the time stamp on each tweet which really adds to the width of the displayed line.  I had the idea to create a time stamp that inserted itself every 5 minutes or so that would give me an indication of 5 minute blocks of tweets and also let me find my place if I’m away from my desktop for a meeting or something so I can scroll back to unread items.

Picture 9

You can see in the above screen shot there are two displayed timestamps in the form of “–Mon Jun..”.  The small library I’m going to discuss here inserts those time stamps into the listing of tweets.  This probably isn’t the most elegant way to handle this but it does give you a preview of the type of alterations you can do to TTYtter with your own libraries.

Lets take a look at the code:

$handle = sub {

my $delayInSeconds = 60 * 5;

#load the Lib_past with current time on first run
if(!$Lib_firstrun){
     $Lib_firstrun = true;
     print "Seeding timestamp generator\n";
     $Lib_past = time;
}

#if we have elapsed $delayInSeconds then print a time stamp
if($Lib_past < (time - ($delayInSeconds))){
     $Lib_past = time;
     print "--" . localtime time . "\n\n";
     print "\n";
}

#this allows TTYtter to handle displaying the tweet normally
my $ref = shift;
&defaulthandle($ref);

return 1;

};

The above code is fairly self explanitory but lets take a look at whats happening.  You want to save this code into a file, ichat.pl for instance might be a nice logical choice.  Then when launching TTYtter you need to specify -lib=ichat.pl and this will load your library along with TTYtter.  The above code will be called every time a tweet is received allowing you to customize and extend what happens at that time during code execution.  The last two lines of code are of interest because those two lines allow TTYtter to handle the tweet display as it normally would.  If you want to modify how the tweet is displayed you have full access to do so and override the default behavior.  This is useful for modifying how details are shown, for instance you could add the source client information if you like.  For this library we just want to display our custom time stamp so we’ll let TTYtter handle the tweet display.

You can read all about this advanced use of TTYtter at the website where it is documented.  I encourage you to play around with it it really is quite fun to get things working just the way you like.  I have a much more complicated library that allows me to group users and filter those users tweets into files.  It also allows for group management within TTYtter via custom /commands.  I’ll post details on that in the coming days and add it to the software download page.

Categories : tips  tools
Tags :     

PaceMate submitted to AppStore

2009.04.09

pacematewait

I’ve been working to learn some Objective-c for a few months now and finally got something put together that is fairly complete.  I’m often using a pace calculator for running at coolrunning.com but wanted one in my pocket.  There are already several really nice ones in the AppStore but this was more of a learning process for me.  I also added something I think is nice that lets you email your data once you entered it.  I intend to enter my run data and email it to myself after a run so that I can then transfer it to dailymile.com or other places I log running information.

At any rate I learned a few things about the application submission process as well as quite a bit about Objective-c and interface builder in xcode.  Interface builder was more of a hurdle than I would have expected.  Coming from .NET forms development background it’s really easy to drag a button onto a form and double click it to have it put my cursor right into the function that handles that button click.  It’s quite a bit more involved when using the xcode setup.

I also think that the AppStore submission process is quite a bit more complicated than it needs to be.  I’m giving my app away for free why do I have to do all the certificate requests and code signing when I don’t care about it being copied and freely used?  It seems like applications submitted at the free price point could avoid all that.

PaceMate is now in the review process and hopefully it will be approved in a few days.

Categories : Apple  iPhone  tools

Deconstructing Starbucks Gold

2009.01.10

I’ve been struggling about the decision to get a Starbucks Gold card since they came out.  My day job is working with customer loyalty platforms so I’m rather suspicious when anyone comes out with a loyalty program that you have to pay up front for.  The Starbucks Gold program is $25 per year (really 380 days) and I thought it would be good to take a detailed look at what you get for that and if it’s a good deal or not.  The first thing to consider is what are you going to get with Gold over regular registered card.  The regular registered card is free as long as you put some balance on it and register it online.

Standard registered Card Gold registered Card
  • Free syrup
  • Free soy milk or whip cream
  • Free refills on drip coffee
  • Free tall beverage with 1 lb whole bean purchase
  • Free AT&T Wi-Fi access for up to 2 hours each day in participating Starbucks stores
  • 10% off most purchases
  • A free drink when you purchase your membership in-store
  • Share your discount on friends and family day
  • A free beverage on your birthday
  • Exclusive offers and discounts throughout the year (no details given)
  • Free AT&T Wi-Fi access for up to 2 hours each day in participating Starbucks stores

So the main difference of ongoing benefit of the Gold card over the regular registered rewards card is the 10% off most purchases.  If your planning to get an espresso machine or coffee maker in the near future this is probably going to seal the deal on it being worthwhile to get the Gold card.  Also if you buy your whole beans at a Starbucks store it’s likely worthwhile to get the Gold card.  The Exclusive offers and discounts can’t really be factored in due to there being no disclosure on what those are so we really need to assume those don’t exist or have zero value.

Strictly from a mathematical standpoint the determination of if the Gold card would pay off for me is easy to calculate.  I purchase about 5 Cafe’ Americanos a week at $2.70 each for the Venti size.  Don’t judge me it’s close to my work and a guilty pleasure.  I’m no fan of the brewed coffee there but the Americano is actually a pretty decent cup of coffee and there are no other options for an espresso drink within 10 miles of my work place.

Lets determine how long it would take me to pay off the Gold card through normal purchasing habits.

$25 Gold Card fee – $2.70 for my first free drink with card purchase leaves $22.30 to make up.  For each cup of coffee I buy with the Gold card I’m going to get $0.27 off of each cup.  So if we divide $22.30 by $0.27 that means it will take  approximately 82.6 cups of coffee to pay for the Gold card.  At 5 cups of coffee a week that is 16 weeks just to make up the card cost.

There are 52 weeks in the year so that means I’ll be using my Gold card for 36 weeks after I’ve made up for it.  The remaining 36 weeks will amount to 180 cups of coffee and multiplying that by the $0.27 a cup discount comes out to a whopping $48.60 in savings.  This is a pretty decent deal even if I never buy anything but my usual coffee that I’m going to be buying anyway.  I’ll be picking one up on Monday when I stop in for my daily coffee.

You’ll have to do the math yourself on your own normal drink and frequency of purchasing to determine if it’s a good deal for you or not.  If you get a drink with Soy in it I think the upcharge for that is $0.40 so that may be more worthwhile than the 10% off you would be getting from using a Gold card.

To find out for yourself you can use our approximate Gold Card value calculator below.  Simply enter the coffees you drink per week and the price of your normal coffee and press the button and it will tell you the numbers for your situation.

[Coffee Calc]

The math is approximate due to rounding but is a good representation of your savings.  If you come up with a negative number then the gold card is probably not a good deal for you unless you buy lots of whole bean coffee or other items.

Categories : tips  tools

Microsoft Tag

2009.01.08

Microsoft released something neat today which is kind of like a QR code but links to an online database for the information.  I kind of like this better than trying to embed all of the information in the code.  This allows for a more rich system of tags that link to greater information.  The downside of course is you cant take a picture off of a poster in the airport and install an application without having some internet connection like you can with a QR code.

At any rate here is the first tag I made that links to the ceTwit download page.  I’m going to put it on the downloads page so anyone can just take a picture of it with their phone and direct link to the download page for the applications.  You can get the Tag reader software in the AppStore for iPhone or via gettag.mobi for all other supported phones.  

barcode

There is additional information about Microsoft Tag here at istartedsomething.com

Categories : ceTwit  iPhone  tools  winmo

Beginning Emacs in 10 minutes

2009.01.01

Emacs is a great text and code editor but it can be very confusing for someone trying to learn to use it.  After you read this you should feel comfortable launching emacs and opening a file, editing the file and using copy/paste.  Future articles will investigate installing add on lisp files such as a mode just for php or even a twitter client.  Installing emacs is outside of the scope of this article but I’m going to direct you to the following two distributions for windows and OS X users in case you want to try it but don’t have it installed.  Linux users should search out a tutorial for installing it on your particular distribution for Debian/Ubuntu its normally as simple as apt-get install emacs.

Before we begin a quick note on keyboard commands in this article as well as most emacs documentation.  There are special keys designated as M and C which typically are the Esc and Control keys respectively.  On older keyboards the M key was the meta key on most modern keyboards they can be used as the Esc and Control keys.  The M is commonly referred to as the Meta key and if your keyboard doesn’t have it just use the Escape key.  It’s a good habit to get into to use the Escape key anyway that way if you float from keyboard to keyboard you won’t be reliant on the meta key for quick command entry.

The easiest way to get started is to just launch emacs via your operating systems preferred method and then open a file.  To open a file your going to use the key combination involving the control key.  The Open File command is C-x C-f that means type control-x followed by control-f.  After the open file command is entered you will get a prompt asking for the filename.  You can either type the name of an existing file or a new name to create a new file.  As a handy tip you can use the tab key for filename completion.  You can for instance type “te” and hit tab to automatically fill in testfile.txt provided testfile.txt exists in the current directory.

Once you have the filename entered simply hit enter and it will either load or create the file and you’ll be ready for editing.  The next thing you should investigate is how to move around in a file.  Most emacs installations will allow you to use the arrow keys for movement but the basic method for movement involves using the control key and 4 directional keys.  There are also more complicated methods of moving by word or page/screen.

Now you have a good basic understanding of how to open a file and move around in it we can take a quick look at how to save.  Saving your file can be accomplished with the C-x C-s command, that is type control-x followed by control-s.

Copy/Paste is one of the things that I think confuses most people in editors like VI and emacs that don’t rely on a mouse.  Emacs is fairly straightforward for copy/cut and paste.  There is a fast way if you wish to just move an entire line do the following

C-k will cut everything from where the cursor is until the end of the line.  It looks like you just deleted the whole line but what you actually did was cut that text as if you were placing it on the clipboard.  To place the text back at a different location you can use the keyboard command C-y to yank that text back into your document.

To mark an area of text such as several lines or an entire paragraph you can use C-space to indicate the start of the selection area and then move your cursor to the end of your desired text and type M-w to copy that region of text.  If you want to cut the text rather than copy it you would use C-w instead of M-w.  Now that you have the text copied or cut you can use the same C-y to yank it back into the document at the location of your cursor.

To recap the copy a region and paste it elsewhere do the following:

  1. Mark the start of the region with C-space
  2. Mark the end of the region with M-w (that is usually Esc-w)
  3. To paste the text use C-y to yank it back into the document

If you want to cut rather than copy you can use C-w instead of M-w and when you type the C-w at the end of the region your selecting the text will be removed from your current location back to the location where you hit C-space.

If you get into trouble just type C-g a few times to abort whatever you have partially entered into the command area.  Another useful item is undo which is C-x u  that is control-x then ‘u’.

Getting started command summary:

  • Open File: C-x C-f
  • Save File C-x C-s
  • Cut a line from cursor to end C-k
  • Yank the clipboard back into the buffer i.e. paste C-y
  • Mark start of a region C-space
  • Mark the end of a region for copy M-w
  • Cut a region of text C-w at the end of the region
  • Exit emacs C-x C-c

The below image links to a quick one minute screencast of the information covered in this post.

You can find a handy emacs reference card here that I’d recommend printing out and keeping handy as you begin using emacs.  In future posts I’ll further explore using emacs for more complicated things like spell checking and special modes for editing source code and using split windows.

Categories : tips  tools
Tags :

EventBox – a quick look

2008.12.31

eventboxEventBox is a nice new piece of software for OS X from Cosmic Machine LLP that allows aggregation of several social networks into a single “box” or window.

It’s a native piece of software so it is fast and really well integrated into OS X.  It supports spell checking, grammar checking, copy/paste undo etc…  All of the things you would expect in a normal OS X application.  It supports Twitter, Facebook, Reddit, Flickr,  and Rss for now.  I’m primarily using it for Twitter, Flickr and Facebook.  I configured Reddit but the fact that Reddit shows in the overall unread count makes the unread items pretty useless on the dock icon so I had to unconfigure Reddit for now.

networksThe Twitter container offers a good bit of functionality with ad hoc searches and profile viewing.  You can enter an arbitrary user name to check on their timeline and then follow them or just read the past timeline.  I like to keep a search for @vkoser going as well as a few other searches that allow me to keep up with specific things on twitter that I’m interested in and these stay persistent in the sidebar as individual containers under twitter that allow them to refresh periodically.  All of the standard things are supported, direct messages, replies, retweets, a built in url shorten-er with several service choices and more.

There is an overall unread container at the top of the left pane that will display unread items in all of your configured services in chronological order.  The development build I’m using right now has a HUD also that will pop up displaying new items.  The HUD overall seems good but I think it needs some further tweaking to be great.  Below is a screenshot of the HUD as it exists now in the development build I’m running.

hud

EventBox is still in beta and there is a lot of work being done to it every day as they enhance it.  They are working on RSS syncing and support for del.icio.us, Last.fm and Orkut and many other things.

I listed a few dislikes below that I’ve been seeing after using EventBox heavily for a week and I have gotten some feedback from the developers that they are looking into them.  The development build I’m using now has solved a few issues that I was having.  Overall I love it and can’t imagine not using it now that It’s become part of my regular routine.  EventBox is currently on sale for $15.00 until the stable release comes out.  If your an OS X user I’d suggesting picking up a copy while It’s on sale.

Like:

  • Aggregation of all my social networks into one Box or Window
  • Spell/Grammar checking
  • Easy to use inline url shortening, paste and hit ctrl-j to shorten
  • Powerful searching
  • Arbitrary username viewing/following
  • Profile peeking
  • A really slick menu bar icon that expands out like rss bookmarks in firefox

Dislike:

  • Reddit.com grouped into total unread count
  • High CPU usage when the containers get lots of items in them 500+ and you scroll This has been taken care of in the latest build and seems to be acting normal compared to Mail.app and other applications
  • No multi account support for different twitter accounts (I’d like to see this implemented by just adding more containers on the fly for each account)
  • The HUD pops up even if EventBox is in the forground, this is probably just a bug in the version I’m using
Categories : Apple  Review  tools

UrlTweets is a great tool to summarize link containing tweets

2008.12.22

I’ve been thinking about better ways to view and keep up with my timeline on Twitter.  One of the things I do when mobile or busy is skip most of the linked content and just watch and participate in the conversations.  This usually leaves me with a bunch of links everyday that I missed.  I had the idea to write something to filter out and display only tweets from my friends that had URLs in them.  I spent an evening coming up with a prototype that ended up working pretty well and over the last few days I’ve evolved it into what is now UrlTweets

I wanted to just use Twitter search but there is no way to limit that to only your friends so it’s pretty worthless for a task like this.  I started off with twitter.class.php as a base and ended up heavily modifying it to do https access as well as support several new methods and paging.  If anyone wants a copy of the new modified class let me know.

I struggled a bit with how to do the authentication for twitter since they have no OAuth schema or anything other than a username/password combo.  I ended up storing the username/password on the client browser encrypted with a key that is only on the server side.  This makes for a secure situation as no user information is stored server.  I hope Twitter will soon roll out a better authentication setup because I know there are people that do not wish to use this type of setup due to trust issues with the developer and disclosing their username/password.

The end result is a simple form you can login to and get a list of your tweets from the past few hours that had links in them.  The script attempts to explode tinyurl links so you can see the original page address as well as display TwitPic pictures inline.

Future plans are for an automated process to run and collect URL’s as well as offering an RSS feed and digested email of the days links.  I am also toying with the idea of showing all tweets that didn’t contain a link so you can view only conversational tweets.

It’s an interesting way to categorize things and I’m enjoying working on it.  I know a few people are getting some good use out of it so it’s been fun getting some feedback on the project.

Categories : tools

Geotagging Photos on the iPhone for Flickr

2008.09.04

The iPhone 3g has a built in GPS so one of the neat things you can do with it is add location information to your photos (Geotagging).  The regular full size photos taken with the iPhone camera have the appropriate EXIF information embedded for location information to work but when you try to email photos from the iPhone directly to Flickr.com for instance the EXIF information is stripped off for some reason.

I tracked down a great application after some searching around that solves this problem.  My ultimate goal was to be able to take a photo on my iPhone and have it end up on flickr.com directly from my phone without having to sync to the desktop pc.

The application I’m using is AirMe from airme.com.  It offers the ability to take pictures directly inside the application and then upload them to a varriety of destinations.  You can upload to Flickr/Facebook and AirMe.

I was interested in uploading primarily to Flickr and getting my pictures to plot onto the Flickr map.  You will need to enable your Flickr map to be public if you want the photos to be automatically added to the map on upload time.

The setup of AirMe is pretty easy, you will need to create an AirMe account on installation, you can do this inside the AirMe app on first launch.  Once you create your account it will walk you through adding your upload destination.  If you choose flickr you will have to login to flickr.com and retrieve your access code to allow AirMe to have access to your flickr account through the API.  This is a security measure and just assures that you wish to have AirMe be able to do some management of your photos.

There are a few more settings you can select such as if you want your uploaded photos to be public on upload and if you want to use the location option.  There is also a selection to determine your photo quality on upload.  Choosing a smaller resolution will obviously decrease your upload time.

Once you take a picture inside AirMe you simply select Use Photo and it will save the photo and begin the upload process to your selected service.  Shortly after taking the picture it should show up on Flickr or the other destinations you may have configured.

There are a few things I think would be nice to add to AirMe, one is the ability to select pictures you have taken with the regular camera application and maintain the geotagging if it exists on the photo.  I’d also like to see the ability to do a crop inside AirMe since the iPhone has no zoom built in this would allow for at least a little fine tuning of the picture before it was uploaded.

This is a great application for my favorite price of Free and I think I’ll be getting quite a bit of use out of it.

Categories : Apple  iPhone  tools