Wednesday, August 1, 2012

Notes for setting up a new Mac

  • Install xcode
  • Install brew
    • Move /usr/local/bin higher up in /etc/paths
  • Install git
    • Config user and email
    • Add SSH key to github
    • Clone linux files repository
  • Install macvim
    • brew install macvim --override-system-vim
  • Install the newer version of iterm2

Sunday, May 27, 2012

Os X vim/git configuration

I spent a while today finally ironing out some small annoyances I've had for a while with my OsX development setup. I had some problem setting the EDITOR variable for git. Even though it was set to vim and which vim showed me /usr/local/bin/vim, whenever I would run git commit the standard OsX version of vim would open up. I ended up just setting EDITOR to the absolute path.

Next up was finally figuring out a way to get a simple way to press esc when using vim. Earlier I had resorted to using ctrl-[ but I was getting really fed up with it now. I found two nice additions to the Os X preferences called KeyRemap4MacBook and PCKeyboardHack. What I wanted to do was change my left control to be esc and change my caps lock to be left control. I have a Japanese Macbook Air where the keyboard looks like this: ovI/AAAAAAAAKfs/c-IVbHNOGPg/s1600/Japanese-MacBook-Air-Keyboard-Layout.jpg I had some trouble initially since my mapping from caps lock to control would end up being translated to esc as well, because I had remapped control to that. In the end I managed to hack my way around the problem by adding a custom mapping for esc to control. And then map caps lock to esc instead... Confusing, no?

This is the curse of wanting to eliminate all the small annoyances you have while programming. Now back to trying to set up a portfolio page on github pages.

Tuesday, August 16, 2011

Compiling Vim on Ubuntu Natty

The latest version of vim 7.3 included in Ubuntu Natty has a bug (Ruby-related I think) that causes the awesome command-t plugin to stop working. To get around this you will have to compile vim yourself to get to a higher patch level. I've done this a couple of times recently but always forget which dependencies need to be installed and which configure flags to enable and which make targets to run if you change stuff. So I thought I'd try to document my findings in case I have to do it again and to try to figure out exactly which packages need to be installed. On some occasions I've ended installing hundreds of megs of dependencies just to be on the safe side.

1) First you need to clone the vim repository using mercurial, this step is easy and is described on the official site:

2) Install dependencies: sudo apt-get build-dep vim This pulls in about 554 MB of stuff at the time of writing and I'm not sure if all of it is needed but it at least is quick to type. Running configure at this point, gawk was still missing.

2) Next you need to configure the build you create. I've found the following to be smallest subset of required flags: ./configure --with-features=huge --enable-rubyinterp

3) then make and make install

Friday, May 13, 2011

Deploying a Django app with Apache and mod_wsgi

At work recently I've been deploying a small Django app. It's taken quite a long time. Most of the time things have been moving forward nicely but every now and then there has been some misleading detail in some instruction which has made me stand in place for a long time.

In a nutshell (on Ubuntu)

  • Apache needs the mod_wsgi module

  • Use the WSGIScriptAlias directive to point to the location of your project's .wsgi file

  • Point to your settings in the .wsgi file

This procedure is described in How to use Django with Apache and mod_wsgi


  1. I used virtualenv to prevent the installed modules from conflicting with other modules. This meant I had to follow the Virtual Environments section of mod_wsgi's wiki. You don't have to follow these instructions precisely. The instructions are aimed at preventing system-wide modules from shadowing/overriding modules in your virtualenv. Simply using site.addsitedir with the virtualenv's site packages directory worked for me.

  2. NOTE! The instructions in Django's docs also neglected to mention that you have to append two paths to your sys.path. You have to append both your project's path as well as the project's parent's path. If you don't add the parent you can't specify os.environ['DJANGO_SETTINGS_MODULE'] prefixed with your project's name. If you don't add the project itself you can't import the apps inside it.

  3. The server that was going to run the web app only had Python 2.4 installed. I wanted to make sure that my development environment would be reasonably close to the production environment. Installing an older version of python was very easy. All you had to do was use make altinstall instead of make install. However, now you also need to compile the mod_wsgi module manually. You use the --with-python=/usr/local/bin/python2.4 configure flag to specify which version to compile for. Then when you make the module it ends up in a hidden .libs folder. Move it from there to Apache's modules folder. I chose to rename it to or something so it wouldn't overwrite the module installed by apt-get earlier. Check some .load file from your /etc/apache2/mods-available/ for reference. Then you can add your own wsgi_2.4.load and wsgi_2.4.conf files to mods-available and use a2enmod to enable it. Now since you are using your own vintage Python version you have to additionally use the WSGIPythonHome /usr/local/ (or something, my mind is a bit unsure of this detail at the moment) directive to specify the prefix to your Python installation.

  4. Finally if you are serving static content (css, images, js etc.) you should be doing that straight with your web server instead of through Django. Django has a very nice app called django.contrib.staticfiles which through adding STATIC_URL to your file, adding django.core.context_processors.static to TEMPLATE_CONTEXT_PROCESSORS and prefixing your static urls with {{ STATIC_URL }} allows you to easily serve files with runserver. Then for production use you will want to set up the STATIC_ROOT variable in, put application-specific media in a static folder and run collectstatic to have all your media files transferred into the STATIC_ROOT. Now you can serve the files from this location by using the Alias directive in Apache for example.

I felt way more l33t when I had to set up the 2.4 version of Python manually than by simply installing everything through apt-get like a n00b.

Google Nexus S

Earlier this week I finally decided to upgrade my old Nokia E51 to an Android phone. Iphones are cool and all, but as a programmer who would like to make some apps of my own, it would be too much to have to both get a Mac and learn objective C as well as iCocoa-whatever-it's-called. You can even code Python on the android!

I think I bought the E51 around 2007-2008. It was good enough for some basic web surfing and worked excellent as a mobile broadband device on train trips at least. However, for a long time I've felt inferior to all the smart phone owners.

I'll get the minor problems I've had out of the way first, so I can end on a positive note. The wlan at the office has been very weak. It has seemed to work fine in my wlan at home though. I was able to download some of my Spotify playlists without problems. Also Angry Birds crashed during start-up and after that there was some bug that shifted the whole set of levels one step down, so I had to reset the game's data.

Apart from these problems, I've been very satisfied with the Nexus S so far. The jump in web browsing convenience from the E51 is huge. The UI is very smooth. One of the reviews I read before getting the phone mentioned something about slight delays in the UI, but I haven't noticed anything. Setting up e-mail was incredibly easy. I guess it helps that I use gmail both for my personal e-mails and for my work e-mail. Now I get nice little notifications every time I get an e-mail to either of them.

There are a lot of nice touches too. I like the effect when the screen is turned off which looks a bit like an older TV screen being turned off. There were some pretty nice blip and blop message notification sounds to choose from.

There are still many areas I haven't explored that much yet. I have only tried taking two pictures so far. Both of which seemed perfectly fine. I haven't tried tracking that much with the GPS yet. There are still a lot of settings to explore. Today, for example, I figured out that it was possible to easily switch between languages while typing an SMS. Another thing which is a bit unclear is how to tell which apps can show a widget with extra information on the home screen.

I've only downloaded free apps so far, so I don't know if you can buy apps without a credit card in Finland yet. Not that it matters that much to me. I have to say I'm a bit overwhelmed with all the crap apps in the app market though. I would much rather have an app market which is free from Coder Joe's MyFirstAndroidApp which is either a crappy clone of some other game (like Angry Birds, Bejeweled or Tetris) or some lame memory game with naughty pictures. Google, please give us a way to filter these apps out!

Well I guess that's about it. This was just supposed to be a brain dump about my initial opinion of my new awesome phone.

PS. The image entering functionality on blogspot (blogger?) is awful. I tried putting the cursor where I wanted the image to go. Press "Add Image" and both of my uploaded images go to the top of the article. No way to drag them in the Compose view. So you have to edit the hellish html to get the image where you want...

Tuesday, March 22, 2011

O'Reilly Disaster Relief 50% Special Off E-books

Today O'Reilly had a great 50% sale on all e-books with all revenues going to the Japanese Red Cross for disaster relief after the earth quake + tsunami from about 10 days ago.

I bought the following books for a rainy/sunny day:

High Performance MySQL, Second Edition

I personally prefer Postgres. I think MySQL feels a bit flimsy for some reason I can't articulate. However MySQL is still very widely used and I felt that whatever lessons I learn from this book probably applies to other SQL databases.

Canvas Pocket Reference

I coded a simple clickomania code with a friend at work which uses canvas for drawing so I was interested in learning more about using canvas.

Programming Android

I don't even own a smart phone :( But I'm still interested in learning about programming for Android. I'll probably end up owning one sooner or later. Just not in a hurry to get one.

TCP/IP Network Administration, Third Edition

This is probably a lot of stuff that I already learned in school many years ago. But I feel like I still have some gaps in my understanding. Gaps that don't usually affect my every day work, but gaps that I still want to fill, well just because.

Anyway, this was a great move by O'Reilly. They deserve a lot of credit for putting this special together. The total paid amount is at $70k at the moment. Let's hope it goes even higher and that Japan finally gets the power plant situation under control.

Monday, February 21, 2011

"The web" has been replaced

I'm working on my own Rails application during evenings at the moment just wanted to point out something I already had noticed a few months ago: most of the old technologies that made up "the web" a while ago have now been isolated through a new layer of "languages" (I hesitate to call html and css languages).

JavaScript can now be written using coffeescript. CSS can be written using sass/scss/less. HTML can be written using haml. Now there might have already been replacement technologies for all these areas a long time (don't know too much about alternative browser languages), but now it's really feeling like these technologies are good enough to be used in real projects.

My Rails application is going to attempt to use all of them. While I think haml is nice and clean and it's great to not have to type all those annoying angular braces, I'm even more excited about coffeescript and scss. As most people who take the time to learn JavaScript notice, it actually has some really good parts but it's bogged down by some pretty last-millennium syntax and some really awkward design and implementation mistakes. On the other hand, I think coffeescript has the nicest syntax of all languages at the moment.

I haven't really used the CSS replacements that much yet. Layout and design aren't my strongest areas. However in nearly every web application I've worked on so far, the CSS has been very messy. I'm hoping that scss might help alleviate this problem.