Archive for December, 2008
December 31st, 2008
So I was playing around with some code in Python today and was curious about static members of a class (I guess that is what you would call it). I wanted to know if I set an attribute at the class level and change it, would all the instances see that change or if each instance is separate.
Here is some code I played with:
>>> class T:
... build_location = None
... def get_location(self):
... return self.build_location
...
>>> t = T()
>>> print t.get_location()
None
>>> T.build_location = "hello"
>>> print t.get_location()
hello
>>> t.build_location = "there"
>>> print t.get_location()
there
>>> print T.build_location
hello
>>> T.build_location = "hello"
>>> print t.get_location()
there
>>>
So, what I did was set an attribute on the class level that everyone can see without an instance of the class. When I create an instance it can see that attribute just like I can from just doing T.build_location. When I change the static variable then the instance sees that change as well (which is what I was hoping for).
Now, the interesting part is that if I use an instance of the class to change the variable, that variable becomes local to that instance as you can see above when I printed the class’s T.build_location. Now I tried to set the class level attribute back to “hello” and that works but now it does not change what the instance sees!
This is not any earth shattering news but I thought it was interesting when I saw it.
December 15th, 2008
So I needed to find the number of files in a directory recursively. I found a great way to figure that out on Linux that has helped me a couple times now. I definitely need to remember it…anyway here is is:
find /my/directory -type f |wc -l
If you need to find the number of directories recursively then do:
find /my/directory -type d | wc -l
Find will just print out all the files it finds. It you tell find a type to find it will only print files of that type (f for file, d for directory). wc will just count the number of lines in the output
December 3rd, 2008
So, I just started using twitter and it is pretty cool. One of the best things I think on facebook is seeing people’s status change…it can show what they are going through or doing right now. Twitter is a little microblogging tool that you basically just state your status like you would on facebook and thats it. You can get updates in text message form sent to your form whenever someone adds something to twitter.
I love it. Sometimes it takes too long to write a whole blog entry but it is easy to send little status updates in my free seconds…the question is, how do I get family members and friends to watch that for my status updates without having them be forced into getting an account and always logging in to see the updates…
Maybe there is a WordPress plugin I can use to show it on my personal blog or some sort of RSS thing to check out. Either way I think I like twitter…although they need to add more ways to send and receive updates, like through email, IM, or RSS or something, because I don’t get unlimited text messages so it can definitely ruin the experience.
December 3rd, 2008
For the last several months on my Ubuntu machine at work the numpad has not been working. It has been so frustrating. I would turn the numlock on and off and nothing would seem to get it to work.
I thought it was something wrong with the keyboard or possibly after a kernel update one of the drivers changed and killed it for some reason. I was on Hardy and haven’t taken the time to update to Intrepid yet. I just figured after I update to Intrepid it would fix the problem. Turns out it probably would have but I fixed it without having to upgrade yet.
This problem actually has to do with Gnome’s Accessibility settings! I found out that if I type 2,4,6, or 8 on the key pad it moved the mouse around by tiny amounts, almost unnoticeable.
To fix the problem I just went to System -> Preferences -> Assistive Technologies, clicked on Mouse Accessibility, selected the mouse keys tab and unchecked the “Allow to control the pointer with keyboard” option. That fixed it!