Ionrock Dot Org

by Eric Larson

My Weblog

Finally Learning Lisp

I've tried and failed to learn Lisp more times than I can count. At this point there are no theories as to why it has been such a challenge. Fortunately, I'm pleased to announce this last foray has proved to be much more fruitful.

It started with the simple task of wanting a better view of a csv file. At work we export data and one of the simple formats is csv. Since my computer life increasingly revolves around Emacs, it seemed like it would be nice to find a way to convert a buffer with a CSV file to a table in org-mode. Emacs makes it really easy to send a selection to shell command, so the pattern was already in place to implement this in Python. After my Python version was done though, it seemed clear it should be relatively easy to write it in Lisp.

The first steps involved doing a little string manipulation. Taking a line and turning it into an org-mode table line was pretty easy:

(defun addpipe (line)   (concat "| " (mapconcat 'identity (split-string line ",") " | " ) " |")))

That effectively splits the line by commas and immediately puts it back together, replacing the comma with a pipe. It then adds a pipe on either end.

Next up was to select the text in the current buffer, split it by new lines, and format each line placing it in another buffer for viewing.

((defun csv2org ( )   (interactive)   (setq buffer-text (buffer-substring (point-min) (point-max)))   (setq prebuffer (delete "" (split-string buffer-text "\n")))   (setq mapped-buffer (mapcar 'addpipe prebuffer))   (with-current-buffer (get-buffer-create "*csv2org*")     (dolist (line mapped-buffer)       (insert (format "%s\n" line))))   (set-buffer "*csv2org*"))

I'm sure smarter folks than me a more elegant way of doing this, but it worked for me and fit my understanding of the problem. For example, creating the "*csv2org*" buffer most likely has its usability issues. That said, I'm pretty happy that I was able to get what I wanted basically working. Obviously there is a great deal more to learn when it come to working with Emacs in Lisp, but this experiment is getting marked down as a success.

While there were not any major revelations, things started clicking more than before. One helpful bit was becoming more comfortable with executing Lisp in Emacs. Using the scratch buffer, it became easy to play with the function and setup a simple development pattern for trying things. Also, all the Emacs and Lisp bookmarks I've recorded over the past couple years ended up providing useful tips for getting further along than before.

For my next trick, I'm going to implement a simple way to paste code to http://rafb.net/paste. Fortunaely, I've already started making progress and despite not finding much information on the URL Package, it seems like it shouldn't take much to get it working good enough.

Posted Mon May 4 15:39:00 2009 by Eric Larson

Catching Up

Since SXSW, I've been in something of a catch up mode trying to finish up a major upgrade to the latest jQuery at work and it has been pretty time consuming. I work on a pretty Javascript heavy application at work that has gone somewhat stale. They say if it's not broke, don't fix it and we did just that. The impetus then to go ahead and take the plunge to upgrade jQuery was a bug in IE 8 that had to do with the scrolling plugin we were using. A few tests were put together and we found that the latest jQuery would do the trick, so that started us down the path. We found out later the bug was actually an IE 8 release candidate bug that had been fixed in the released version. It was somewhat disheartening to do so much work on a bug that wasn't actually a bug. Since we have a shiny new jQuery, I'm not all that upset.

In our case the 80/20 rule was very much true. The first step was to change the script tag to the latest version, run the tests and see what breaks. After changing some of the API calls, the vast majority of things worked. I'd say around 80% in fact! The things that didn't work were a bit more troubling. One of the major changes was that we moved from using the old interface library to using the new jQuery-UI. This seemed to be a good idea as there were some helpful updates to the widget APIs as well as an entirely new widget and theme pattern that could be helpful. Unfortunately, what caused the most trouble was upgrading our code that used the old widgets.

One interesting aspect the jQuery team added was the inclusion of themes for UI widgets. This required making a difficult decision regarding how a UI widget is implemented in the DOM. The basic options are to 1) ask the user to declare the different components on page or 2) as the user to declare a container where the widget will fill in the required DOM elements. The first option is a tedious one since you will need to code for many different cases and define not only the required elements, but rigidity of the markup. The second option is also difficult because you have the obligation to expose the HTML the widget will write in order to allow setting the state of the widget (ie when a user goes back). The jQuery team chose the second option and it seems to be the correct decision. While it definitely caused me quite a bit of grief understanding how the widgets changed, in the end, the pattern seems like the best trade off.

Another aspect of the upgrade that I thought was interesting was the disparate documentation out there for making a jQuery plugin. I have been writing most of my javascript code as jQuery plugins in order to keep everything within their framework. My reasoning is that I can push the cross browser issues to the library and hopefully save myself some time. The problem is that there are quite a few plugin tutorials that all offer slightly slightly different views of how to properly write a plugin. After reading some mailing list posts and seeing the new widget API in jQuery-UI, it is clear that this problem is being addressed, albeit with caution. The unanswered questions regarding how to write a plugin stems from the flexibility found in Javascript. You can write code in such a wide variety of styles that choosing one or even recommending one is difficult. While I was not able to utilise it, the jQuery-UI widget API is a huge step towards providing a plugin pattern that I hope will eventually be extended to general jQuery plugins.

This upgrade has been pretty tough and I'm sure part of that was my own fault. My tendency was to try not to change the way the widget worked. My logic was that the algorithm had worked previously, so changing things radically would only present the opportunity for new, unknown bugs. While I still think this is true, one side effect of reimplementing things is that you have the opportunity to see what the underlying library is doing with less distractions as well as understanding potential pitfalls the previous author might have already solved. It is also relatively painless to make a go at reimplementing things and drop it if it becomes obvious you are on the wrong path. As I move forward I think my goal will be to make creating one off revisions of things as quickly and easily as possible. I'm not sure how best to do that but I have feeling if I streamline my experimentation workflow, the result will not only be more ideas getting fleshed out, but a better understanding of bugs that I'm fixing.

Posted Tue May 12 19:09:09 2009 by Eric Larson

Checking out the Zoo

Over the weekend we went to the Austin Zoo. It was a really good time. One of the tigers was in some play area where they put meat in the trees, so he was really active "hunting" for the surprises.

The Austin Zoo isn't a huge zoo. There is not an enormous facility or any sort of major features. From what I gather, it is much more focused on helping animals that were forced to enter into captivity. This makes zoo feel a little closer to a rescue facility than a typical zoo. Unfortunately, this also makes it clear that the zoo needs better funding. You can see cages where they simply put sheet metal on top with some large rocks to secure the makeshift roof. There empty cages that serve as storage for tools. Sometimes the cages seem a little smaller than expected. While I'm sure the zoo keepers know what they are doing, it does make one wonder what kind of oversight is involved in running a zoo. I also wonder if the Austin Zoo is really associated to the city or it is just a name some group was able to use.

In any case, my impression is not meant to be condemning. Instead I'd hope someone reading this might consider how they can help. We made sure to spend some money in the gift shop as well as make a donation. It wasn't much, but if more people visit, it can only help improve the situation. And despite the humble surroundings, it really is a ton of fun.

I know for a fact that non-profits are hurting right now. The economic downturn really puts a damper on this critical part of our society since they are already being run through the extra resource people have. When it seems like there isn't any extra, that means the non-profits get cut out. This is really a shame if you ask me. If you work, you are likely to pay taxes and that means funding non-profits as the government is a pretty huge contributor. When you pay taxes, you effectively lose the choice of where that money goes and in effect, you might very well be funding something you don't believe in. When you contribute to a non-profit, it is your choice. You can remain local if you'd like or try helping a global issue. The important thing is that you get the chance to make a choice.

This kind of turned into a rant, so my apologies. I'm not asking for money or anything, just sharing an observation I had at the zoo.

Posted Mon May 18 15:54:25 2009 by Eric Larson

More on Using Linux

Recently, I started using my Linux partition on my macbook and so far, things have been running pretty smoothly. I'm enjoying stumpwm with my two monitors and I'm pretty comfortable with the setup. That said, there are always some small oddities and frustrations that seem to creep in.

My biggest gripe is sound. It is unclear what Apple does to make the internal speakers sound reasonable. What is clear is that Ubuntu is not doing the same thing. While I was pretty happy my Apple keys worked for turning up and down the volume, the actual sound out of speakers is pretty terrible. It nothing headphones doesn't fix, but still a hassle.

Another issue is the sound server. In linux there are a set of back ends that "talk" to your sound hardware. Gnome (or Ubuntu) seems to adopted Pulse Audio, which is a compatibility layer on top of the lower level back ends. From a programmers prospective, this abstracts some of the more complicated issues and allows for a simpler API. From the users perspective, things just work and all seems to be well. In actuality, what really happens is that Firefox seems to eventually stop playing sound (ie Flash) and both Firefox and the Pulse Audio session need to be restarted in order to listen to hip new indie music. I'm sure much of this process has to do with the Flash plugin, but from the standpoint of a user, it's a pain.

Generally, I've found everything to be rather stable, with the exception of Firefox. It seems to always crash at some point. Flash is most likely the culprite, although I really don't spend very much time on sites using Flash. It just occurred to me that it is possible ads might be the main source of bad Flash, so I'd wonder if an ad blocker plugin might help. I'm not really a fan of ad blockers since advertising is such a critical part of the web ecosystem, yet I'm downright sick of Firefox crashing, so it might just be the way to go.

There are other issues of course. I'd like to gnome terminal, but I can't get the fonts to look like a regular xterm. I'm using Gnome with stumpwm so Adobe Air apps don't complain. This adds the gnome tool bar which is rather unnecessary. Gripes aside, it has been really easy to get back into Linux on the desktop. It is a lot of fun to have a system you can tweak to your liking. It is also kind of fun to have things to work on. While my sound issues are definitely a pain in the neck, it also gives me something to try and fix, which generally means understanding more about my system. Most of the time it is not the most useful knowledge, but often times it is really helpful stuff. For example, setting up my VPN to only be used on selected traffic. I can't say I'd reccommend using linux to everyone, but if you are using OSX because it's a *nix, it is worth trying out linux on th desktop.

Posted Wed May 27 16:11:00 2009 by Eric Larson
Created using Python, jQuery and Emacs