Monday, November 2, 2009

Convert an encoded URL query string into a nested hash in a Rails App

On my work with, I wanted to parse out the following string, and produce a nested hash of the query part, just like rails does.

I search the web and found no answer. So I searched through the rails source code and found the answer in the Rack gem.

The command is Rack::Utils.parse_nested_query

Here is my example:

Loading development environment (Rails 2.3.4)
>> ab = "http://localhost:3000/churches/list/address/27713/5?fr[ed]=0&fr[ed]=1&fr[d]=0&fr[tz]=1&fr[et]=0&fr[et]=1&fr[tw]=0&fr[t_opr]=before&fr[t_opt(4i)]=9&fr[t_opt(5i)]=00&commit=Filter+Results"
=> "http://localhost:3000/churches/list/address/27713/5?fr[ed]=0&fr[ed]=1&fr[d]=0&fr[tz]=1&fr[et]=0&fr[et]=1&fr[tw]=0&fr[t_opr]=before&fr[t_opt(4i)]=9&fr[t_opt(5i)]=00&commit=Filter+Results"
>> c = URI.parse(ab)
=> #
?> d = Rack::Utils.parse_nested_query(c.query)
=> {"commit"=>"Filter Results", "fr"=>{"t_opt(4i)"=>"9", "t_opt(5i)"=>"00", "tw"=>"0", "et"=>"1", "d"=>"0", "tz"=>"1", "t_opr"=>"before", "ed"=>"1"}}
>> d = Rack::Utils.parse_nested_query(c.query).symbolize_keys
=> {:commit=>"Filter Results", :fr=>{"t_opt(4i)"=>"9", "t_opt(5i)"=>"00", "tw"=>"0", "et"=>"1", "d"=>"0", "tz"=>"1", "t_opr"=>"before", "ed"=>"1"}}
>> e = d[:fr].symbolize_keys
=> {:tz=>"1", :d=>"0", :"t_opt(4i)"=>"9", :ed=>"1", :et=>"1", :"t_opt(5i)"=>"00", :tw=>"0", :t_opr=>"before"}

Saturday, October 3, 2009

Upgrading my 1st Gen Jailbroken IPhone to Version 3.1

Last week I followed the usual instructions to update the 1gen phone from 2.x to 3.1. I've listed the steps I followed. Details on each step can be easily found from web searches.

  • Backup the Iphone settings using Itunes. Jot down all the apps downloaded via 3rd party installers like Cydia. You'll have to install these later after the upgrade.
  • Download PwnageTool 3.1 via bittorrent
  • From Itunes download the 3.1 software update
  • Use PwnageTool expert mode to create a custom 3.1 .ipsw file. Keep all the default options, except make sure not to select Ivy app from the Custom Packages section. Failure to do this will mean Cydia Installer will fail to work.
  • Take out the SIM (not sure if this helps)
  • Put the IPhone in DFU Mode using PwnageTool
  • Install the custom 3.1 .ipsw file using Itunes
  • Restore the Iphone settings using Itunes
  • Reinstall apps installed via 3rd party installers like Cydia. My favourites are BossPrefs and OpenSSH.
Surfing the web using EDGE stopped working after this upgrade. Modifying the carrier.plist file on the Iphone reveals the configuration option to edit APN/Username/password information.

Thursday, April 16, 2009

Switching to PostgreSQL

After watching the podcast , I realized that mysql is not a truely free product.
My goal is to always use open source

Wednesday, March 18, 2009

Creating dummy network interfaces in Linux

I'm working on a lab recreate where I have to replay traffic from a sniffer capture.
I need 2 interfaces, one ethernet and one dummy interface. After a few hours searching the web I found my answer on how to setup a dummy interface.

To create the dummy interfaces, make sure the kernel is compiled with the CONFIG_DUMMY option.

In the 2.6.27 kernel this is found in Device Drivers -> Network Drivers section

To create the dummy interface after the dummy module is installed issue:
modprobe dummy
If you need 3 fake interfaces, the command is
modprobe dummy numdummies=3

Now I can assign traffic to go out dummy0 interface..