October 1st, 2006

Ruby wrapper for Yahoo! Browser-Based Authentication

As you probably know we launched Browser-Based Authentication. What this means is that users can grant third-party web-based applications access to their Yahoo! data. (Actually, this could be used for non web-based apps too.) For a more detailed explanation, go here.

Anyway, I’ll explain how this works using the Ruby interface I just wrote and (sorta) tested:

  • Registering your web application: First off, you need to register your web application. After registration you’ll get your appid and shared secret.
  • Logging-in users:

    obj = YBBAuth.new(appid, secret)
    obj.get_auth_url('')

    Once you get the auth URL, direct the user there. Now the user is informed that your amazing web application is asking for permissions (read, write or both) and whether he wishes to grant permission, etc. Once the user grants permission, Yahoo! will redirect the user to your application (you would’ve submitted the URL when registering for an appid).
  • Getting user credentials: When Yahoo! redirects the user, it adds a token parameter to the URL. You need to extract this token in order to get user credentials:

    obj.get_access_credentials(token)

  • Making an authenticated request: Now you can make authenticated GET/POST requests:

    obj.ws_auth_get_request('http://photos.yahooapis.com/V3.0/listAlbums')

    The above snippet makes use of the Yahoo! Photos API.

» The Ruby wrapper

The interface isn’t complete or well-tested (I have a flight to catch in a few hours so I need to leave in a bit). I’ll work on it in a day or two.

Posted at 10:15 pm | Link | 25 comments | Leave a comment

August 1st, 2006

Unmemoize

I tried to add an unmemoize function to the memoize module I talked about earlier:

module Memoize
   def memoize(func_name)
      cache = {}
      (class<<self; self; end).send(:define_method, "#{func_name}u", method(func_name).clone)
      (class<<self; self; end).send(:define_method, func_name) do |*args| 
         return cache[args] if cache.has_key? args
         cache[args] = super    
      end     
   end
   def unmemoize(func_name)
      (class<<self; self; end).send(:define_method, func_name) do |*args| 
         eval(func_name.to_s+"u(#{args})")
      end     
   end
end

So now you can memoize a function and then, at a later point, unmemoize:

def fib(n)
   return n if n < 2
   fib(n-1) + fib(n-2)
end

include Memoize
memoize(:fib)
...
fib(15)
...
unmemoize(:fib)
...
fib(15)
...

It works — in that the function actually unmemoizes, but the function takes noticeably longer than the original function. There’s definitely something I’m not doing right — I don’t know what though.

Anyway, it’s been a long and tiring day. Later.

Posted at 01:23 am | Link | 11 comments | Leave a comment

July 29th, 2006

OSCON Wrapup

OSCON was a lot of fun. My talk went pretty well. I think. Here’s the presentation, if you’re interested.

A lot of the sessions and tutorials were nice—I mostly attended a bunch of Perl talks. Among the keynotes, the best, in my opinion, was Kathy Sierra’s.

Oh, this picture that I took won a runner-up prize at the Third Annual OSCON Photo Contest. So I got a HP Photosmart R717. Just like that.

Also, during the OSCON week, we released an update of our Search Web Services SDK. Here’s the announcement. It now includes the Lua and Ruby bindings that I had worked on earlier.

I’ll write more about the stuff that happened during that week if/when I get time.

» Pictures from OSCON 2006

Posted at 03:15 pm | Link | 7 comments | Leave a comment

July 24th, 2006

Memoize

MJD was talking about Memoize. Here it is in Ruby:

module Memoize
  def memoize(func_name)
    cache = {}
    (class<<elf; self; end).send(:define_method, func_name) { |*args| 
      return cache[args] if cache.has_key? args
      cache[args] = super     
    }       
  end     
end

There’s a lot of code in the Perl Memoize module; maybe it does other things—I haven’t really looked. Oh, and here’s this Memoize module from RAA. I’m some months late. :-)

Here’s some pictures from Portland.

Posted at 03:15 pm | Link | 7 comments | Leave a comment

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

June 3rd, 2006

Ajax Hacks

I just got my copy of Ajax Hacks (I’ve contributed couple of chapters sub-chapters). It happens to be one of their bestsellers, btw.

I was supposed to get the book quite sometime back, but since I didn’t, I was asked to choose any O'Reilly book of my choice. Now that was not an easy thing to do: I couldn’t think of anything that I wanted bad. (I would have asked for any book on Haskell or OCaml, but they don’t seem to have any books on functional programming languages.) I ended up asking for AppleScript: The Definitive Guide. What book would you have chosen?

Anyway, apart from those two books, they also sent me a copy of AppleScript: The Missing Manual. Sweet!

Posted at 05:09 am | Link | 20 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

April 3rd, 2006

OSCON

[...] Congratulations! You have been accepted as a presenter for the O'Reilly Open Source Convention 2006 at the Oregon Convention Center July 24, 2006 - July 28, 2006. [...]

Yeah, I’ll be speaking at OSCON 2006. Will be nice to meet some of the Ruby guys and the Pugs folks. I guess I’ll be in the Bay Area after the conference.

Posted at 12:55 pm | Link | 25 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 14th, 2006

Pugs

I have one last set of pictures from Vienna that I’ll probably post a little later. (My health hasn’t been good at all, so didn’t bother.)

Moreover, I’ve been playing with Pugs lately. nothingmuch (whom I had met at OSDC Israel) gave me a commiter bit yesterday. Haven’t done anything much yet, except for writing a couple of tests. For now (sometime maybe) I’m just going to write Perl6 examples so I get a feel of the language and also figure out what’s broken and stuff (class attribute inheritance, Perl5 module imports—sort of, etc.). Will probably look into the guts of the module import bit later.

Anyway, what interested me to Pugs is that the guts are all written in Haskell—something I had an interest in and used a tad at one point. And, of course, the people are all really nice.

Posted at 03:11 pm | Link | 1 comment | Leave a comment

March 12th, 2006

Building Pugs on OS X

It’s indeed not very straightforward to install Pugs on OS X. There’s some good instructions available here. Anyway, I’ll just rehash most of the things mentioned there with the current state of the art, and some additional notes. These instructions are for GHC 6.4.1, hs-plugins (the latest), parrot 0.4.2 and Pugs 6.2.11.

Install parrot

Download parrot.

sudo mv parrot-0.4.2/ /usr/local/
cd /usr/local/parrot-0.4.2/
perl Configure.pl
make
make test # optional
sudo make install

Install GHC

(You’ll need DarwinPorts for this.)

sudo port install ghc

This will take a *long* time. Took me a little more than five hours. (Optionally, you could probably download the OS X binary.)

Install darcs

darcs is a revision control system, written in Haskell, required to get hs-plugins.

sudo port install darcs

Again, you could optionally download a binary.

Install hs-plugins

darcs get http://www.cse.unsw.edu.au/~dons/code/hs-plugins
cd hs-plugins/
runhaskell Setup.lhs build
runhaskell Setup.lhs install
sudo ranlib /usr/local/lib/plugins-1.0/libHSplugins-1.0.a

Install Pugs

Download Pugs.

export PUGS_EMBED=perl5,parrot
export PARROT_PATH=/usr/local/parrot-0.4.2
perl Makefile.PL
make
sudo make install

make will take a while. Took me around two hours. The wait is worth it; however, you could optionally use make unoptimized — this will make Pugs compile faster, but will run much slower.

That should be it. Pugs should run fine now (here’s a screenshot):

$ pugs
...
^z
$ pugs -e "print 'hello, world';"
hello, world

Posted at 01:55 pm | Link | 0 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 20th, 2006

Lookie!

Ruby-GTK Uploadr running on OroborOSX on Mac OS X Tiger. Of course, it doesn't feel native, but at least better than vanilla xorg. I should probably try playing around with GTK+OSX.

Posted at 07:26 pm | Link | 3 comments | Leave a comment

Feed changes

I realize that not all folks are probably interested in the photos I post on Flickr, so I’ve made a change to my feed, and added another feed:

Sound good?

Oh, and yeah, I’m in Bombay. This time for longer than a weekend. Here until Wednesday, after which I fly to Vienna. Haven’t done much, except for yesterday when, at around 2 AM or so, we impulsively decided on a booze session in Gorai. :-)

Posted at 01:31 am | Link | 0 comments | Leave a comment

February 16th, 2006

Flickr Uploadr on OS X

So I finally managed to get my GUI Flickr Uploadr to work on OS X. It was not easy installing ruby-gtk2 in that I had lots of dependency issues. The issues were mostly with atk, gdkpixpuf, and glib. At first, I tried installing GTK2 using Fink. It failed because of GCC issues with glib (I think), which I later figured was because of a problem with pkg-config. I ditched Fink, and used DarwinPorts. Things were good.

After that, I had GTK initialization issues, which was because I hadn’t exported DISPLAY (to 127.0.0.1:0; thanks, Gopal!).

I couldn’t use my old code as is because the Ruby-GTK2 bindings on my FreeBSD box is an older version. (I’ll put the code up sometime later. And maybe also try to document some poorly documented Ruby-GTK2 stuff like Gtk::TextView, Gtk::TextBuffer, etc.) So, it works, but not perfectly:

Ruby-GTK Uploadr running on OS X

Yeah, it looks horrible, but then I&rsquo'm not going to play with it on OS X again—I just wanted it to work.

Oh, by the way, Google Talk is *love*!

Posted at 01:39 am | Link | 9 comments | Leave a comment