Archive for the ‘CodeBin’ Category

Kill currently playing track in iTunes

Sunday, April 29th, 2007

If you are anything like me you have probably amassed an iTunes library that would take a nice holiday to wade through. With your iTunes on shuffle you might even run into some tracks you downloaded eons ago, after reading rave reviews on some weird blog, that on second thought sound pretty damn lame. I have always been bothered with iTunes’s lack of a quick way to ‘kill’ tracks. When you are in your library and the track you are listening to is selected you need to hit a key combo and click an ok button just to get rid of it. And when listening to a playlist the delete option is completely missing. So i set out to fix that.

What i came up with is a simple applescript that you can assign to a keyboard shortcut so killing that track is always just a keystroke away. Think that’s neat? Please follow along…

step 1

Download and unzip the Kill Track Applescript file.

step 2

Enable the script menu with the Applescript utility located in the Applescript folder in the Applications folder.

step 3

Copy the script to your ~/Library/iTunes/Scripts folder. (create the Scripts folder if it does not yet exist).

step 4

Open System Preferences and go to the Keyboard & Mouse preferences panel. Go to the Keyboard Shortcuts tab and add the Kill Track menu option for iTunes and pick a shortcut.

KillTrack.jpg

step 5

That’s it! The next time you’ll open iTunes you’ll see the little scripting menu icon in the top and it’ll have the Kill Track option there together with the keyboard shortcut. Next time you feel like hatin’ a track; hit the shortcut and kill it. I promise you’ll feel better afterwards.

The script automatically removes the track from your library and removes the file from disk.

KillTrack2.png

Disclaimer: this script comes with no warranty whatsoever, use at your own risk. Your computer might turn green and go poof if you use it.

Quicksilver Plugin for Jaiku (using Plazes)

Wednesday, March 14th, 2007

Today i finished the Jaiku Quicksilver plugin i have been using for a while but never got ready for general distribution. The script works in mysterious ways, or better put; it uses not only Quicksilver but also Plazes to do an update so you don’t have to set the location by hand and can simply type a message and be done with it. This of course comes with a price; you will have to have the Plazes plazer installed to actually use the script. This makes the potential group of users rather small but there are bound to be at least four people out there who find this useful ;)

Install guide!

  1. Download the Applescript file
  2. Make a folder called Actions in the folder ~/Library/Application Support/Quicksilver
  3. Copy the Jaiku Applescript into the Actions folder
  4. Restart Quicksilver (sometimes it is hard to get it to refresh)
  5. Add your plazes username and password to the keychain using the name http://beta.plazes.com (if it’s not already in there)
  6. Add your jaiku username and personal key (as the password) to the keychain using the name http://api.jaiku.com (you can get your personal key here). Use the application called Keychain Access for this and the previous step.
  7. You’ll have to click yes a bunch to allow the keychain to be used

There is a plazeless version too, follow the same steps as above only leave out the ones where it invloves Plazes.

User guide!

  1. Open Quicksilver (command-space)
  2. Hit . (period) to open text mode
  3. Type your message
  4. Hit tab
  5. Start typing Jaiku
  6. When you see Jaiku appear as the action, hit enter
  7. Go check you Jaiku stream to see if it worked!

Version history

  • v0.1, 14-3-2007, initial release
  • v0.2, 14-3-2007, removed default icon since it can’t be changed yet anyway

Roadmap

  • Icon selection
  • Maybe get Plazes data from feed (no need for a password)
  • Maybe release a plazeless and/or a standalone version (if anyone needs it)

p.s.
The script is ‘run only’ for now since not all of the stuff it uses is public yet. Full code should be available soon so you can go build your own versions. changed files to full source, adapt and multiply!

Plazesmap plugin version 0.4

Wednesday, April 26th, 2006

I just upgraded my Plazesmap Wordpress plugin to version 0.4 which upgrades the Google Maps API used to version 2. This will allow better satellite photos and map data where Google started offering these (parts of europe for instance).

Last.fm Recent Tracks plugin - version 0.4

Thursday, March 9th, 2006

I just updated my Last.fm plugin. Get the latest version here: Last.fm Recent Tracks Wordpress plugin

The caching behaviour has been changed to account for the fact that Last.fm sends an empty list after an x amount of time in which no new tracks have been added to the Last.fm profile. Default behaviour was to display “no recent tracks” when this happens which i have changed so that it now keeps displaying the cached list of recent tracks until a new list is available from Last.fm. (It will still display “no recent tracks” when your profile was empty to start with or an error prevented the plugin from getting your new profile data.) This seemed to be the preffered behaviour for most people but if lots of people want the old behaviour too i might make it optional (shout if you do). Have fun.

Plazes (Google) Map Wordpress plugin released

Wednesday, November 9th, 2005

Oh my. I just released my Plazes meets GoogleMaps plugin which takes your plazes location and displays the nice little Google map you can see here at the top of this blog. Disclaimer: Like the Last.fm plugin it’s very beta so it could very well make your server explode if you install it. Both the Last.fm plugin and this plugin are now available through the source repository over at wp-plugins.org.

Installation instructions:

  1. Download the plazesmap zip archive (version 0.4).
  2. Unzip it and copy the plazesmap directory over to your /wp-content/plugins/ directory
  3. Get a Google Maps API key for your weblog.
  4. Edit plazesmap.php and fill in you API key (mine won’t work on your site).
  5. Turn on the plugin in your Wordpress admin interface.
  6. Call the plugin with your Plazes username and password from somewhere within your templates like so:

<?php current_location('username','password'); ?>

And that’s it!

Todo:

  • Add caching of the plazes data

Changelog:

  • version 0.4: switched to google maps version 2 (more data & images!)
  • version 0.3: fixed Internet Explorer Javascript bug (thnx Andoni)
  • version 0.2: added offline and error handling
  • version 0.1: initial release

Branches:

Last.fm recent tracks Wordpress plugin

Tuesday, November 1st, 2005

13409
I hacked together a simple Wordpress plugin for Last.fm which uses the webservice feed to display the recently played tracks on your weblog. It’s based on the del.icio.us Wordpress plugin and uses a similar layout, the same caching mechanism (to a file in /tmp) and CURL to retrieve the feed.

You can download the plugin here: lastfm.zip

To install simply unzip and copy the lastfm.php file to your /wp-content/plugins/ directory. Turn it on in your administration panel. And finally call the recent_tracks(<username>) function with your username from somewhere in your template. i.e:


<li><h2><a href="http://www.last.fm/user/tizzle/">last.fm/user/tizzle</a></h2>
<ul>
<?php recent_tracks('tizzle'); ?>
</ul>
</li>

Make sure your webhost has installed the CURL library for PHP though otherwise this plugin won’t work.
If not you could opt to use this modified version of my plugin which uses fopen instead.

Version history:

  • 0.5 (16-05-2007) - small fix to account for changes in Lastfm XML format (Thanks Anthony!)
  • 0.4 (09-03-2006) - changed caching behaviour and using XML instead of RSS feed
  • 0.3 (01-11-2005) - moved UL tag generation into plugin
  • 0.2 (01-11-2005) - fixed a caching problem
  • 0.1 (01-11-2005) - initial release

Getting total results of a query

Monday, October 24th, 2005

There is a really simple way to calculate the total results a MySQL SQL query with minimal overhead. This saves an extra call to the database in which you calculate the total yourself. Just use SQL_CALC_FOUND_ROWS in your query like this:


$sql = "select SQL_CALC_FOUND_ROWS a.id, a.title,
from articles a
left join sections s on a.section_id = s.id
where t.name_short = '$type'";

// run the query (i use a db object in this example)
$db->query($sql);

As you can see you can use this in any type of select query. And then you can request the total like this:


// ask MySQL for the result total
$db->query("select found_rows() as total");
// assign to variable
$total = $db->get('total');

You still call the database a second time but the variable is already in memory so there is no overhead.

p.s.
If you come here more often you are probably not used to seeing code here but i in the future i want to try and share some more solutions to common coding problems on this blog. Mostly PHP and SQL, hopefully some more Ruby/Rails in the near future.