The Big Picture Analyzer

One of my favorite blogs that I follow is The Big Picture. Its a collection of amazing pictures. Make sure that you go into each article, that single picture is only a teaser and often collections have over 30 images.

(JOERG KOCH/AFP/Getty Images)

At the Big Picture it is very common for commenters to list the numbers of the images that they really liked. This intrigued me a little bit. Also, the comments on the main page are limited to just
100 comments, when there might actually be over 2000 comments on some collections.

So, I wrote a Ruby Script that I call bigpicvotes that takes in the URL to a Big Picture site and analyzes the comments to make a guess at what pictures were voted for the most!

bigpicvotes usage

Above is a sample usage on an article with now over 2600 comments. Notice that the URL you provide can be either the “all comments” URL or just the URL with the pictures that you are likely to be looking at. Also, the usage allows for a second optional parameter. This is to show the top N images instead of defaulting to the top 10.

One last thing. To use it you will need the Hpricot gem. That is simple enough to install:

shell> gem install hpricot

Again, the script is available here: bigpicvotes

Stack Overflow – Edit Summary Quicklinks

I requested a feature to make the few edit summary suggestions clickable. I, like many developers, don’t normally let my keys leave the keyboard. However, this was one case where I felt making those suggestions of “corrected spelling” and “fixed grammar” should automatically be inserted.

Showing the Usage

Well the suggestion was declined. I can’t blame the team. Nobody upvoted the suggestion. But I felt strongly enough about it, and knew that it was very simple to implement that I whipped up a GreaseMonkey script to do it myself. The script runs like a charm and even adds a few extra suggestions to the original three. It handles formatting and commas all automatically, so don’t worry about a thing, just click. Enjoy!

Script to Add Edit Summary Quicklinks

Script to Prevent Blank Edit Summaries

UPDATE: Fixed to use keng’s URL and added just plain old stackoverflow.com without the beta sub-domain in preparation for a launch. Thanks keng!

DOUBLE UPDATE: Sam put out a “wanted ad” for a Greasemonkey script to prevent blank edit summaries. I whipped that script up and linked to it up above. Thanks Sam! Quick Demo

5 Useful Mac Apps

I’ll admit it, I am a big fan of applications and an even bigger fan of Mac OS X applications. I even spent months researching which applications I would download and purchase even before I got my MacBook Pro (I’m thinking especially of TextMate).

This article is going not going to recommend the usual list of applications that you find being recommended like QuickSilver or TextMate. Instead I’m going to recommend those applications that I didn’t really hear of before I found them by luck. All 5 of these I use very often and I love them. They are not ordered from best to worst, that would be impossible given the different purposes and different areas that these apps address.

In the words of Bryan Hansen, the developer of Jolt (the first app I list):

The biggest problem for mac apps like this is getting the word out that they even exist.

Here are the players:

1 – Jolt – Bryan Hansen – Free or $5 donation
Jolt Icon
Jolt is a beautiful tool for all laptop users. Its goal is to temporarily prevent the power saving dim that we all experience. You might be watching a video or reading a long article and your Mac will interrupt you by dimming. This simple program solves that problem without interrupting your workflow at all.

The interface is strikingly simple. It sits in your menu bar and with a simple click it will activate. It defaults to 5 minutes but you can set multiple levels from 3 minutes to forever. To access its preference just right click the icon. I found this app useful just a few hours after I downloading it.

2 – cd to – Jay Tuley – Free
I’m a developer who really loves the terminal. I write Ruby/Perl scripts all the time. I have a terminal open 150% of the time I’m on my laptop (that means I have on average 1.5 terminals running at all times).
cd to icon
Seeing that I do so much in the terminal, Jay’s Finder Application is a godsend. Again, a perfectly simple interface, “cd to” is just a button you can place on the Finder’s toolbar. Right now it’s look and feel is just like Mac OS X 10.4 Tiger’s Finder window, but it fits in just fine on my Leopard Finder’s toolbar. With just a click it opens up the Terminal, changes directory to the current directory the Finder was in, and clears the screen so you have a fresh terminal. How awesome is that!? If you can’t think of how much time this will save you, then this isn’t the application for you. But, if you’re sitting there and already struggled this very day trying to find the current path to a directory in one of your Finder windows download this tiny app and struggle again.

3 – Desktoptopia – Desktoptopia Team – Now Free!
I am passionate about my desktop wallpaper. Until I bought Desktoptopia I would spend hours (it makes me cringe thinking about it) looking for that perfect wallpaper on my Windows laptop. Well, now I just click the menubar icon and in seconds I’ll have a really great wallpaper downloaded and set for me. This small investment has been a huge time saver and therefore a very smart purchase for me. You can freely check out most of my wallpapers for the last six months, I am proud of all of them: http://myskitch.com/joep/
my desktoptopia wallpaper

The interface for Desktoptopia is again very simple (seeing a trend with these great apps?). It is a preference pane where you can set general settings to choose the categories of wallpapers and if you want you can have your background change every few minutes. You can enable a menubar icon from which you can choose “Next Background,” rate the background (1-5 stars), and even visit the artists website.

In case anyone is interested the Wallpapers all download to ~/Library/Application Support/Desktoptopia/.Backgrounds/ so you will always have a hard copy. Still many of these wallpapers are submitted by users and so I would be hesitant about freely spreading the Wallpapers without the artist’s permission.

4 – Skitch – plasq – Free (Beta, if invites are not immediate then just leave a comment)
Skitch is simply phenominal at what it does. Skitch takes screenshots using crosshairs, fullscreen shots, iSight pics, simple but useful and fast editing like arrows and text, the list really goes on and on. Those are normally just the basic run of the mill features of image editors but Skitch makes it dead simple. Thats not even close to the good part.
skitch logo

The highlight of Skitch is the fact that it comes with your very own myskitch account. When you sign up with Skitch (very simple) you are given webspace to store your images. The desktop application, again a phenominal interface from the menubar, has a single button you can click that uploads (“web posts”) your image to your myskitch page. From there you can distribute that image freely, share it with friends, make it public, allow people to comment, or use them on your webpage like I do.

The superfast drag-and-drop feature to “Save” the image is integrated right into Skitch’s window design. To give the image a nice name and choose the format (jpg, png…) you don’t even have to open up a dialog box! Its almost too simple and intuitive. There is also a robust history, insanely easy cropping and resizing images, the list of feature just keeps going on and on.

You won’t believe me if you don’t try it yourself. This is one of the few apps I could have really benefited from having on a Windows machine but no such app existed. Lets just say that this little gem has seriously altered and improved my workflow in more ways then one.

5 – TextExpander – Smile on my mac – Free (Donationware)
This slogan is so true it actually isn’t funny:

If you’re not using it, you’re wasting time.

TextExpander example
Since downloading TextExpander I have grown so accustomed to having a shortcut type out my name that when I had to use a Windows computer the other day I had difficulty typing my name. This is not a bad thing, instead it is proof that this little program does what it does so well that I count on it, I depend on it, and it rewards me by making me smile every time I use it and hear the little chime of saving time and keystrokes. (run-on sentence?)

TextExpander makes a short snipper of text like typing “nname” expand to “Joseph Pecoraro” or “bjcom” expand to “http://bogojoker.com”. I have a bunch of snippets for personal things but the most common have to be your name, address, phone, already prepped and ready to go once installed. Adding snippets is a breeze, and to top things off TextExpander even keeps stats on how many characters and how much time it has saved you. I have used just about 700 snippets, expanding to about 7,000 characters saving me about 2 hours worth of typing at 100 Words Per Minute. I can now no longer misspell “tomorrow” (because I just did and I had a snippet fix it for me).

So there you have it. 5 apps that you can use today that I think will directly impact your relationship with your computer. They will make certain things simpler, make you happier, and finally you will be more productive. Enjoy.

mgrep – Multiple Regex Grep – SotD

My newest Ruby utility is called mgrep. It is a multiple regular expression version of grep. Input is processed line by line and each regular expression is said by the user to match or not match. All lines that meet the user’s desires for matching/non-matching regular expressions are printed in the following format: “filename [line number]: line of text.”

This can be taken in a number of different directions. I’m thinking “Partial Matches” meaning one regular expression matches one line in the file and eventually a second regular expression matches a totally different line and if all of these conditions succeed by the end of the file then print out the filename. This sounds more useful and will most likely be in version 1.0.

Here is the current usage:

usage: mgrep [-#] ( [-n] regex ) [filenames]
  #         - the number of regular expressions, defaults to 1
  ( ... )   - there should be # of these
  regex     - regular expessions to be checked on the line
  filenames - names of the input files to be parsed, if blank uses STDIN

options:
  --neg, --not, or -n    line must not match this regular expression

special note:
  When using bash, if you want backslashs in the replace portion make sure
  to use the multiple argument usage with single quotes for the replacement.

The usage is a little confusing seeing as the number of regular expressions on the command line are variable based on another command line switch. All in all though it is rather clear. Options will likely come in the future, much like grep or awk if I get around to it.

Here is an example probably not useful but at least it shows functionality, the line must contain a number, a double letter, and end with a !: [input]

1 ab !
- aa !
1 aa -
1 aa !
oh yah! 1

And when I run my script, I’ll put all the regular expressions in /here/ to make it clearer, this syntax is allowed by mgrep for convenience. Here is what it looks like:

joe[~/sandbox]$ mgrep -3 '/\\d/' '/(\\w)\\1/' '/!$/' input
input [4]: 1 aa !

To show of the –neg or -n option this command will show all the lines that do not have a hypen and still end with a !:

joe[~/sandbox]$ mgrep -2 -n '/-/' '/!$/' input
input [1]: 1 ab !
input [4]: 1 aa !

The script surely be updated soon, but grab it now and try it out:
mgrep – Most Recent Version – Download
mgrep – changelog

Clicky Greasemonkey Menu Script Updated

I noticed that I can’t really live without this script. Clicking those menus is just too difficult. The updates made to Clicky January 19th changed the way they handled their dropdowns. Clicky wrapped them into objects and added a bunch of functionality to make their content updateable via AJAX requests for their new filters. Some spiffy updates but code that I could not use from within Greasemonkey!

So have at it. The user script is available right here.

If you look at the script you will see that I handle opening and closing of the menus much like the Clicky’s object code does it. There is a variable to hold the current open menu if there is one so that opening a different menu closes any other open menu. I only add an onmouseover event and jimmy in my own close code when you click the close menu button. This works around Clicky’s object code without breaking anything that I can see.

rr – 1.0 – Now a Pipe Friendly Filter

rr has reached the 1.0 milestone! The obvious improvement over the last version is that input is allowed from standard input. It seemed silly to always require a filename and the option of having standard input was always on my to do list. Usage is now:

usage: rr [options] find replace [filename]
       rr [options] s/find/replace/ [filename]

Now you can use rr as a filter and happily make find replace changes by piping input into it or out of it! I already have a script that runs a file through 4 rr commands to produce much nicer and cleaner output. Wrap that up in a shell/ruby/perl script and you have a useful tool.

Enjoy. Again its all free!
rr – Current Version Download
rr – changelog.txt – Click Here

$ gem install regex_replace

rr – Regex Replace on a File – SotD

I was frustrated with regular expression find/replace programs that only did line processing. This was because often I had find/replace needs that spanned multiple lines. Programs like grep, ack (which I recently found and is really, really very awesome for searching code), and sed were easy enough to use for basic needs. But again, when it came to multiple line pattern matching both fell short of my needs.

My solution was to write my own script to parse an entire file as a single string and do my find/replace bidding. The cons being liberal use of memory and a few hundredths of a second longer then the usual find/replace algorithms seemed insignificant to the pros of a multi-line capable find/replace using a regular expression with the capability of using back references (like \1) to incorporate captured groups from the regex into the replacement text.

So, without further ado I present rr.

I am hopeful for some public criticism to help me bring rr up from its current version of 0.9 to a landmark 1.0. The ruby script weighs in at 100 lines but really under 50 are code and the rest is comments, whitespace, or the usage string. Speaking of usage, here is what it currently [v0.9.0] looks like:

usage: rr [options] find replace filename
  find     - a regular expression to be run on the entire file as one string
  replace  - replacement text, \1-\9 and \n are allowed
  filename - name of the input file to be parsed

options: --line or -l process line by line instead of all at once (not default) --case or -c makes the regular expression case sensitive (not default) --global or -g process all occurrences by default (this is already default)
negated options are done by adding 'not' or 'n' in switches like so: --notline or -nl
example usage: The following takes a file and doubles the last character on each line and turns the newlines into two newlines. rr "(.)\\n" "\\1\\1\\n\\n" file

More then likely this will undergo a lot of changes. A quick list of my current ideas include:

  1. If no filename is provided take input from STDIN. Multiple files can be handled by piping the `cat` of multiple files through rr.
  2. Better switch structure, although right now I don’t have any idea what that is

I’ll throw a test scenario at you. I had tabulated data in a file but each row was split across multiple lines. Now this wasn’t the only data in the file but I’ll present you with a simplier version here: [in.1]

Product A  12.99
           2001
----
Product B   1.99
           1997

Here you can see that I can’t just replace every other newline. What I want to actually do is replace newlines where there was a digit followed by a newline, some whitespace and another digit. I ran this through my script:

> rr "(\d)\n\s+(\d)" "\1  \2" in.1 > out.1

And I got the output I wanted: [out.1]

Product A  12.99  2001
----
Product B   1.99  1997

Even cleaner results can be seen by running a more advanced regex to remove the extra lines:

> rr "(\\d)\\n\\s+(\\d.*?\\n)(-+\\n)?" "\\1  \\2" in.1
Product A  12.99  2001
Product B   1.99  1997

So what are you waiting for? Download the script, add it to your bin directory, give it a test run, and tell me how you want it improved!

rr – Most Recent Version – Download

Thanks!

search