June 5th, 2006

What’s playing

I play all my music from iTunes now (most of it is on my FreeBSD box, though, served using mt-daapd). Anyway, time to update my current song script:

#!/opt/local/bin/ruby

require "rubygems"
require "net/ssh"
require "net/sftp"

script = <<SCRIPT
        tell application "iTunes"
                set {art, nm} to {artist of current track, name of current track}
                set disp to art & " - " & nm
                if disp is "" then
                        set disp to current stream title
                end if
                return disp
        end tell
SCRIPT

song = `osascript -ss -e '#{script}'`.chomp

exit if song == ""

`convert -fill black -pointsize 12 'label:#{song}' curr_song.png`

Net::SFTP.start("<host>", "<username>", "<password>") do |sftp|
        File.open("songs.txt", "a") { |f| f.write "#{song} (#{Time.now.to_s})\n" }
        ["songs.txt", "curr_song.png"].each { |file|
                sftp.put_file(file, "public_html/journal/#{file}")
        }       
end

Yeah, that’s a bit of AppleScript in there.

I’ve set it up to run every ten minutes. It also generates a list of all the songs I’ve played. I can probably use that data to figure not-so-useful patterns.

Posted at 06:19 am | Link | 17 comments | Leave a comment

May 30th, 2006

UpcomingFS

I like to use the terminal when I can. Presenting UpcomingFS—access upcoming.org event information:

[ppillai@renegade ]$ ./upcomingfs.rb /tmp/fuse/ &
[1] 10700
[ppillai@renegade ]$ cd /tmp/fuse
[ppillai@renegade fuse]$ ls -1 texas
66002 - Nine Inch Nails
74539 - Suds on Sixth
77608 - Exposure Dallas - See and be seen.
77609 - Exposure Dallas - See and Be Seen.
[ppillai@renegade fuse]$ 

You can also view events in a city within a state (it doesn’t seem to work very well, though):

[ppillai@renegade fuse]$ ls -l massachusetts/boston | grep BarCamp
71709 - BarCamp Boston
[ppillai@renegade fuse]$ 

To view an event's details:

[ppillai@renegade fuse]$ ls -1 massachusetts/boston | grep Band
79932 - Live Band Karaoke - Beatles Night!
[ppillai@renegade fuse]$ cat 79932

Live Band Karaoke - Beatles Night!
==================================
                 
The Milky Way is hosting a special Beatles theme at the first and best Live Band karaoke night in Boston.

Sing the Beatles backed by a live band!

Prizes for best song and best costume.
No cover, as always.
22:00:00 to 01:00:00, 2006-05-30 to 
[ppillai@renegade fuse]$ 

To unmount the filesystem:

[ppillai@renegade fuse]$ cd..
[ppillai@renegade tmp]$ fusermount -u /tmp/fuse/
[ppillai@renegade tmp]$ 

Get the code here. You’ll need fuse and the ruby bindings. (I just got a Linux box; it’s got to be of some use other than writing Java.)

Posted at 06:13 pm | Link | 11 comments | Leave a comment

May 26th, 2006

Escapa!


Escapa!
Originally uploaded by Premshree Pillai.
I hacked this game a bit: put it behind our internal auth, threw in a DB to store high scores, etc. People are going crazy! There's also a picture of Philip explaining how to score high or something to Surat.

There's also a nice video, but I'll probably not post it. :-)

There'll be more pictures soon. Check here later.
Posted at 02:37 am | Link | 6 comments | Leave a comment

May 13th, 2006

Comparing eating out patterns in different cities: normalized graph

I normalized the data (see earlier post). Readable? Got suggestions on how to improve?

I ditched rgplot and instead used Gruff (wraps RMagick which wraps ImageMagick). Installation is pretty straightforward. However, I faced a problem with installing ghostscript on my OS X box. Something in the portfile is broken or something. Anyway, you might need to comment the following lines in the ghostscript portfile (typically something like /opt/local/var/db/dports/sources/rsync.rsync.darwinports.org_dpupdate_dports/print/ghostscript/Portfile):

[...]

debc62758716a169df9f62e6ab2bc634 aj16.tar.Z md5
b24ac1b6966adf3a92edaae42eda662c ag14.tar.Z md5
f9cad1b32e56f65339da26266f568e97 ac15.tar.Z md5
a9d876f28dde1d4a0a6571eb0e281761 ak12.tar.Z md5

[...]

default_variants +aj16 +ag14 +ac15 +ak12

Posted at 04:57 am | Link | 43 comments | Leave a comment

May 11th, 2006

Flickr Lightbox


Flickr Lightbox
Originally uploaded by Premshree Pillai.
Some folks were discussing Zooomr in an internal list. Someone mentioned the lightbox feature (try it here).

The feature is useful, most of the work had been done, and I was bored. So here you go, a Greasemonkey script that'll add the lightbox feature to Flickr. It works on any Flickr photos list-type pages (recent photos page, your friends page, favorites, any tag page, etc.).

Note: tested on Firefox 1.5, Greasemonkey 0.6.4 on OS X 10.4.3 and FreeBSD 4.10.

Enjoy!

Update (18/05): updated the script to work on Flickr gamma.
Posted at 08:57 pm | Link | 27 comments | Leave a comment

May 7th, 2006

Comparing eating out patterns in different cities

If there’s a city you’d like to see in the comparison, let me know.

Posted at 02:41 pm | Link | 15 comments | Leave a comment

May 4th, 2006

People in Bangalore like to eat out on Sundays

Interestingly, folks in Bombay seem to like eating out on Tuesdays:

Notes:

1. Most people seem to end up using the tag “hotel” when they really mean to use “restaurant”, so I’ve gone with the former.
2. I rely on Flickr photo data and my program. You don’t have to take the graphs seriously.

Here’s the script I wrote to draw that graph (requires flickr.rb and rgplot):

#!/usr/local/bin/ruby18

require "../flickr"
require "gnuplot"

API_KEY = "078be2728a42f4e8228f2c2b8c9b6cca"

flickrObj = Flickr::Flickr.new(API_KEY, "")
photosObj = Flickr::Photos.new
days = Hash.new { |h,k| h[k] = 0 }
photosObj.search(["#{ARGV[0]}","hotel"], "all", 0, 1000).each { |ele|
	if /([0-9]+)\-([0-9]+)\-([0-9]+)/.match(photosObj.get_info(ele)["date_taken"])
		begin
			t = Time.mktime($1, $2, $3)
			days[t.strftime("%a")] += 1
		rescue
		end
	end
}
Gnuplot.open do |gp|
	Gnuplot::Plot.new(gp) do |plot|
		plot.title  "Photos taken in restaurants in #{ARGV[0]}"
		plot.ylabel "No. of Photos"
		plot.xlabel "Days"
		i = 0 
		plot.xtics("("+days.keys.map{|ele| "'#{ele}' #{i;i+=1}"}.join(",")+")")
		plot.data << Gnuplot::DataSet.new([(1..7).to_a, days.values]) do |ds|
			ds.with = "linespoints"
			ds.notitle
		end
	end
end

Usage: ./eating-out.rb city_name

Enjoy!

Posted at 08:19 pm | Link | 5 comments | Leave a comment

March 30th, 2006

Export Firefox Bookmarks to Safari

Firefox on OS X sucks. Big time. I decided to move to Safari, but I couldn’t do that without exporting my bookmarks. Here’s how I did it:

The Firefox bookmarks is in an HTML file. It’s typically located at ~/Library/Application Support/Firefox/Profiles/<profile name>/bookmarks.html. Safari stores its bookmarks at ~/Library/Safari/Bookmarks.plist, which is a binary file.

Use this simple script to export your Firefox bookmarks as a readable XML, and follow these steps:

renegade:~ $ ruby ff2safari.rb  > ~/Library/Safari/Bookmarks.xml
renegade:~ $ cd ~/Library/Safari/
renegade:~/Library/Safari $ mv Bookmarks.plist Bookmarks.plist.backup
renegade:~/Library/Safari $ plutil -convert binary1 -o Bookmarks.plist Bookmarks.xml

Note that this script simply dumps all your Firefox bookmarks in Safari’s Bookmarks Bar. (I have a very few bookmarks on my browser, most of which are in the Bookmarks Toolbar.) You could use an XML parser to export bookmarks as is. To understand the format of the XML you need to generate, you might want to export the existing Safari Bookmarks file to XML:

renegade:~/Library/Safari $ plutil -convert xml1 -o readable.xml Bookmarks.plist

One interesting thing to note: a ktrace/kdump on Safari didn’t do any open on Bookmarks.plist. I wonder why.

This post brought to you from Safari.

Posted at 02:34 pm | Link | 14 comments | Leave a comment

March 10th, 2006

Wien

I’m not doing well at all (terrible throat, thus cold, thus headache, etc.), so no Vienna post.

Well, sort of.

That’s not a single image; each square is a CC-licensed image from Flickr. Click on any of the squares to go the that image’s photo page. (If this wasn’t LiveJournal I probably could’ve thrown in some JavaScript magic.) Generated using this badly written script. (Requires flickr.rb.) Basically, you can supply it a word, tags for the word (some color, for example; in this case it’s “blue”), and tags for the surrounding spaces (in this case I’ve inserted a specific image).

Blah.

Posted at 02:04 am | Link | 7 comments | Leave a comment

February 3rd, 2006

Watch Google videos in any country

I never used Google Video before. But now that some of Google’s tech talks are available online, I decided to take a look. Turns out I can’t view videos from India (and some other countries). This is the message you’d get, for example, when you try watching a Jessica Simpson video:

Thanks for your interest in Google Video.

Currently, the playback feature of Google Video isn't available in your country.

We hope to make this feature available more widely in the future, and we really appreciate your patience.

Of course, there are solutions, like using a proxy, etc. Anyway, here’s a Greasemonkey script to fix that thing.

Posted at 05:28 pm | Link | 16 comments | Leave a comment

January 6th, 2006

Command-line Flickr Uploadr

I had written a command-line script to upload photos to Flickr, but it used the old auth mechanism. A couple of days ago a co-worker pinged me because he was having problems getting auth to work. I realized I never cared about the web auth. I’ve extended the code to allow for that now. Apart from that I did some cleanup, etc.

And since the old auth no longer works, I’ve hacked up a simple script to upload photos to Flickr. (You’ll need the API too, of course.) Using it:

./flickr-uploadr.rb path/to/images/dir/ tag1,tag2,tag3

Hope someone finds it useful. :-)

Posted at 07:59 pm | Link | 4 comments | Leave a comment

November 25th, 2005

My first widget!

Now that I’ve got a Mac, I could play around with Konfabulator.

The screenshot that you see is my first attempt at creating a widget. It shows the latest ten public photos from your Flickr contacts (navigation using the prev/next buttons). (You need to set your Flickr login email the first time you run it.) Clicking on the photo title takes you to its Flickr page. Something like this probably already exists, but I wrote it so I could play around.

It’s amazingly simple to create a widget. Hopefully I’ll hack something more useful some day.

I’ve tested this only on Mac OS X Tiger, but it should work on Windows too. Download: FlickrFriends.widget »

Posted at 02:49 am | Link | 2 comments | Leave a comment

November 12th, 2005

360° Tagging (or Leveraging Existing Tagging Platforms)

Yahoo! 360°, as you know, doesn’t have the ability to tag entries as of now. I was wondering if there’s maybe a way I could add tagging to it. And then it struck me: Social Bookmarking!

Any sane social bookmarking site allows you to add a URL and associate a bunch of tags to it; and also has the capability to return a bunch of tags given a URL.

So, yeah, obviously it’s a Greasemonkey script. You get the idea now, I guess. I thought of using Yahoo!’s My Web 2.0 for this, but then there isn’t a push API. del.icio.us turned out to be my ideal candidate — they have post/get APIs, and they use HTTP authentication (which means no complications).

So this is how it works:

  • The script basically figure out the permalinks and titles of the blog posts, and store then as hidden variables in the forms that you see.
  • When you 'Add Tags', the permalink gets posted (through a PHP script proxy) as the URL to be bookmarked, and the title gets posted as the description (or the equivalent).
  • Now when you want to view posts with any tag, I just append a ?tag=foo to the blog URL, and it displays titles of all those posts, pointing to their permalinks.

Let’s take a look at a couple screenshots:

So to add a tag, you need to go to your My Blog page. Adding tags (space-delimited) is pretty straightforward, as you can see in the screenshot above. Now one problem is that I couldn’t find an API in del.icio.us that lets me add tags to an existing bookmarked URL. (I could maybe figure out tags for an existing URL, then add the new tag to the list, delete the URL, and then bookmark again... but, well, that’s too much of a pain.)

That's the same My Blog page when you pass a tag query to it — ?tag=code, in this case.

One thing — and an important one at that — lacking here is that only the logged-in user can make use of the tags. That’s kinda sad, but del.icio.us doesn’t have an API where I can do a tag lookup without requiring authentication information. Once they have such an API, it’d be pretty cool — all you’ll need to do is install (a modified version of) this script, and you’ll be able to see what others have tagged their posts, and browse their posts using tags.

So as of now what this script does is it makes your life easier if you want to categorize your blog posts... for you.

More interestingly, this script demonstrates how to leverage an existing tagging platform (del.icio.us, in this case), and make use of it in an application (Yahoo! 360°, in this case). Of course, using Greasemonkey is not really a solution but, hey, it works!

The script: 360.user.js.

NOTE: Like I mentioned earlier, the script uses a PHP proxy to interact with del.icio.us. Now I don’t do anything evil within the script but, if you’re like me, you might wanna get the source and host it on your box or something.

Posted at 11:59 pm | Link | 5 comments | Leave a comment

July 21st, 2005

Greasemonkey Dict

It’s quite common to lookup dictionaries for words on web pages. I wrote a Greasemonkey script to make life a tad easier for me:

Now I don’t know if there’s such a script already. Anyway, doesn’t matter now. I’m using OneLook to fetch the definition. I know it’s probably not the best thing to do, however, I don’t know of any dictionary services that provide an API. Know any?

Well, I could set one up locally, but that’d work for me only. Oh well. Laters.

Oh yeah, using it: just double click on the word that you want to know the meaning of... if it does mean anything, a ncie box will appear, nothing happens otherwise.

Script’s here. That’s it for now from Monkeyland!

Posted at 12:54 pm | Link | 28 comments | Leave a comment

July 9th, 2005

My Web 2.0 Page Tags Displayer

Yellow from Monkeyland once again.

My Web 2.0 is cool, as all of you’ll know. And we have an API—that means uber-cool shit. So, yeah, I hacked a little Greasemonkey script that does this:

Yeah, well, in case you didn’t get it, it basically displays the top (latest?—I’m not sure, and didn’t care to check) tags that the page you’re viewing has been tagged with by My Web 2.0 users. The screenshot above is a section from news.google.com. The thingie at the bottom-right is what the script does.

That’s it from Monkeyland for now.

Posted at 02:51 pm | Link | 0 comments | Leave a comment

July 4th, 2005

Flickr Tags Autocomplete

Yeah, well, yet another Greasemonkey autocomplete script. If you go to Flickr’s Photos upload page, there’s no provision to select from your tags to add tags. Moreover, the default browser autocomplete obviously doesn’t understand Flickr’s space-delimited tagging. So when you type a character it’d provide you the entire set of tags that you might have typed earlier.

This script, on the other hand, has undergone rigorous training from folks at Flickrland and Monkeyland. After you type a space in the tags text box, the script will autocomplete for the character after the space. It’s kinda buggy, let me tell you. Get the script here. And don’t forget to set user_id—some-number@N00—in flickr_request().

That’s it from Monkeyland for now.

Posted at 11:59 am | Link | 5 comments | Leave a comment

June 17th, 2005

Skip Slashdot Comment Preview

On any of Slashdot’s Post Comment pages—this, for example:

...
Logged-in users aren't forced to preview their comments.
...

Now forcing users—whether Anonymous Cowards or not—to preview sucks. I hate it. And it’s stupid considering I can get rid of it. Here’s the Greasemonkey script you’d require. It adds a ‘Submit’ button on the page, and sets a hidden variable op—which, apparently, Slashdot uses to identify whether it’s a preview, or submit, or whatever—set to value Submit.

Well, I thought that alone would have done the job. Turned out there’s some more weird shit that it does internally—and I’m not terribly sure what all. My guess is that it does some session stuff, where it sets some flag to indicate that the comment-to-be-posted has been previewed. So, the script, when you click on submit, first does a xmlhttpRequest with op=Preview, and then submits the form. Seems to work.

That’s it from Monkeyland for now.

Posted at 01:10 pm | Link | 4 comments | Leave a comment

March 4th, 2005

What about REBOL?

Yahoo! Search Web Services demo using REBOL

Heh, REBOL is fun at times. Somebody asked me that question—“What about REBOL?”. Um, I don’t think I’m going to find time to write an API or anything. Basically I’m not in any mood to add parse handlers for the various search types.

Well, there you go, a Yahoo! Search Web Services demo for REBOL. That’s about REBOL.

Code... )

The screenshot was generated using REBOL itself: save/png %screenshot.png to-image out

Posted at 03:39 am | Link | 4 comments | Leave a comment