The Blog of Brad
Posts tagged code
Days of Code: Perl URL Shortener
Jan 24th
Today I got some work done; I didn’t get anything on my list that I made yesterday done, however I did experiment with jQuery (the Javascript library)… and now have an easy-to-use listing mechanism (to see the sum of all URLs in the database and the viewers logs). Take a look . With that you may notice something… I repurposed my ‘ol Brad-Zone.com domain name — it is shorter than bradarsenault.com (17 vs 13).
I’ve updated the project page at Code >> Perl URL Shortener with today’s code.
Code: Add sites to Social Links [UPDATE]
Nov 28th
[UPDATE] Changed base URLs for yFrog and TwitPic in the code. And edited the name of the yFrog image.
Since I’ve launched the redesigned BradArsenault dot com, I’ve been using a WordPress plugin called Social Links to show my social links (such as to Last.fm, Digg, Flickr, etc.) and this is how to add services that aren’t included by default.
First off, I’ll walk you through adding yFrog, however this will work with any site (that is publicly accessible with a user-specific URL)
First you have to get an image for the site you want to add. This could be from the favicon.ico file from the site (look for a link to that in the site’s source code) or from an image search. You then have to dress the icon up by cropping it, giving it a transparent background (if it has empty space in the icon), and resizing it to 16×16 pixels.
This was my design process in Pixelmator

Pixelmator designing yFrog favicon
You now have to upload this to the /images of this plugin’s folder with an easy name, like yfrog.php. The next step is to add the right code to the php file.
I use Espresso by MacRabbit for my code, however any raw text editor will work (Smultron, SubEthaEdit, Coda, the Transmit built-in editor, and many others will work for this). Open the sociallinks.php in the main plugin folder.
Look down the code for the
$definitions array
and add another definition at the end (so that you would be at
array(22
if you are starting from the stock code). Add this code.
/sociallinks/sociallinks.php
array(22,'yfrog.jpg','http://yfrog.com/%userid%','Enter your Twitter handle','yFrog'),
If you’re not familiar with PHP then you may need this help: The first quoted block (that’s an apostrophe there, it’s the non-shifted quotation mark) is the location of the image relating to that service, in this case yFrog.png. This is what we just edited and put in the /images folder of the plugin. The next portion is the link that this will go to when clicked to bring you to your user page, excluding the feature that uniquely identifies your account. Where you see %userid% is where your user name will be inserted by this script in the management page.
The next block gives you instruction as to what to enter, in this case yFrog uses your Twitter handle for your page. Finally, you have to state what this service is called.
Save. Now rename the old version of the script (sociallinks-1.php?) and upload the new script with the name sociallinks.php. Now you can go to the administrative page and select your new service. If there are errors, it’s most likely because you forgot a comma after each entry except for the last, forgot to close a quote, used the mismatched quotes, or didn’t use quotes at all.
fwiw here is what I have: (starting at line 67 of the PHP file)
/sociallinks/sociallinks.php
array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),
/*I added the rest of theses --BradArsenault (Nov 28/09)*/
/*Note the changes I made to TwitPic and yFrog -- these are the correct base URLs*/
array(20,'technorati.jpg','http://technorati.com/people/technorati/%userid%/','Enter your Technorati username.','Technorati'),
array(21,'friendfeed.png','http://friendfeed.com/%userid%','Enter your FriendFeed username.','FriendFeed'),
array(22,'yfrog.png','http://www.yfrog.com/froggy.php?username=','Enter your Twitter handle','yFrog'),
array(23,'twitpic.png','http://twitpic.com/photos/%userid%','Enter your Twitter handle','TwitPic'),
array(24,'qik.jpg','http://qik.com/%userid%','Enter your Qik user account','Qik'),
array(25,'wakoopa.png','http://wakoopa.com/%userid%','Enter your Wakoopa user account','Wakoopa')
);
If you want to use the icons that I used you can download them here (icons.zip)
Track My Snow Leopard Shipment!
Sep 1st
If you remember back earlier thi year I had a post about tracking a classic Mac keyboard and mouse from eBay… well I’ve since shipped a few items on Canada Post, Fedex, and Purolator and have come up with a few PHP pages to make these pages viewable on non-secure connections and to eliminate almost all scripting (at the very least make these viewable on cell phones). I will be releasing the source code to these pages for you to use, but in the meantime you can wait and watching with me as my copy of Snow Leopard ships across the country to me: [bradarsenault.com/track.php].
I’m now at DreamHost!
Mar 29th
I’ve been moved over to DreamHost for a total of… three minutes. If you’re interested, here’s what I did:
1. First I logged into my domain via GoDaddy’s SSH, I zip’d all of my files as allfiles.zip via the command zip -r allfiles.zip * This command says to zip (* means wildcard, so everything), the -r means to get subfolders, and the filename allfiles.zip tells it where to put the zip’d files.
2. All said and done that took less than a minute to do, but to transfer the 400MB files took about five minutes.
3. Then I had to login to DreamHost (they provided me with a temporary *.dreamhost.com address to do this, for free) and upload the allfiles.zip, which took just under an hour–so I then went to sleep.
4. This morning I found that bradarsenault.com has finally propagated through the inter-tubes to point to DreamHost, so I logged into bradarsenault.com via SSH and simply did the command unzip allfiles.zip. This took a few seconds and voila-all of my data is now at DreamHost.
5. Databases, I backed up my database last night at GoDaddy and downloaded it (via FTP) this morning. I then created a database at dreamhost with the same name (I know, Steve Gibson, but the passwords and names are REALLY long). From there, I simply chose the import button, uploaded the database.
6. Finally I had to edit the wp-config.php file to point to the new database.
So far, from what I can tell, DreamHost is much faster than GoDaddy, the load averages on my server are a lot lower, and everything feels snap-tastic.
CODE: Message Shown from List
Mar 20th
This AppleScript provides a simple function, if you need to show pre-determined text on your screen in a noticeable way, Quicksilver’s ‘Large Type’ function is great. This script allows you to enter the sets of text you need to show in the code then run the script to select the bit to show. To close it, select the “Cancel” button. Their is no reasonable limit to the length of the list. This script requires Quicksilver.
set myMessages to {"message 1", "message 2", "message 3", "message 4", "and so on and so on...."}
repeat
set selectedMsg to {choose from list myMessages}
if (selectedMsg as string) is "false" then --This is to detect if you pressed cancel.
exit repeat
quit
else
tell application "Quicksilver" to show large type (selectedMsg as string)
end if
end repeat
--you could have it do something here, after you've gone to exit the script.

