Programming
Adding ‘addremove’ to Git
I’m a happy git user, but mercurial has a nifty command with no git equivalent: hg addremove. This command removes deleted files from the repository and also adds new files in the current directory. For me, at least, it’s a useful command that I’d like to have. Of course, git is nothing if not flexible, so let’s add this command! I’m using a suggestion for a script that I found here. Add the following lines to your $HOME/.gitconfig:
[alias] addremove = !git add . && git ls-files --deleted | xargs --no-run-if-empty git rm
Tada—git addremove puts new files in the staging area and also removes deleted files. Now you don’t have to pay attention to your hipster friends who try to tell you how great mercurial is.
Using notify-send to Slack Off Efficiently
I’ve been working on a big project in MPI and the execution times on my code are annoyingly long (on the order of minutes). I like to keep my work in a separate workspace from my browser to minimize distractions, but then when I set my code running and head over to visit reddit or something I often don’t notice when my code finishes. Today it occurred to me that this would be a good use for libnotify. There is a command-line utility called notify-send (you should have it if you have a recent version of Ubuntu; not sure about other distros) which gives a simple interface to libnotify, so I whipped up a tiny script to call it:
#!/bin/bash EVAL_STRING="notify-send -u normal -t 5000 -i info \"Task completed\" \"$@\"" eval $@; eval $EVAL_STRING
I put it in a folder which is in my path, and now I just do
$ notify ./takes_forever
and I know as soon as it’s done. OK, back to work.
First Thoughts on Scala
Over the past week or so I’ve been looking into the Scala programming language. If you aren’t familiar with it, Scala is one of a group of new-ish languages including Groovy, Clojure, and Nice (as well as new implementations of preexisting languages like Jython, JRuby, and Rhino) that run on the JVM (either interpreted or compiled to Java bytecode). Over perhaps the past decade the JVM has been increasingly seen as an attractive target platform for language development for several reasons:
- Implementation in Java instead of C
- Features like garbage collection, portability, and a huge standard library come for free
- Languages benefit from advances and optimizations in the JVM
(This is part of a trend pointed out as Prediction #4 in a list of 10 predictions about software Steve Yegge made about 5 years ago.) In fact, targeting a virtual machine has almost become the only way to implement new, fancy languages with reasonable performance, portability, and implementation time.
Interfacing C and Python 3 using SWIG
I like Python, and I use it for almost all of my personal projects and whenever I can get away with it in school. Sometimes, however, (rarely, these days) you’re looking for raw speed. Python, alas, is not the fastest kid on the block, and at these times you might have to turn to a different language to give you the necessary speed. (Another option you might consider first is Psyco.) In these situations it is often the case that only particular operations or functions really have to be fast. Even if you want to write the whole piece of software in C, you might like to use Python to write the front end. There are a lot of different ways to do this, but my favorite is SWIG, because it’s easy and I’m lazy.
Comments, Please
I just put up the comments. This took a few hours of work to get right, and I suspect that there are still bugs. The formatting seems to be great, but I think that there might be problems with submission. I’ve tried to make it somewhat secure by stripping most of the nonsense you could put into one of the form strings to cause nasty things to happen. So (fingers crossed) it should be safe from SQL injection, XSS trickery, or html that messes up the page too much. › Continue reading
RSS Goodness
I’ve set up a lovely RSS feed for the site. Please subscribe! I actually don’t use RSS feeds myself, although I set up Google Reader a long time ago with all of my favorite feeds. I know quite a few people who use Google Reader to aggregate all the content from sites they frequent. I still love going to the sites, though—having it all in one place makes me feel like I’m wasting time too efficiently. › Continue reading