Category Archives: Programming

django unicode integration: fix for venus djando template

I just upgraded django tree which recently merged in the unicode support. This immediately broke django templates for venus. Here is what you need to change in planet/shell/dj.py to account for new django changes:
43c43,46
< f.write(t.render(context))
---
> ss = t.render(context)
> if [...]

Dear Lazyweb

I am looking for a flash media player which can play audio/video content in browser. I am currently using del.icio.us’s playtagger for now, but it is limited to mp3 only (I had to change the code a little bit to prevent it from adding multiple inclusions - my changed code is here) and it does [...]

Fix maharashtratimes.com font problems on firefox

Maharshtratimes.com (or maharashtratimes.indiatimes.com) is a marathi news website using unicode fonts. But it does not display correctly on firefox browser. The problem is because of a single HTML div which uses justified font style. It displays correctly on IE (which is why it is not getting fixed) - this could be because of firefox’s buggy [...]

Using Ruby for integer format conversions

Here are some recipes for interpreting stream of bytes as different C types. I will keep adding more to this as I go…
Convert a byte stream (embedded in a string) into 1 byte signed integers:
“\xfc\xfd\xfe\xff”.unpack(”c*”)
=> [-4, -3, -2, -1]
Convert a byte stream (embedded in a string) into 1 byte unsigned integers:
“\xfc\xfd\xfe\xff”.unpack(”C*”)
=> [252, 253, 254, 255]

Check if a site is phishing site.

Here is the updated bookmarklet: Phishy? (tested on firefox 2.0 only!)
1. Drag this link to your bookmark. This checks if the site you are currently on is a phishing site.
2. Drag this link to your bookmark. This prompts for a URL and checks if it is a phising site.
Uses phishtank’s check URL API.
If this [...]

Fixing the geocoder gem.

I wanted to use the ruby geocoder library on the windows machine, but the installation of the gem failed due to some weird error. I checked the rubyforge project page to see if someone else had a similar problems and someone actually had, but the bug was open for a long time. I decided to [...]

More about Phishtank API

Here is what will be good-to-have from phishtank.com API:

Good documentation about each interface e.g. how is callback_url used by auth.frob.request API ?
Description of all possible fields in return response (all possible XML elements and their possible values)
Some test URL’s and emails which will return known responses (i.e. phishy URL, good URL, not in the database [...]

Phish Tank

http://www.phishtank.com is a new service which aims to help weed out phishing URLs and email addresses using wisdom of the crowds. Users can submit emails/URLs which they suspect of fraud and others can vote if they really are fraudulent or not. I think it is a great concept. There is a REST API using which [...]

Ruby script to get a list of all mp3 files in a directory sorted durationwise.

Here is some ruby practice…

def mp3len(dirname)
require ‘mp3info’
summary=[]
Dir[dirname].each do |f|
Mp3Info.open(f) do |info|
summary.push([f,info.length])
end
end
summary
end
puts “Enter directory containing mp3 files”
dirname=gets.chomp
dirname = File.expand_path(dirname)
puts “Searching #{dirname}”
dirname += “/**/*.mp3″
s=mp3len(dirname).sort {|a,b| a[1] < => b[1]}
s.each{|q| puts “#{q[0]} => #{q[1]} [...]

Escaping URLs vs escaping HTML

I often get confused between two types of escaping you need to do when developing web applications: URL escaping and HTML escaping. This is a short note about when should you use what.
URL Escaping (or HTTP encoding or URL encoding) is used to escape the characters not allowed to be permitted for a URL (e.g. [...]

Playing mp3 links right in your browser

The del.icio.us folks have a nifty javascript piece of code which adds a small button to all the mp3 links on your webpage. (This infact embeds a small shockwave/flash script for each link). All you need to do is include the following code in the head section of your webpage:

<script type="text/javascript" src="http://del.icio.us/js/playtagger"></script>

Here is a link [...]

Yahoo Geocoding in ruby…

Find lattitude and longitude of any address
Yahoo just released a new beta of their maps webservice. Here is a small ruby script (inspired by Rasmus’s PHP code ) that I wrote that returns Lattitude, Longitude of the address provided…

require ‘open-uri’
require “rexml/document”
include REXML
url=’http://api.local.yahoo.com/MapsService/V1/geocode?appid=yahoomap.rb&location=’
puts ‘Enter Location: ‘
address=gets
address=URI.escape(address)
result=URI(url+address).read
doc = Document.new result
r=doc.elements["/ResultSet/Result"]
print “Precision: “, r.attributes["precision"],”\n”
r.children.each { |c| print c.name, [...]

Library Lookup greasemonkey script for San Diego public library and San Diego County library

I promised here that I will polish my library lookup script and post it here, but haven’t yet found any time to do that. I am posting it here so someone could work on it and make it better…
I have tried to look for the ISBN in both SDCL and SDPL, and it inserts the [...]

Django middleware

In the django project settings there is a key called MIDDLEWARE_CLASSES which is a tuple of strings implementing the middleware methods. Django base handler (TBD explain what this class does) reads this setting and initializes three of its own attributes: _request_middleware, _view_middleware and _response_middleware. It goes through the list of middleware classes instantiates each of [...]

django decorators

Django framework has used some design patterns. There is a directory called decorator which currently has two decorators: (decorator is just a method which dynamically adds additional functionality to original method depending on the situation)

funcA = login_required(funcA)
This replaces the funcA with a function which checks if the user is logged in and calls original function [...]