Archive for the ‘programming’ Category

stumpwm — wow

Thursday, September 18th, 2008

I had a long train ride today, and little battery life left.  So I read the manual for stumpwm and played with it.  Wow.  The real key for me was figuring out how to restore windows to full size after splitting them “C-t Q”.  So here are the commands that I use to navigate stumpwm
“C-t s” splits a window (actually a frame in stumpwm parlance)  vertically — making it half as tall

“C-t S” splits a window horizontally — making it half as wide (horizontal vs vertical splits may be obvious to some people but they always seem to trip me up when I read them).

“C-t f” puts a number in the upper left hand corner of each frame, pressing the number for the frame you want to go to will do that.
“C-t Q” makes a window full-screen
“C-t w” lists the windows — applications running

“C-t #” where # is the window you want to use, brings that window to the top of it’s frame and puts focus there

“C-t C-#” grabs a window from whatever frame it is in, and pulls it into your current frame

getting emacs, a terminal (for emacs to run in), and firefox were all major amounts of damage, that I have sustained for the last month or so.  Firefox was by far the hardest, when I get FF3 setup in x on OS X I will write about the process.

Here were links that helped me

http://stevey-home.blogspot.com/2008/04/osx-for-emacs-users.html

http://tiny-tools.sourceforge.net/emacs-keys.html  — i’m still digesting this but it seems to be the msot thorough explanation of xmodmap and emacs key oddities that I have seen.

by using xev, I have figured out that I have 9 seperately addressable modifier keys available to me , counter-clockwise (capslock, l-shift,l-ctrl,windows,l-alt,r-alt, windows-context,r-ctrl,r-shift).  freaking sweet

Getting the SVN revision number of a file in python

Thursday, September 11th, 2008

I’m writing out data from python programs and it is important to have an audit trail.  I decided that I would write out the SVN revision number of the code generating the reports, into the reports.

Getting the svn revision number of a file is fairly straight forward in python:

os.popen('svn info %s | grep "Last Changed Rev" ' % fName, "r").readline().replace("Last Changed Rev:","")

that acutally returns a string with the revision number in it.

Thats a bit of code though, and I didn’t want it sprinkled, duplicated, all over my different python files

so I put it in my util library

in python, grabbing the name of the file you are working from is fairly straightforward:

__file__

however, since I was writing this in my utility library, I didn’t care about that file’s name, I wanted the name of the calling file.

I figured that out

fName = sys._getframe(1).f_code.co_filename

this gets the name of the file 1 call up the call stack

combining these I ended up with

def getSvnVersionOfFile(fName = sys._getframe(1).f_code.co_filename):
return os.popen('svn info %s | grep "Last Changed Rev" ' % Name, "r").readline().replace("Last Changed Rev:","")

Security Anomally in CoreGraphics Event Taps

Thursday, September 4th, 2008

When I was playing around with changing modifier keys for OS X I stumbled onto some inconsistencies with permission requirements and abilities for two very similar event types.

The code I used here is modified from http://osxbook.com . You can view the code on github here https://github.com/paddymul/osx_keyboard_play
There are two programs included in the tar ball.  getKeyPressCode and insertKeyPressOnModifier. They have a very similar structure.  I will start by describing getKeyPressCode

GetKeyPressCode has two functions, main and a call back function.  A call is made to CGEventTapCreate , which passes the myCGEventcallBack function in (I’m hazy on my c code,  it must somehow pass in a pointer), and event mask flags for the type of event, in this case kCGEventKeyDown or kCGEventKeyUp.
The callback in getKeyPressCode displays the keycode for any character you press, in any application on the system. If you press the = key, it replaces that with ‘f’ .
To run getKeyPressCode, you need to be superuser (sudo) or have Assistive devices enabled.  Otherwise the program will fail saying, event tap failed to create.  Also notice that when you go to a  systemwide password box (such as you would be prompted for in keychain) , no keyUp or keyDown events are fired, even though the program was run with superuser privileges.

The second program is insertKeyPressOnModifier.  This program has the same form, the difference is that it catches modifier keys — CGEventFlagsChanged.  This program displays the EventFlags for modifier keys (“CAPSLOCK” , “SHIFT”, “CTRL”, “OPTION”, “OPTION/ALT”, “APPLE”) when a modifier key is pressed.  When any modifier key is pressed, the program inserts an “=” or “+” depending on whether or not shift was pressed.  Again this behaviour takes place in any application on the system.

Now the interesting thing is, you don’t need superuser rights or assistive devices enabled to run insertKeyPressOnModifier.  Even more interesting is, inserKeyPressOnModifier still fires events when you are in a system wide password box, it will also insert ‘=’ characters.  This seems like a potential security hole.

I filed a bug report for this a year ago, apple hasn’t responded or fixed the hole.  This I have observed this behavior on a Mac Book Pro running Tiger and Leopard.  I’m not well versed in C, CoreGraphics, OS X internals, or general security measures like this.  There could be a very good explanation for the behavior, to me though, it seems like an inconsistency that could be a hole.  I haven’t seen the password box behavior mentioned anywhere else.

You can look at the header file for CGEvent on your mac here

/Developer/SDKs/MacOSX10.4u.sdk/Developer/Headers/CFMCarbon/CoreGraphics/CGEvent.h

modding bs.el for emacs

Wednesday, August 6th, 2008

I use bs.el to switch between buffers in emacs.  I have bs-cycle-next mapped to C-Tab and bs-cycle-previous mapped to C-Shift-Tab .  The problem is when I quickly page through my buffers, the buffer list that shows up in the mini window rotates and the current buffer doesn’t show up in the list,

1-2-3-4-5 c-tab

2-3-4-5-6 c-tab

3-4-5-6-1
the position of buffers doesn’t remain the same, which makes it hard to quickly go to the desired buffer.  I wanted behaviour like this

(6) 1 2 3 4 5

6   (1)  2  3 4 5

6   1  (2)  3 4 5

With the included file, bs.el now behaves in the way I prefer.   This is the first serious lisp programming I have ever done, also the first mod I have made to emacs.

http://paddymullen.com/upload/try2-bsmods.el

TODO: figure out font-face-lock to get the current buffer highlighted instead of surrounded with pipes ||

I bought a 30 inch screen

Sunday, June 29th, 2008

I should blog about this now, while the imprint is fresh in my head.

1. I am moving from a laptop to a Samsung 30 inch lcd

2. It is big, huge, the way you use the computer will change.

3. Moving from a laptop, you have to get an external keyboard, get one you like.  I’m typing this on my father’s iMac keyboard right now, it sucks.

4.  Bump up your mouse acceleration,  A mouse is necessary with this size screen, forget a trackpad, and even a mouse is innadequate.

5.  Window management on OS X is severely lacking.  I really want to get stumpwm working.

So far I like it.

lispnyc

Wednesday, November 21st, 2007

I have started attending lispnyc events. Wow, what a group. This is the smartest room full of programmers I have ever been in. It is also a surprisingly approachable group. Whether or not you care about about lisp or functional programming I recommend that you attend. Not everyone there programs in lisp or even a functional language for their day job, they all care about programming though. As I learn more about lisp, through events like this, more and more thoughts pop into my head which enhances my code in less functional languages.

Delving into the Firefox source code

Friday, April 27th, 2007

Continuing from the previous post. I downloaded the Firefox source code and started trying to figure out why textContent was faster than innerHTML.

The FF source code is a daunting beast, around 57,000 files. I started with grep. this returned 57 files for innerHTML and 72 files for textContent. I then used comm to see which files had both words in them, only one did.

Somehow I decided to try looking at the idl files that grep returned. From these files I was able to figure out what I thought were the .cpp files related to the properties.

Here are links to the files on Mozilla’s website
innerHTML is found in this file
nsGenericHTMLElement.cpp
Here is a changelog of the setInnerHTML function
http://lxr.mozilla.org/mozilla1.8/ident?i=SetInnerHTML

Here is the cpp file that contains textContent
nsHTMLOptionElement.cpp
here is the changelog of the setText function
http://lxr.mozilla.org/mozilla1.8/ident?i=SetText

I haven’t actually yet figured out what each function does, but I’m getting there. I’m also not sure if I have the correct file for textContent.

speed of innerHTML vs textContent

Friday, April 27th, 2007

I was working on one of my js apps that updates the content of an element on mouseover. The performance in FF 2 was poor compared to all other browsers. After profiling with Firebug I realized that the problem was setting the innerHTML of an element. In Firebug, setting the innerHTML took about 3 times as long as the rest of the code for the mouseover, which included getting the mouse position, pulling a value from a large array, performing math on that number, and moving a cursor to the proper place on the screen.

I looked up the js docs, and found that FF elements have a property named textContent. I used this property instead of innerHTML, and performance for the mouseover doubled.

I was happy about finding this quirk. Then I told my friend Derik about it, he asked “did you look at the source to figure out why textContent is faster?”, then he called me a pussy when I told him I hadn’t.

The next post will be about delving into the Firefox source code

Why I chose to be a programmer

Monday, April 2nd, 2007

I’m not sure what to title this. “Why I’m not an economist… Why economists are hypocrites…” but I decided to go with something positive.

So I graduated about a year and a half ago with an Economics degree from George Mason University. I enjoyed the way my degree taught me to think and analyze things. I agree with the tenets of Mason’s econ program (free markert libertarianism). But I didn’t want to be an economist.

I realized that if I became an economist, I would sit in a room and write papers, do studies, and pontificate about things that I had no hope of ever changing. That sounded like a career of frustration. I also knew that my career would be dependent on intra office politics and more schooling compared to actual accomplishment and ability.

So I decided to become a programmer. I have used and programmed computers for years and started off college as a CS major (thats another story). I built a we app in my spare time ( http://formula1db.com ) a couple of weeks after I finished classes and was quickly hired. I chose to be a programmer for many reasons

1. I build things. I like building things and having a tangible result. I take pride in this and I get to do this with my career.
2. This is not a risk averse field. Yes I could hose a database or a server, but a properly architected system will have a backup plan. This allows potential employers and me to be much more daring. I was able to be hired with comparatively little experience because if I screwed up they would only be out my wage (I couldn’t nock down a building, kill a patient, or cause millions in financial damage by a mistake).
3. This is a field with low barriers to entry. This was important for me for my initial job but is also important for a couple of other reasons. I can cheaply start my own company, I only have to feed myself for a couple months. I can also practice at home on my own equipment to become better with my trade. Imagine a pediatrician asking to take a baby home for a night or two to practice appendectomys. Because there is a low barrier to entry this career also doesn’t suffer from ivory towers, any nobody can come up with a good idea, I like this because it keeps me on my feet.

Now I have tried to be positive, here is some friendly jabbing at economists, specifically free market classicals.

For a group which decries unions, government regulation, and barriers to entry aren’t they all hypocrits for chosing a profession which has all of those characteristics. (I will write the first comment on this article picking my arguments apart).

My degree advisor, Bryan Caplan has written many papers about why higher education is inneficient and should be disincentivized. This was a running joke around the department because he of course also argued that economists are important and should be incetivized, I think we all recognized the humor.

Publicly available subversion host

Tuesday, January 23rd, 2007

Subversion is crucial for my development efforts, without I spend a lot of time getting frustrated with things that should be easy.  Subversion is very useful even when I’m the only coder on a project, it is a necessity for collaborative development.   I wanted to get a subversion server that I could access anywhere in the world and that clients could access, they can’t get to my linux box sitting behind my cable modem.

I looked at getting a virtual private server, you get a good amount of space with them, but you have to setup subversion yourself.  Dreamhost now offers subversion hosting too, but I have heard mixed reviews about them.  Version control isn’t something I wanted to skimp on.  I ended up going with CVSdude hosted subversion.

I’m really glad I did, I pay less than a VPS for something that is up right now.  For $30/month I get unlimitted repositories (each client will get their own repository), and 5 Gigs of total space.  I also get web-svn, bugzilla, VC, and Trac project management.  Each repository gets its own trac setup.  All of this is managed with a decent web interface (it’s table based :( ), and it just works.   I probably saved at least 2 or 3 days of sysadmin work by going with CVS dude.  Comparative advantage is a great thing to remember.
The CVS Dude service has been good.  They have a good pipe, I get 40K up, and 600-900k down, I’m pretty sure my cable modem is the limit, those are about the most I get for uploads and downloads for other activities.  I misnamed my repository initially, thinking I was picking my admin name, instead that was the base name for all my repositories.  A short email to their support fixed that in a couple hours.  I am concerned about looking professional with a repository URL that looks like svn.cvsdude.com  luckily I can get a domain name for my repository and they say it will work.