Categories: Technical, Django, Erlang, Linux, Mac OSX, Postgresql, Python, Subversion, Ubuntu, Vim
The wireless challenge
By Chee Ming on Sep 21, 2007 | In Technical, Exoweb, Ubuntu | Send feedback »
I managed to get my Dell Inspiron 510m laptop connected to a WPA2 with AES encryption and hidden SSID by doing some minor hacks with configurations files. But I was not totally happy with the setup because it didn't jell nicely with the GNOME NetworkManager.
At first, it just didn't seem to work. I had no idea why. I did some reading online and stumbled upon this short article.
The most important part that would get NetworkManager to work properly is to remove the configurations in /etc/network/interfaces. Just comment out everything except the stuff for the local loopback (lo).
But it wasn't over yet. I still didn't manage to connect to the wireless network at home. It seems although the wireless router is configured to use WPA2 Personal, it might not be so when configuring the settings. One way to find out would be to use the following command:
iwlist eth1 scanning
Replace eth1 with the wireless interface for your laptop and scan for something that looks like this:
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
So just use those settings there and it should all fall in place.
I never realised that connecting to a wireless router can be so challenging. ![]()
Up close and personal with Erlang
By Chee Ming on Sep 18, 2007 | In Exoweb, Erlang | 2 feedbacks »
I've been reading a bit about Erlang on the web and decided to take a plunge to learn it. I've been going through a few chapters of Joe Armstrong's Erlang book from the Pragmatic Programmers series and its been a pretty interesting mental ride. I've not really done much programming in functional languages except maybe a tiny bit of Lisp, so I am basically a newbie.
The variables in Erlang don't vary! Data types in Erlang are immutable. Which means a simple logic this, which is a very normal way of doing things in procedural languages, won't work:
i = 0
while i < 10
print i
i = i + 1
The pattern for Erlang would be to use arguments and tail recursion:
loop(Count) ->
if
Count < 10 ->
io:format("~w~n", [Count]),
loop(Count+1);
true ->
done
end.
But that isn't pretty, let me try again:
loop(Count) when Count < 10 ->
io:format("~w~n", [Count]),
loop(Count+1);
loop(_) ->
done.
There are probably many other ways to do it in Erlang that is more beautiful than what I've shown. What I want to emphasize is that its definitely a different way of solving problems.
One thing that I don't really agree with Erlang is the syntax. Erlang is full of punctuation. I think I've wasted quite a lot of brain cells just thinking of the right syntax rather than actually solving a particular problem. And I think it makes code harder to maintain. You can just copy and paste a code and fix the indentation. You need to worry about the commas, semicolon and periods. And at the end of a block you need to remember not to put any punctuation.
It is definitely tiring hunting down syntax errors. I'm too used to Python's whitespace and new lines, which I think is much more readable and maintainable.
I don't like the syntax but I do like the pattern matching features of the languages. They have a pretty interesting way to achieve polymorphism, which is normally overloading and overriding in object oriented languages. Check the following code out:
area({square, Side}) ->
Side * Side;
area({circle, Radius}) ->
3.142 * Radius * Radius;
area({triangle, A, B, C}) ->
S = (A + B + C)/2,
math:sqrt(S * (S - A) * (S - B) * (S - C));
area(Other) ->
{invalid_object, Other}.
And you would call the area() function in the following ways:
area({square, 2}).
area({circle, 3}).
area({triangle, 3, 4, 5}).
I'm just at the 5th chapter. Still 3 quarters more to go. I haven't started with the concurrency stuff which is where things start to get interesting with the language since it has that built in. Things should get pretty exciting. My plan is to build a system with Yaws and Mnesia. What should I build? I am not sure. I'll probably get some ideas along the way.
Configuring Ubuntu 6.10 (Edgy) to work with WPA2 Personal with AES and hidden SSID
By Chee Ming on Sep 10, 2007 | In Technical, Exoweb, Ubuntu | Send feedback »
I wanted to connect my Ubuntu to the wireless configuration mentioned above and realised that my GNOME network manager only supported WEP. I did a bit of research online and found a ton of info but the most useful for my case was the wifi doc from Ubuntu website. By the way, I am using a Dell Inspiron 510m.
I did a bit of hacking around and finally found a way.
- Install WPA supplicant like this: apt-get install wpasupplicant (requires root access)
Create the config file for WPA supplicant. I saved it at
/var/run/wpa_supplicant.conf/etc/wpa_supplicant/wpa_supplicant.conf (you probably need root access). It will look something like this:network={ ssid="[ENTER SSID HERE]" scan_ssid=1 # use this when access point using hidden ssid proto=WPA key_mgmt=WPA-PSK psk=[ENTER PSK HERE] # generate this using wpa_passphrase }- Generate your PSK using the wpa_passphrase program
Edit the /etc/network/interfaces file (again root access). For my setup it is eth1 for the wireless. So I just put the following
23 lines afteriface eth1 inet dhcpas such:auto eth1 iface eth1 inet dhcp wpa-driver wext wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf wireless-essid [ENTER SSID HERE]
wext is the driver that I am using. I guess this might be different depending on your setup. Check the man for wpa_supplicant to get an idea. The wpa-conf part points to the config file that was created earlier. The wireless-essid setting is also required, although it seems there is a duplication.
There is a line that looks like
auto eth1which doesn't seem to matter where its placed but I put it before the line containingiface eth1 inet dhcpjust to be safe (and consistent).
- Finally, restart the network like this:
/etc/init.d/networking restart. You can check if you get an IP address from the access point by usingifconfig (root access!).
You can troubleshoot just the wireless authentication part with the following command (root access!):
/sbin/wpa_supplicant -i eth1 -D wext -c /etc/wpa_supplicant/wpa_supplicant.conf
As you can see, replace eth1 with your wireless network device and wext with the driver that works for you. The /var/run/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf is the config file you created earlier. You should see something like this if everything works well:
Trying to associate with 00:16:01:ad:88:71 (SSID='[YOUR SSID HERE]' freq=0 MHz)
Associated with 00:16:01:ad:88:71
WPA: Key negotiation completed with 00:16:01:ad:88:71 [PTK=CCMP GTK=CCMP]
CTRL-EVENT-CONNECTED - Connection to 00:16:01:ad:88:71 completed (auth)
[id=0 id_str=]
If you don't get the message above, please run iwconfig and see if your wireless network interface is already associated with any of the access points. If not, you need to set it explicitly with iwconfig eth1 essid [YOUR SSID HERE] and try running the wpa_supplicant again.
If something breaks, just go back to edit your config file and retry until it works.
Hope that helps people out there with similar configs! ![]()
Update: /var/run is a bad place to put config files as it will clear the stuff there on each restart. I should have realised this earlier!
. Also added additional info about setting the ssid before running wpa_supplicant.
My debian workstation got spywared!
By Chee Ming on Jul 18, 2007 | In Technical, Exoweb | 1 feedback »
Do you know how computers running Microsoft Windows always gets attacked by spywares. They are small programs that run amok in the operating system doing next to nothing of value to the user and most of the time it makes the system crawl to a stop. Some even steal passwords and confidential information. No good come out of these programs.
I am not sure how it came about but I think it was after I installed the hplib scanner drivers. My debian setup at work felt like it was getting slower. At first I just ignored it. After a while it really annoyed me. The function test suite that I had to run before commit code was getting slower and slower even with postgresql running on ramdisk.
So I started some investigation. First up was to look what was running under the hood with top. Hmmm, very interesting. My machine has a load average of 2 point something. What is up?
Poking further, I looked at the processes and found that lpd is constantly doing something. After a while, I am pretty determined its lpd at fault and proceeded to kill it. ![]()
I executed the following command:
sudo killall -9 lpd
And suddenly there was silence. The sky became clearer and birds were chirping again. Life was good again. Wait! Its not over yet. There is more that needs to be done:
I forgot which version of lpd I was running at that time. But I looked through repository using apt-cache search and found that there is a new version of lprng. I tried installing the new version and to my distaste I was back in the two-point-something-load-average swamp. What the heck? Its the next generation lpr for gawd sake!
I reinstalled the old school lpr and everything was fine. I have no idea why and I didn't proceed further to troubleshoot. It could also be some issues with the hplip stuff I installed.
Some additional info:
lpr 1:2006.11.04 didn't give me any problems but lprng 3.8.28dfsg.1-1.1 is just way too hot for my machine. ![]()
Why I love Python, Episode 1
By Chee Ming on Jun 4, 2007 | In Exoweb, Python | Send feedback »
Programming in Python can be so fun at times. Python allows you to do a great deal with very little. Greg and I were debugging some funny error handling code and we wanted to quickly find a way to check when a particular attribute has been accessed. First we wrote the following class:
class Exploder:
def __init__(self, value):
self._v = value
def __getattr__(self, n):
raise "BANG! (%s)" % self._v
def __eq__(self, other):
if isinstance(other, Exploder):
v = other._v
else:
v = other
return self._v == v
Once that is done, put the following method in the class that defines the attribute that you want to track:
def __setattr__(self, name, value):
if name == 'YOUR_FIELD_NAME_HERE':
value = Exploder(value)
self.__dict__[name] = value
In hind sight, I think we could have also used property to achieve the same thing, which might be even easier.
