Tag Archives: Programming

My first Greasemonkey Script

flickr_logo_gammaIt’s been years since I did any Javascript programing, but I had a simple problem and decided to dive into it.

Like many of the little programs I write, I had a “problem” and wanted to solve it. I wanted a convenient link on the photo page to cut and paste the short URL of FLickr Images.  Look at this URL for a nice photo my wife took:

http://www.flickr.com/photos/s_d/3665619548/

As a URL goes, not too bad, but suppose you wanted to insert the link in
Twitter or Facebook? It’s a little verbose.  Wouldn’t this be better?

http://flic.kr/p/6zVfZ3

Yep, I think so too and so does Flickr:
http://www.flickr.com/services/api/misc.urls.html#short
http://www.flickr.com/groups/api/discuss/72157616713786392/
This thread showed how to do it: http://www.flickr.com/groups/api/discuss/72157616713786392/

The FlickrBase58 function in the script was written entirely by ‘Xenocryst @ Antares Scorpii’
http://www.flickr.com/people/antares/

Other than reformating, taken verbatim from link here
http://www.flickr.com/groups/api/discuss/72157616713786392/72157620673064673/

The Original way *I* wrote it was to retrieve the HTML, Parse it for
<link rev=”canonical” type=”text/html” src=”//flic.kr/p/6zVfZ3″ >

And use that link. While fun to write, that’s the wrong way to do it so I rewrote it to use the function written by ‘Xenocryst @ Antares Scorpii’ .  When installed on Firefox running the Greasemonkey extension, it will insert a link on the page on the right side just under “Flag your photo” that says:

The Flic.kr link is: http://flic.kr/p/6zVfZ3

This will allow you to right click the URL, copy it and paste into Twitter or Facebook.

Here is the script.

NOTE: I’m pretty certain it’s harmless, but use at your own risk. It’s hardly great programming and I’m sure someone else would have done it too, if not better.

Music I’m listening to right Now:
Paralyzer ” by Finger Eleven from the “Them VS. You VS. Me” Album.

Why I converted to WordPress

Wordpress ButtonsBefore anyone goes on a rant, I have no loyalty for any particular product or technology. In Movable Type’s case, I liked it for it’s convenience and the fact that it was written in PERL.

I’ve been a PERL programmer for years. If I need a new tool for work, I simply write it in PERL. In the case of my MTYahooMaps plugin (and my version of MTGoogleMaps), I wrote it because I was interested in Maps and integrating it on MT Blogs. It was fun to write, I learned a lot and It works.

With the last upgrade of MT to 4.X, my plugin no longer works. Neither did the CAPTCHA plugin, SCODE (YES, I use CAPTCHA , YES, I’m told it’s Not effective…). Frankly, as soon as I started to use MT 4, I was getting all sorts of comment SPAM that I wasn’t getting under MT 3.X so, I switched back. The bottom line is, CGI PERL brings my server to it’s knees. Likely my server was not configured as efficiently as it could be and the uptime and top command would show serious problems for my server. When using MT 3.x, my cpu would get pegged often enough that I would have to knock the webserver down just to use the box.

Under WordPress, I have yet to see the CPU pegged (Still working on getting MRTG configured too). Also, the user interface is a lot easier to use than MT. So easy, I find myself posting entries much more often.

With the exception of Nikon products, It’s all brand X to me. MT is a good product and Sixapart is a great company, I just feel like doing something different. Who knows? I may go back to it at a later date.

BTW: My brother is writing up the conversion on his blog, “Mostly Harmless“. He did all the work, I’m merely reaping the benefit. Also, he wants me to learn PHP and do some custom programming for WordPress.

Music I’m listening to right Now:
Misery Business” by Paramore from the “Riot!” Album.

MTGoogleMaps Test..

Hmmm, the New MT may break my version of MTGoogleMaps. Let’s See.

Update: Nope, I missed some PERL libraries.

Music I'm listening to right Now:
"Makes Me Wonder" by Maroon 5 from the "It Won’t Be Soon Before Long" Album. Just heard it on Z100. You can see the video here on Z100. As soon as you begin to hear it, you know it’s Maroon 5.

PERL Programing

PERLBy training, I am a programmer. Its something I enjoy and use to my advantage whenever possible. In this case, I had a repetitious task to perform and so I made a PERL program to solve it. 

This past Monday, while working from home, my DSL went out for several hours. Since I was stuck on site fielding questions from the Support team, I started tinkering with a program I use to copy Nikon NEF files from a flashcard reader. 

Basically, I like to sort my files in directories by camera model and date. That is, if I take a photo with my Nikon D80 on May 20th, 2007, I'd copy them into:

C:StuffStefanNikonD802007-05-20

Sounds simple, but suppose I put two weeks of photos on a 2 GB memory card? Doing it manually is a pain and I'm lazy. So I wrote a PERL program to do it.  

Here's How it works:

  1. Get a directory of the memory card (G:DCIM100ND80)
  2. Load the EXIF info from each file, one at a time
  3. From the file, determine the Camera Model and  Date it was taken.
  4. Get some stats from the EXIF Info.
  5. If the destination directory does not exist, create it (c:StuffStefanNikonD802007-05-20)
  6. Copy the file
  7. Go to the next file.

A colleague asked for a copy, so I niced it up, commented it, added command line parameters and I'm releasing it into the wild.

Prerequisites: PERL, of course and  ExifTool by Phil Harvey. Frankly,  Phil Harvey did all the heavy lifting here. He wrote a great PERL module and I'm only using a little bit of it. The rest is just simple file manipulation.

From a command line:
c:> perl copyNEFJPEG.pl -?
USAGE: copyNEFJPEG.pl
 [–from X:] (e.g. –from i:) Default = i:
 [–to X:somedirectory] (e.g. –to X:somedirectory)
                             Default = d:StuffStefan
 [–writecfg] Write config file to "copyNEFJPEG.cfg".
 [–nothing] Do Nothing, just show me.
 [–usage|help|?] This message.

Example:
c:> perl copyNEFJPEG.pl –from g: –to c:stuffStefan –writecfg –nothing

In this case, it will write a file called  copyNEFJPEG.cfg to the same location as copyNEFJPEG.pl and set the defaults to the command line (Assuming "c:stuffStefan" exists in advance). The "–nothing" parameter  shows what it would do without doing any copying (other then the config file that is) . Next time, you would simply use:

c:> perl copyNEFJPEG.pl

and it will just copy the files (Did I mention I'm lazy??). Once the config is done, you could just set it up as a shortcut. This program won't overwrite anything or delete the source files. It's fairly harmless, but if you use it, do so at your own risk. I've used this on Nikon NEF files and JPEG files. Likely it would work on CANON RAW files, but I don't have any to test. If anyine wants me to test with CANON RAW files, leave me a comment.

You can download it in a zip here

Music I'm listening to right Now:
"The Taste" by Five for Fighting from "The Battle for Everything". Five for Fighting is John Ondrasik.