Why X-Files is awesome; reason #187

Not that I needed further proof of the sheer awesomeness that is the X Files but when I saw the episode Kill Switch recently, I realised that they had thought of the Matrix long before the Wachowski brothers. Take that!

Ah! My precious X Files. I never knew beauty till I knew thee!

Comments

iOS development.

Wrote my first bit of iOS code yesterday. Was great fun. :) Mostly it was adding a custom image to an app but it was fun nonetheless.

Also, I do not think I like XCode as an IDE but more on that later.

Comments

Fukushima reactors. An explanation.

Taken from here.

I have been reading every news release on the incident since the earthquake. There has not been one single (!) report that was accurate and free of errors (and part of that problem is also a weakness in the Japanese crisis communication). By “not free of errors” I do not refer to tendentious anti-nuclear journalism – that is quite normal these days. By “not free of errors” I mean blatant errors regarding physics and natural law, as well as gross misinterpretation of facts, due to an obvious lack of fundamental and basic understanding of the way nuclear reactors are build and operated. I have read a 3 page report on CNN where every single paragraph contained an error.

Comments

Au Revoir Lucid Ending!

Reading about Lucid Ending on Reddit reminded me of this song from the movie Kaagaz Ke Phool

Comments

Asset Tracking II

I just realised that simply using Prey would probably put you within some walkable distance of your stolen/lost laptop, but if the place was say a shopping centre, then you would be screwed. Then I remembered this xkcd comic, and decided to do something similar.

SSH into the system using the IP address generated by Prey. Raise the volume to maximum.

[damascus:~] sudo osascript -e “set Volume 10″

And then play some music file.

[damascus:~] afplay ~/Desktop/Symphony_IX_IV.mp3

Hopefully, the music should be loud enough for you to locate the laptop, even if through people’s reaction to a sudden loud orchestra amongst them.

But if you are not satisfied with this, then just use the say to speech synthesise words from the command line after you have raised the volume.

[damascus:~] say “This laptop is stolen! Help! Call the Cops!”

Comments

Asset Tracking.

Sometime ago, a friend of mine lost his laptop in a taxi and never saw it again. And today, Humpy showed me this video, and I decided time had come to do something about my laptop and my iPhone.

The iPhone was easy, ever since tracking your iPhone came free with the iOS 4.2 through the Mobile Me subscription. I set up a Mobile Me account on my iPhone, and then simply went to MobileMe and then checked the map for my phone.

I highly approve of the fact that I can send a message, lock and even wipe my phone in case its stolen or lost, but one thing I would have loved, would have been to get a picture of the person holding it. But this is a good start. Onto securing my laptop. I initially thought a daemon running in the background would be enough. And I even wrote a small one :

#!/bin/bash
PING=/sbin/ping
CURL=/opt/local/bin/curl
MAIL=/usr/bin/mail

output=`${PING} -t1 google.com`

connected=`echo $output | grep ‘unable’`
curr_date=`date`
email_address=”ipaddress.of.mujtaba.laptop@gmail.com”

if [ "x$connected" = "x" ]; then
ip=`${CURL} -s http://checkip.dyndns.org | sed ‘s/[a-zA-Z/<> :]//g’`
echo “Your IP = $ip” | mail -s “IP on $curr_date” $email_address
fi

And then I realised I am probably not the first person to have thought of securing my laptop and a quick google search proved that. A post on teknobites caught my attention and I was directed onto Prey. Installation was easy and setting up the daemon happened quickly. I went to the panel, logged in and marked my laptop as missing, set report duration and waited patiently.

Lo and Behold :) there was my laptop.

And what the scallywag was doing, and what he was logged in as :

And the best thing, it even takes the picture of the scallywag. :)

Me likey!

Hats off to guys at Prey.

Comments (1)

Flatten a Hash!

Flattening an array is a standard question in interviews, especially for modern languages like python and ruby. I just thought trying to flatten a hash would be much more interesting.

Here is my attempt at converting something like

{“a”=>1, “b”=>{“c”=>3}, “b2″=>{“c2″=>{“d2″=>2, “d3″=>8, “b2″=>9}}}

into

{“a”=>1, ["b2", "c2"]=>9, ["b2", "c2", "d2"]=>2, ["b2", "c2", "d3"]=>8, ["b", "c"]=>3}

require 'enumerator'
class Hash
 def flat_each(prefix=[], &block)
      each do |key, value|
           if value.is_a?(Hash)
                 value.flat_each(prefix + [key], &block)
           else
                 yield prefix + [key], value
           end
     end
end

main_hash = Hash.new
given = {"a"  => 1,"b"  => { "c" => 3 },"b2" => {"c2" => {"d2" => 2,"d3"  => 8,"b2"  => 9}}}
given.to_enum(:flat_each).collect { |k,v| main_hash.merge!({ (k.size == 1) ?  k.first : k.uniq  => v}) }
puts main_hash

Algorithm adapted from Ruby Forum.
Not sure this is what you would call flattening a hash, but this is the best I could rustle up in half an hour.

Comments (3)

Floating Point : Never forget!

Taken from Floating point accuracy problems.

Floating-point numbers cannot precisely represent all real numbers, and that floating-point operations cannot precisely represent true arithmetic operations, leads to many surprising situations. This is related to the finite precision with which computers generally represent numbers.

For example, the non-representability of 0.1 and 0.01 (in binary) means that the result of attempting to square 0.1 is neither 0.01 nor the representable number closest to it. In 24-bit (single precision) representation, 0.1 (decimal) was given previously as:
e = −4
s = 110011001100110011001101, which is 0.100000001490116119384765625 exactly.

Squaring this number gives 0.010000000298023226097399174250313080847263336181640625 exactly.

Squaring it with single-precision floating-point hardware (with rounding) gives 0.010000000707805156707763671875 exactly. But the representable number closest to 0.01 is 0.009999999776482582092285156250 exactly.

Comments (1)

Wireless and iPad – update

Found that one of the reasons why the connectivity was slow between my iPad and the internet was that full duplex was enabled on the gateway(laptop) but not the router.

Thanks Humpy :)

Comments

iPad and mobile broadband

I recently got given an iPad to play with and considering this was my first time ever using this latest of toys, I was pretty keen on it’s functionality.

I got the device, and managed to configure it and set as many apps on it as I wanted to my hearts content thanks to the wifi at work. But when I got home, the attraction of the device plummeted. This was not due to any fault of the device itself but due to the rather lamentable condition of internet connectivity.

Due to the fact that the area that I inhabit has pair gains setup over its phone lines, I cannot get ADSL connectivity and hence must rely on mobile broadband. This is all well and good but the problem arises when the setup of the mobile broadband refuses to allow shared internet connections through my MacBook over the airport. Hence the decreased interest in my iPad when I got it home.

I tried many things in order to share the connection to my iPad. I tried to share the screen, looked for apps to connect directly to a laptop; I tried a lot of things. In the end, Andrew Humphrey suggested I try to share it over ethernet through a router. I still had a Netgear router lying around from the heady days when I had ADSL and hence decided to use it. Alas, even that let me down.

Daniel Hall made the observation that Netgear routers do not allow static routes and hence I just needed a dumb router, which he was kind enough to lend me the next day.

Hence, as the situation lies, I have a mobile broadband dongle connected to a laptop, sharing the connection over Ethernet to a dmb router which then shares it over wireless to which my iPad connects.

It seems a very round about way of getting wifi to my iPad, but it was the only way. And now that I have wifi, the iPad seems so much more interesting. Let’s see, how long this lasts.

Comments (3)

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »