Archive for the ‘Uncategorized’ Category

Removing applets from Gnome Panel / Resetting Gnome Panel

No Comments »

So, I was adding applets to my panel and there was one that was messed up. I looked in the gconf-editor and noticed a ton of the applets that I was adding but they were not showing on the panel so I couldn’t delete them. Well, if you want to delete panel applets that you can’t see then open up gconf-editor and navigate to apps/panel/applets and find the name of the key that is the applet you added. It will most likely be named applet_#, look at the bonobo_iid to find out what the applet is.

gconf-editor

gconf-editor

Once you have the name then run the command:

gconftool-2 --recursive-unset /apps/panel/applets/your_applet_name

If you want to destroy all your panel applets and start over then do:

gconftool-2 --recursive-unset /apps/panel
gnome-panel --replace

SSH Tunnel Quick Reference

No Comments »

This is really for my own benefit and quick reference. Here is the command to setup a local tunnel to a remote machine using ssh:

ssh -f -L [local-bind-address]:{local-port}:{endpoint-machine}:{endpoint-port} -N user@ssh-host

The options used:

-f – go into background before executing any commands
-L – For port forwarding [bind address:] local port : host : hostport
-N – Don’t run any commands on the remote SSH host, just set up the tunnel

The nice thing about this is that the endpoint machine can be different from the ssh host and the name used is in fact resolved by the remote ssh machine.


Fixing messed up permissions on a linux filesystem

No Comments »

Ever accidentally change permissions on a filesystem and don’t know what it was before or how to get it back? Me too…

I was messing around with openSuSE the other day. I installed it on another partition on my hard drive. I mounted my Ubuntu partition and was just trying to copying some stuff over. In one of my dumbest moves I did something to the effect of chmod a+rwx /media/ubuntu, effectively screwing up all my permissions…I honestly don’t know what I was thinking.

Just recently I booted into my Ubuntu installation and noticed something weird when I logged it. It said that it couldn’t read some .dmrc file because of wrong permissions. I just fixed the problem and carried on. Then as I was trying to run a command with sudo it gave me the same error, that the permissions on /etc/sudoers was wrong. Good luck fixing that without a root password.

So I went back to openSuSE and wrote a little script that would fix the permissions as much as possible. I had another Ubuntu system that I mounted using sshfs and then basically searched for every file that existed locally on the remote machine and took the permissions from the remote machine’s files and copied them locally to fix the issue. Obviously it would not catch every file because I have different things installed on each but since they were both Ubuntu machines it came out close enough.

So here is the script I used, hopefully it will be of help:


#/usr/bin/env python
import os, stat, sys

def get_perms(path):
	st = os.stat(path)
	mode = st[stat.ST_MODE]
	return mode & 07777

def set_perms(frompath, topath):
	os.chmod(topath, get_perms(frompath))

if __name__ == "__main__":
	print "copying perms to %s" % sys.argv[1]
	print "looking for similar files in %s" % sys.argv[2]
	if raw_input("do you wish to continue? ").lower() == "y":
		for root, dirs, files in os.walk(sys.argv[1]):
			for f in files+dirs:
				topath = os.path.join(root, f)
				frompath = topath.replace(sys.argv[1], sys.argv[2], 1)
				print "doing %s -> %s" % (frompath, topath)
				if os.path.islink(topath):
					print "file %s is a link, skipping" % topath
					continue
				if not os.path.exists(frompath):
					print "file %s does not exist to copy perms from" % frompath
					continue

				#print "frompath %s, perms %o" % (frompath, get_perms(frompath))
				#print "topath before to %s, perms %o" % (topath, get_perms(topath))

				set_perms(frompath, topath)
				#print "frompath %s, perms %o" % (frompath, get_perms(frompath))
				#print "topath after to %s, perms %o" % (topath, get_perms(topath))


Akregator starts with error message ‘Unable to load storage backend plugin “metakit”. No feeds are archived’

2 Comments »

I was just playing around with different feed readers lately. I enjoy Akregator because it gives me all the options I need and probably the feature that I like the most is that it displays the number of unread items in the system tray and can be minimized to the tray as well.

I have installed Akregator on my machine at work and everything was working great. I installed it on my laptop and was having a problem that showed a message ‘Unable to load storage backend plugin “metakit”. No feeds are archived’ and all feeds were marked as unread even though it had previously been read.

Found a fix that was pretty simple. Just run kbuildsyscocoa from the command line and start it up again. Works like a charm.


Killing a thread in Python

No Comments »

I have been searching for quite a while for information on how to kill a thread in Python and I finally found a great solution. I was just about to implement my own way of doing it but it is not as clean as this way (although killing threads is not clean in the first place).

My thought was to use threading.settrace() and set my own trace function for every thread that is started. That way every thread will have to pass through the trace function in oder to continue executing and it doesn’t matter where in the code it is at or going. In my trace function I was going to add an Event that it would wait on if I want to pause execution of the thread, or check something to make it through an execption to exit out of the thread.

I was in the process of searching for a way to find out if a thread died because of an Exception when I ran across a post here: http://www.dlevel.com/blogs/alex/20

What they have done is added a terminate() method to the Thread class in the threading library. This will throw a SystemExit exception and quitely terminate the thread. Just take the code and paste it into a new module and use that Thread class as opposed to the threading.Thread class.

I agree with what he says about using this. Obviously it is not very safe to do this but in some cases you really need a way to terminate a thread and if you are careful it can work out ok.


Interesting Python Static Attributes

No Comments »

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.


Find the number of files in a directory

No Comments »

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


Twitter Me This

1 Comment »

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.


Numpad not working in Ubuntu

1 Comment »

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!


SSH Filesystem

No Comments »

Holy cow, this about blew my mind. I was working on a simple little website that had no FTP access so I was just planning on copying all the files down to check out the site and see how things were working. Obviously it is not fun to do that. Well I did have SSH access to the server and so I was trying to see what images were which, well, I didn’t really want to scp all the files I wanted to preview one-by-one. Oh, and I didn’t have root access and wasn’t sure if it had NFS available or not. That’s when I found out about sshfs!

With sshfs I can mount all the files locally over an SSH connection! To do this I:

sudo apt-get install sshfs

Edit /etc/modules and add a line that says ‘fuse’ if it is not there already

Add myself to the fuse user group:

sudo adduser username fuse

Then just mount the filesystem:

sshfs username@host:/path/to/remote/files /media/mount-point

Then to unmount do:

fusermount -u /media/mount-point

That’s it. It was so nice to work on all the files using my local tools and apps. Obviously this is not the best idea for changing a production server but it just provides a little nicer look at the remote files.