Thursday, November 25, 2010

Redis patterns | search

Problem

You want to implement search against user objects stored in redis using Python. Something like querying for all user ids whose username begins with "an".

Solution

Here we have user objects stored in as hashes with "user:obj:" as prefix.

For example

user:obj:3955 {id: 3955, username: 'John', ..}

We need some extra data structures to support our search i.e. (search user objects where username begins with given phrase. So search for jo should match John, Joe and so on. We will use sorted sets of all usernames and will assign every element a score. This score is a float and helps us in finding the matching words.

Some scores for eg.

a -> 0.097
ab -> 0.097098
ac -> 0.097099
bc -> 0.098099

So for above four string if we find strings that has score that is => 0.097 and < 0.098, we find all strings that begins with 'a'


Code



Discussion

This to demonstrate simple redis pattern and using it in Python.

See Also

There are already some good writeups on related topics.

Saturday, August 28, 2010

xfce and ubuntuone

I do like Ubuntu Netbook Remix’s UI. However with 10.04 it’s just gone so unstable for me.
  • After login when system prompts for keyring secret, UNR environment crashes and drops to gnome. I have to relogin if I need UNR env.
  • After I removed a few packages it could not just start gnome panel causing a great inconvenience. I guess this is due to Evolution integration with latest Ubuntu. Mail client I like and use is Thunderbird. I cant switch to Evolution.
  • Initially after 10.04 release it was damn slow to respond, so had to do some work around to get it to acceptable speed.

Considering all that I decided to switch to Xfce. It just worked like charm. But now I also use (and like :) ) UbuntuOne service for my backup. UbuntuOne is not integrated for XFCE. Also you cant do everything from UbuntuOne’s cli.

u1sdtool -q; killall ubuntuone-login; u1sdtool -c # configuration
u1sdtool --create-folder ~/my_data # add folders you want to be synced
u1sdtool --list-folders
u1sdtool --current-transfers

For more details you might want to check Ubuntu One wiki .

Wednesday, February 24, 2010

Reliance Netconnect Broadband+ on Linux

  • It works. Make sure while purchasing you inform them that you use Linux
  • It’s fast and reliable in Pashan, Pune area
  • Below config worked for me on Ubuntu 9.10 AND 10.04
  • There are Linux drivers on the CD but I could not get it working on Ubuntu 9.10.
  • For activation, I had to use Windows :(

sudo apt-get install usb-modeswitch wvdial

vi /etc/wvdial

[Dialer Defaults]
Phone = #777
Password =
Username =
Baud = 460800
Stupid Mode = 1
New PPPD = 1
Tonline = 0
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = Analog Modem
Baud = 460800
Modem = /dev/ttyUSB0
ISDN = 0

Saturday, January 2, 2010

All izz well?

Surely one of the most over-hyped film. What was good? Aamir, Music and the first half laughs. Post interval it becomes a predictable, boring, idiot bollywood movie.

Munnabhai s were certainly better. I would say watch it on TV or atleast don’t pay 3 times higher than usual for tickets like we did. 4 and half stars by critic hmmmm..