Roshan.info

Archive for the ‘Coding’ Category

Using Firefox 3.0+ cookies with wget/curl

Sunday, March 14th, 2010

Firefox versions prior to 3.0 stored their cookies in a standard cookies.txt file that could be used by tools like wget or curl. From version 3.0 onwards, Firefox uses sqlite for persistence of cookies and other data, making it slightly more difficult to use the same cookies. Here’s an invocation you can use to generate a cookies.txt file from your cookies.sqlite file:

sqlite3 -separator $'\t' cookies.sqlite \
    'select host, "TRUE", path, case isSecure when 0 then "FALSE" else "TRUE" end, expiry, name, value from moz_cookies' > cookies.txt

Make sure you’re in the proper profile directory, and that Firefox isn’t running. Otherwise, you’ll get a message that the database is locked.

I’ve tested this so far with Firefox 3.5 and 3.6. Should work as long as the structure of the cookies.sqlite file doesn’t change.

Updating the firmware of an Olimex AVR-ISP500 from Linux

Wednesday, November 4th, 2009

I recently got an Olimex AVR-ISP500 and wanted to upgrade the firmware from my Ubuntu desktop (didn’t really fancy installing any drivers on the Windows machine). Here’s what I had to do:

First, make sure you have lrzsz available:

roshan@optimus $ sudo apt-get install lrzsz
[sudo] password for roshan:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Suggested packages:
  minicom
The following NEW packages will be installed:
  lrzsz
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
Need to get 108kB of archives.
After this operation, 279kB of additional disk space will be used.
Get:1 http://mirror.switch.ch jaunty/universe lrzsz 0.12.21-4.1 [108kB]
Fetched 108kB in 0s (430kB/s)
Selecting previously deselected package lrzsz.
(Reading database … 293796 files and directories currently installed.)
Unpacking lrzsz (from …/lrzsz_0.12.21-4.1_amd64.deb) …
Processing triggers for man-db …
Setting up lrzsz (0.12.21-4.1) …
roshan@optimus $

The AVR-ISP500 starts in firmware-update mode if you have a jumper between pins 1 and 3 of the ICSP10 connector. Plug in the programmer and make sure the status LED continues flashing the sequence green, red, off.

Check /var/log/messages to see what device node is associated with the programmer. On my machine, it turns up as /dev/ttyACM0.

Download the latest firmware from the Olimex AVR-ISP500 page. Unzip the file, and you’ll find the firmware image avr-isp500.img

Run the sx command as shown, making sure to adjust the firmware image file and ports to suit your system. If all goes well, you’ll see the following:

roshan@optimus $ sx -X –16-bit-crc avr-isp500.img > /dev/ttyACM0 < /dev/ttyACM0
Sending avr-isp500.img, 97 blocks: Give your local XMODEM receive command now.
Bytes Sent:  12416   BPS:870                             

Transfer complete
roshan@optimus $

I found that it took a few tries to get the timing right, and that if you ran the command too soon it errored out:

roshan@optimus $ sx -X --16-bit-crc avr-isp500.img > /dev/ttyACM0 < /dev/ttyACM0
Sending avr-isp500.img, 97 blocks: Give your local XMODEM receive command now.
Xmodem sectors/kbytes sent: 0/ 0kRetry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Got 01 for sector ACK
Retry 0: Retry Count Exceeded

Transfer incomplete
roshan@optimus $

I just repeated the command every time it failed, until it finally “took”.

Using flickcurl in a script

Tuesday, October 27th, 2009

I’ve recently started using Flickr more than I have before, where my workflow consisted of using Lightroom to sort out the photos, process them and to give them a rating, export from lightroom, watermark, upload all the files to my photostream, and then add the photos I’d rated with at least 4 stars to a particular photo pool. These steps were not as seamless to me as they could have been, so I started looking for ways to automate the process. flickcurl came up as an obvious candidate, so I put together the following script.

Pre-requisites for this script to run are

You should be able to install all the pre-requisites on a Debian-based system using apt:

sudo apt-get install flickcurl-utils jhead imagemagick xmlstarlet

And now for the script:

#!/bin/bash
if [ ! -d to_upload ]
then
  mkdir to_upload
fi

POOL_ID="1234567@N89"
FLICKCURL="/home/roshan/progs/flickcurl/bin/flickcurl"
WATERMARK="/home/roshan/graphics/watermark.png"

for img in `ls *.tif | sort -r`
do
  imgbase="${img/.tif/}"
  echo "Photo $imgbase"
  target="to_upload/${imgbase}.jpg"
  xmpfile="to_upload/${imgbase}.xmp"
  logfile="to_upload/${imgbase}.log"
  echo "  Watermarking"
  composite -gravity SouthWest "$WATERMARK" "$img" "$target"
  jhead -v "$target" 2> /dev/null | sed -n -e '/xmpmeta/,/xmpmeta/p' > "$xmpfile"
  rating=`xmlstarlet sel -N xap="http://ns.adobe.com/xap/1.0/" -t -m "//xap:Rating" -v . $xmpfile`
  echo "  Rating: $rating"
  echo "  Uploading"
  $FLICKCURL upload "$target" public 2> "$logfile"
  PHOTO_ID=`sed -n -e '/Photo ID/{s/^.*: //;p}' "$logfile"`
  echo "  Uploaded as Photo ID $PHOTO_ID"
  if [ $rating -gt 3 ]
  then
    echo "  Adding $imgbase to pool"
    $FLICKCURL groups.pools.add $PHOTO_ID $POOL_ID 2> "$logfile.zrh"
  fi
done

I found that flickcurlutils 1.3 available through the Ubuntu Jaunty repositories would consistently segfault while trying to upload any photo which I wanted to mark public. The latest code (1.14) available on the flickcurl page doesn’t have this problem, so you might want to download and compile that yourself.

The script itself is relatively straightforward. It sets up a few constants (adjust to suit your system), creates a working directory, and then starts looping over all TIFF files in the current directory. For every TIFF file, it creates a watermarked JPG file, and extracts the XMP information that Lightroom has embedded in the image. The XMP file is an XML file, and among the information stored in it is the image rating which we get at using XMLStarlet. Upload the image, and depending on the rating given to the image, also add it to the pool.

It’s a relatively simple script, with no error-checking at all, but it does what I need.

Find linked sites bookmarklet

Sunday, November 16th, 2008

It’s difficult to identify a single page or site on the Net as being yours. Sure, you may have your own blog or even a completely independent website, but with sites like Del.icio.us, Flickr, FriendFeed and your profiles on all these pages, you’re bound to have at least a half dozen other pages that are “yours”. So now that you’re on these services, what should you do? To get the most of them, you’ll of course need to find your buddies on these sites, and that’s where things get tough. How do you know that the John Smith on service XYZ is in fact the same John Smith that you play scrabble with? If John has linked from his web page to his user profile then it’s no problem, but what if he’s only got a link the other way around, from his user-profile page back to his web-site. You shouldn’t have to click through the dozens of profile pages to find his - let Google do the work for you through the Google Social API!

A few months ago, Google made available an API which you can use to query the social network inherent in the web, by following the “me” links or pointers from one network’s profille to another, as well as the “friend” pointers. By then giving the URL of my web site, I can find all my “other” pages on the Internet, as well as everyone else that I link to or am linked by.

Using this social graph of services, it’s easy for you to find what services you have in common with someone else to be able to link with them there. To make this easier I have a very trivial bookmarklet I can invoke when I’m on any site, which does a lookup via Google Social’s API. To use it, simply drag and drop the “Google Social API Lookup” link to your bookmarks toolbar. Click it when you’re on any blog or profile page, and you’ll do a Google Social lookup. Enjoy!

Testing the Selenium way - Google Maps API tests released

Thursday, September 18th, 2008

A lot of people know that I’ve been working with Selenium to automate UI tests. You can now see a few examples of how specifically we use Selenium at Google, via the publicly released Selenium-based tests used as part of the Maps API testing process.

When you’re developing a Web-based application, testing a Web UI can get quite time-consuming. Throw in the problem of having to support multiple browsers, and the complexity of AJAX, and things can get out of hand quite quickly. This is where having an automated set of UI tests can be a life-saver. Make these tests part of your CI process, and you’ll get feedback as soon as something is broken.

Often, people end up testing the UI as part of an end-to-end test. This isn’t necessarily the best way to be testing the UI, as you’re no longer able to pinpoint the location of problems to a particular layer. Is that problem you’re seeing a data-encoding issue of the HTTP request/response, the database, or the persistence API? It could be anywhere. So take advantage of that multi-tiered system design which you have. Test each layer in isolation, separate it from the other layers that it’s talking to by putting fake, mock or stub layers in place, and test that layer by pumping in events and calling methods. Check the calls appearing out of that layer to verify they’re what you expect, and you have a much more useful set of tests.

April Fool’s Day at Google Zurich

Tuesday, April 1st, 2008

We’d already been advised to make sure to dress appropriately (in a suit), and been constantly reminded to bring our wallets. Here’s a picture documentary of what awaited us. In short, there was no more free food or drink, the pinball machines require you to put coins in (*gasp!*), and the Wii and XBox have disappeared. I think my favourite prank was the message on the printers:

Gallery Link - Printer: Out of ice-cream

The money collected today is being donated to charity.

Here’s a group shot of all those who participated:
Gallery Link - Group photograph of Business as Usual at Google

The Google public April Fools jokes so far include Google Australia introduucing Google gDay, Gmail adding Custom Time, and Virgin and Google cooperating for Virgle. In other news, Google China’s Search is now powered by real humans and the YouTube homepage has been rickrolled (click on any featured video)! Google Book search introduces - scratch and sniff, and Google Calendar has the Wake Up Kit!

Sinhala Unicode and Browser/OS support

Saturday, November 24th, 2007

After my last two posts on the Sinhala iGoogle keyboard gadget and searching for Sinhala Unicode, I had a few questions on what Sinhala Unicode would look like, seeing that one needs to have a Sinhala Unicode font installed for it to render properly.

Each operating system seems to need a different number of steps to enable proper rendering.

Here’s the way my name should look:

And here’s my name, as rendered incorrectly in most configurations:

Both LKLUG and Akshar Unicode have problems rendering the text, even in configurations where other fonts are able to do so fine.

Akshar Unicode


This font looks the most broken

DinaminaUniWeb


This has a rustic, old-fashioned feel to it.

KandyUnicode


This font might have been alright had it not been that heavy.

KaputaUnicode


Kaputa is a very clean, clear font without any unnecessary embelishments.

LKLUG


LKLUG is slightly broken, and has issues rendering some combinations. It also has a slightly old-fashioned feel to it.

Malithi Web


Clean, and easy to read.

Potha


Potha is a very nice font, getting the strokes just right, looking elegant, modern and uncluttered.

Iskoola Potha


So it comes as no surprise that Potha seems to have been cleaned up and included in Windows Vista by default, named Iskoola Potha. This font has the honour of being the best-looking Sinhalese Unicode font.

Sarasavi Unicode


Sarasavi came in as the second best Sinhalese font. The strokes on this font were a bit too heavy, making it more difficult to read, with some of the strokes being exaggerated.

Searching for “Roshan” in Sinhalese on Google in the Sinhalese locale

Wednesday, August 15th, 2007

Here’s a test to see what happens when you search for රොෂාන් (Roshan) and සෙම්බකුට්ටිආරච්චි (Sembacuttiaratchy) via Google Sri Lanka. Actually, that last search should eventually be a GoogleWhack. :-) If you use Firefox, the pages might not render correctly. Make sure you have a font like Kaputa Unicode installed. If you use any flavour of Linux, you’ll have to follow the instructions from here to enable proper support and rendering.

WebSiteOptimization - page load speed checker

Wednesday, June 2nd, 2004

WebsiteOptimization.com provides a service to analyze webpages to determine their page-load speed, and suggesting ways to improve it. A useful tool for those developing web-sites.

Moving to Wordpress

Tuesday, June 1st, 2004

MovableType 3.0 has changed it’s licensing, so it’s time to start looking at alternatives. WordPress seems to be the next logical choice. Even found a guide on migrating from MovableType to WordPress, where I’ll probably be spending quite some time.