Quick tip: Adding the current git branch to the shell prompt

January 26, 2010 chopmo Leave a comment

This information is readily available on the GitHub support pages, but I’m posting it here for reference (do I won’t have to dig it out again the next time I need it).

  1. Save this file somewhere and source it from your .bashrc or .bash_profile. This provides all sorts of completion magic for git, but I’m not really sure if it’s required for the prompt trick to work :-)
  2. Update your PS1 to include __git_ps1. Example:
    export PS1='[ \u@\h \w$(__git_ps1 " (%s)") ]\$ '

Voila! You now see the current branch when CWD is inside a git repo:

[ jtj@nova ~/projects/eldorado (railsforum) ]$
Categories: tips

Talking the talk

January 16, 2010 chopmo 2 comments

I have come to realize that I talk a lot about Clojure, but I don’t really use it.

I am very excited about functional programming in general and Clojure in particular, so I spend a lot of time catching up on the news on this front. Lots of stuff going on, always.

The other day I sat back for a moment and looked over the hundreds of blog entries piled up in my reading list. Suddenly I realized that most of these would be conveying actual experiences with some language or framework. Be it Ruby, Clojure, Erlang or what have you, these authors have actually tried something out and written about it.

This is more than I can say for myself, unfortunately. I do have several pet projects underway, but I’m not making nearly as much progress as I would like to. Why? Because I spend way too much time reading about new stuff. Reading about what everybody else have been making progress on.

So I have decided that I need to code more and read less. Pretty much the opposite decision from the one I made a few years ago, but hey, times change. It’s a tough balance to strike properly, but I guess we all do the best we can.

Right now I’m splitting my spare time between two areas: Functional programming and dynamic languages. More specifically Clojure and Rails. I have a lot of ideas for projects in both camps, but like I said I’m spending way too much time catching up. I have seriously considered ditching one of these areas completely, but I just can’t do it. Both are extremely interesting from different points of view.

And since I need be both places at once, I must be very careful about how I spend my time. If I want to move forward with my projects, I can’t afford to spend entire evenings reading up on almost a hundred technical blogs. Even worse, almost every single entry is tempting me to go on out on a tangent. So much interesting stuff to learn, so little time. But I’m not really in it for the learning. What I really love about being a geek is the part where I create new stuff. And I think that is what I’m good at, too.

I really need to start walking the walk. It’s OK that I’ll fall a little behind the newsstream, because I’ll gain a much deeper understanding of the areas I choose to focus on. And before long, I should be able to contribute interesting new stuff on my blog as well.

Categories: clojure, ruby, thoughts

URL ABC

January 13, 2010 chopmo Leave a comment
Categories: other

Chromium without the spellchecker on OSX

January 5, 2010 chopmo Leave a comment

I really, really like the Chrome/Chromium browser, and I’ve become more or less addicted to it. The ability to search directly from the address bar (or whatever it’s called) is a small but extremely useful feature. Also, in my experience it is both faster and less resource hungry than the alternatives, Safari and Firefox.

On Linux and Windows, I use it all the time without problems. But on OSX, one issue has just been too annoying to allow me to use Chrome exclusively: The spellchecker can’t be disabled. The issue it tracked here and here, they just haven’t gotten around to fixing it yet. And since I write a lot of email in Danish, all the red underlining it very distracting (I know that it can be disabled for one text field at a time, but that’s not very cool either).

So I decided to roll a custom build. As you would expect, disabling the spellchecker (permanently) is trivial:

Index: chrome/browser/spellchecker_mac.mm
===================================================================
--- chrome/browser/spellchecker_mac.mm	(revision 35439)
+++ chrome/browser/spellchecker_mac.mm	(working copy)
@@ -145,24 +145,25 @@
 static int last_seen_tag_;

 bool CheckSpelling(const string16& word_to_check, int tag) {
-  last_seen_tag_ = tag;
+//   last_seen_tag_ = tag;

-  // [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
-  // NSRange that we can look at to determine if a word is misspelled.
-  NSRange spell_range = {0,0};
+//   // [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
+//   // NSRange that we can look at to determine if a word is misspelled.
+//   NSRange spell_range = {0,0};

-  // Convert the word to an NSString.
-  NSString* NS_word_to_check = base::SysUTF16ToNSString(word_to_check);
-  // Check the spelling, starting at the beginning of the word.
-  spell_range = [[NSSpellChecker sharedSpellChecker]
-                  checkSpellingOfString:NS_word_to_check startingAt:0
-                  language:nil wrap:NO inSpellDocumentWithTag:tag
-                  wordCount:NULL];
+//   // Convert the word to an NSString.
+//   NSString* NS_word_to_check = base::SysUTF16ToNSString(word_to_check);
+//   // Check the spelling, starting at the beginning of the word.
+//   spell_range = [[NSSpellChecker sharedSpellChecker]
+//                   checkSpellingOfString:NS_word_to_check startingAt:0
+//                   language:nil wrap:NO inSpellDocumentWithTag:tag
+//                   wordCount:NULL];

   // If the length of the misspelled word == 0,
   // then there is no misspelled word.
-  bool word_correct = (spell_range.length == 0);
-  return word_correct;
+//   bool word_correct = (spell_range.length == 0);
+  // return word_correct;
+  return true;
 }

 void FillSuggestionList(const string16& wrong_word,

The diff is a bit messy, but I just commented out the entire body of the CheckSpelling method and replaced it with “return true”. As in “Sure, that word is correct” :-)

If you want it, you can download it from here.

Of course, this means that I now use Chromium instead of Google Chrome, but so far I haven’t noticed any adverse effects from making that switch.

Categories: other

Emacs 23 on OSX – pros and cons

January 3, 2010 chopmo 3 comments

I’ve been considering upgrading my Emacs installation on OSX for a while. Until now, I’ve been using Carbon Emacs, and I have been quite pleased with it.

However, Emacs 23 has been the recommended release for a while now, and it’s probably time to move on. So I thought I’d use this entry to sum up my findings so far about making the switch.

The facts

First, a note about naming. “Carbon Emacs” is Emacs 22.x, distributed by Apple (CORRECTION: No, it is built and distributed by Seiji Zenitani. Thanks Ian). Not maintained or supported by Apple, but they have a pretty download page for it nonetheless. As of this writing, the build is about 6 months old.

To get Emacs 23 on the Mac, you need the Cocoa version, called simply “Emacs.app”. It can be downloaded from here, and the current version is 23.1.

Pros

Much nicer fonts

Ah yes, this is what everybody has been talking about. I know very little about typography, but I think it has to do with antialiasing and the fact that Emacs.app uses the Cocoa libraries instead of Carbon (which has been around since Mac OS 9).

The fonts look great. At first I almost couldn’t tell the difference, but it becomes very apparent once you switch to a smaller font. In Carbon Emacs, I never managed to use a 10pt font for very long at a time, because it was pretty hard for me to read. Now, it is very clear. This is obviously a huge improvement because it allows me to have more text on the screen.

–daemon mode

I haven’t really played with this yet, but it looks cool.

This feature allows you to run emacs in “daemon mode”, meaning that it evaluates all startup files but does not open a frame. It then opens a socket and listens for clients.

To open an Emacs frame, use emacsclient. It seems to require a little extra tweaking in my setup, because when opening a client frame the toolbar is not disabled, the Meta key is not properly set up etc. But I’m sure that would be easy to fix.

The great news here is that it allows you to have one master instance of Emacs running and open files in it easily. For example, set your $EDITOR variable to “emacsclient -t”. The advantage of this method is that you can use the same instance of Emacs throughout your system. Right now I’m used to invoking something like “emacs -q -nw /etc/foo” if I need to quickly edit a file in the shell and don’t want to wait for my sea of customizations to be loaded.

Cons

weblogger.el is messed up again

I know I have no right to say this, but I want to be honest. This really, really pisses me off. I cannot believe how fragile the weblogger.el/xml-rpc.el combination is.

Until I updated to the latest versions, it didn’t work at all. I already forgot what was wrong, because I’ve gotten so used to just trying out all sorts of tweaks until it works (or I give up).

So after installing the latest versions, I am able to download the list of posts (with weblogger-fetch-entries). But alas, all of a sudden there is some issue with longlines-mode, so when writing a new entry, the text just becomes invisible. Figuring that out within a few minutes gave me a sense of Deja Vu. I must have been bitten by this issues at some time in the past, or I would never have figured out so quickly what was wrong. (UPDATE: It turned out that only the showing of hard newlines had to be turned off, and that this is not related to weblogger.el. But somewhere along the way, this entry was messed up so real newlines were inserted.)

Having to disable longlines-mode is painful to be sure, but the annoyance passes quickly as I discover another two issues.

After saving an entry (weblogger-send-entry) the *weblogger-entry* buffer is buried. Why?? (UPDATE: It turns out that this was also the case in the previous versions. I had just forgotten that I had made a dirty hack in weblogger.el to fix it).

Also, the interaction with wordpress.com is just painfully slow. It takes me about 10 secs to save an entry. I have no idea why that is. I haven’t started using https or anyting like that. A quick look at tcpdump reveals an 8 second pause that is new since my Emacs 22 setup.

twit.el broken

This is another regression I just discovered while writing this entry. When trying to run twit-show-recent-tweets, I get the following error.

error in process sentinel: Symbol's value as variable is void: url-http-attempt-keepalives

Again, no idea what is wrong. I updated to the latest twit.el (which worked fine in Carbon Emacs). When trying in an Emacs with no customizations, it just hangs.

Fullscreen mode broken

This is a well-known issue, and a pretty serious one IMO. I get some extra text from reducing the font size, but it is wasted on menubar and window decorations as long as I can’t properly fullscreen the frame.

Verdict

So, is it time for me to upgrade to Emacs 23? Absolutely not. It has taken me way too long just to write this blog entry simply because stuff keeps falling apart.

I’m afraid I’ll have to spend a significant amount of time tweaking all my customizations to work with Emacs 23. And I’m afraid it is going to be a while before I have nothing better to do. Until then, I’m stuck with Emacs 22.

But hey, that’s not so bad, is it?

Categories: emacs, rants, tips

Python performance on multicore systems

December 21, 2009 chopmo Leave a comment

Today I stumpled upon this excellent presentation by David Beazley about Python’s global interpreter lock (GIL).

I knew about this lock already, and I knew that it prevents parallel execution of threads in Python. What I didn’t know is that performance actually suffers on multicore systems!

Of course there’s a logical explanation for this, and David took the time to dig into the code and find out what is going on. And he does a great job of explaining it to the rest of us.

Highly recommended if you want to know more about Python threading and signal handling.

Categories: concurrency, python

Growing up as an Emacs user

December 19, 2009 chopmo Leave a comment

Today I took another step towards Emacs adulthood: I disabled transient-mark-mode.

Big deal, you say? Well, I vividly remember the relief I felt when I found out how to enable it as a novice Emacs user two years ago. Not having a visible selection was just too wierd.

But now I’m ready to change that habit as well. I enjoy the reduced visual clutter, and ironically, I find it easier than before to quickly extend the region to the part of the buffer I want. A frequent annoyance with transient-mark-mode enabled was that I often highlighted text by accident.

However, I’m a bit annoyed that some commands don’t behave the way they used to. For example, comment-dwim (which I use a lot) needs transient-mark-mode to be enabled on the region to (un-)commet. I know that I can temporarily enable transient-mark-mode by doing two C-SPCs instead of one, so I guess it is a small price to pay. But I don’t understand why it can’t just work on the region.

I’m not sure why I suddenly decided to ditch transient-mark-mode. Maybe I accidentally highlighted a region one time too many. But it got me thinking, yet again, about the way I use Emacs. I’ve used it for a few years now, and I think I know and use the most important productivity tricks. But obviously I know that there’s so much still to learn. And now that I feel comfortable, moderately productive and (most importantly) almost never annoyed at anything, I don’t learn as much as I should. I still customize stuff at least few times a week, but I don’t learn significant new features, modes etc. very often.

I want to change that. I really want to be an Emacs wizard, not just an experienced user.

So where should I find inspiration to learn new stuff? The hard part is that I don’t know what I’m missing anymore. As a novice user, I knew what Emacs could do, but not how. Now I need to find out what else Emacs can do. Apart from the plentitude of Emacs-related blogs out there, I’ve found a really good source of inspiration. At VMware, we have a “Tips & tricks” mailing list to which I’m subscribed. Often, useful Emacs, Vim, Sed, Awk etc. tips are posted on that list. I just need to pay attention, which can be hard when you receive hundreds of emails every day.

So let that be the tip of the day. If you work with other Emacs users, learn from them. Create a forum on which you can exchange tips and tricks, be it a mailing list, wiki page or whatever.

And be sure to forward a copy of each tip to me ;-)

Wow, that entry ended up way too chatty.

Categories: emacs, thoughts, tips

Funding the development of Clojure

December 16, 2009 chopmo Leave a comment

Rich Hickey has done a pretty amazing job, mostly single-handed, of creating Clojure. Aside from the popularity of the language itself, Clojure seems to have inspired even more people to start talking about functional programming.

However, Rich is going to need funding to continue developing the language next year.

In his own words:

As should be obvious, Clojure is a labor of love on my part. Started
as a self-funded sabbatical project, Clojure has come to occupy me far
more than full-time. However, Clojure does not have institutional or
corporate sponsorship, and was not, and is not, the by-product of
another profitable endeavor. I have borne the costs of developing
Clojure myself, but 2009 is the last year I, or my family, can bear
that.

The above is an exerpt from a long post by Rich on the Clojure Google Group.

On a personal note, I am surprised that Rich explicitly states that people who are just “evaluating Clojure” should not feel obliged to pay anything.

This is a really nice attitude, but also very ineffective. By far most of us use Clojure only for playing around and maybe solving the occasional Project Euler problem. Does that amount to more than just evaluating the language? Most would probably say no, especially when the suggested donation for “real users” is $100/year.

Instead, if all us casual users donate just a little bit, for example $10, it will amount to quite a substantial amount of money. My guess would be a lot more than the $100/year paid by the relatively few commercial users.

So if you want Clojure to stay alive, chip in! $10 is not a lot of money.

Categories: Uncategorized

Quick tip: Replacing cmd.exe

December 14, 2009 chopmo Leave a comment

It has been a long while now since I ran Windows on hardware. However, I need to use it for a lot of things at work, so I have several Windows VMs running on ESX hosts and I just RDP to them.

Most of the time, this works really well. I have always been pretty impressed with the RDP protocol (not so much after trying NX, but it’s still decent). However, one huge annoyance is the Command Prompt, cmd.exe. Whenever large amounts of text scroll by (verbose logging, for example), my RDP session simply hangs. There’s nothing I can do to break the output. Ctrl-C can take ages to get though and I usually end up killing the RDP client.

So I recently decided to find an alternative, and that turned out to be pretty easy: Console.

It is by no means perfect, in fact it is pretty rough around the edges. But scrolling works much better than with cmd.exe, and there are a few other improvements as well. For example, it is possible to resize the window without entering numbers in a dialog box :-)

Copying and pasting works a bit differently, so that took a few days of getting used to. But the good thing is that I no longer pause a running process accidentally by selecting a character of text (grr…).

Categories: microsoft, tips

fork()

November 25, 2009 chopmo Leave a comment

This blog may look like it is dying, but that is in fact not the case.

What you’re looking at is the technical, english-language content from my personal weblog, on which these entries will soon be removed, of course. I recently realized that mixing personal and techical stuff on one blog is probably not a good idea. Neither is mixing languages (danish and english).

Thankfully, the solution is pretty easy with WordPress’ export/import feature: Split the blog into two. This is the technical half of that split.

So on this blog I will write about all kinds of technical stuff, mostly programming- or Emacs-related. I’ll probably spend some words on tips and tricks for the efficient use of Emacs. Emacs has been one of the great revalations for me, and it pains me to think about how many years I made do with all kinds of inferior text editors. However, I’ll try not to write annoying things like that on the blog. :-)

I won’t limit the scope to Emacs, though. Basically, I’ll write about anything where I feel that I may be able to help others. Also, I’ll often use the blog as a notepad for configuration snippets, gotchas etc. that I tend to forget. Chances are that others forget them as well. The post about changing text encoding in Emacs is a perfect example of this.

This post is really just a marker, because there’s already some content on the blog. I just wanted to explain the change of address, the huge temporal gaps (clearly I have some catching up to do) as well as stating my intentions for the future of the blog. I’m really looking forward to putting a lot more stuff up here. On my personal wiki, I have a long list of topics to write about, so it’s time to get cracking.

Comments are always very welcome!

Categories: other