Quickly jumping to symbols

This is brilliant.

For a while, I have been using ido to quickly jump between buffers and files by just typing any part of the file/buffer name I want. In fact, typing any sequence of letters narrows the interactive search to candidates with names that contain those letters in that order:


fb -> Foobar, FrancisGailBrown

But for finding method definitions in a big source file, I have always just used isearch. It turns out that there is a better way.

By combining imenu with ido, I can quickly find methods as well:



All it takes is this method in my init.el:



(defun ido-goto-symbol ()
"Will update the imenu index and then use ido to select a
symbol to navigate to"
(interactive)
(imenu--make-index-alist)
(let ((name-and-pos '())
(symbol-names '()))
(flet ((addsymbols (symbol-list)
(when (listp symbol-list)
(dolist (symbol symbol-list)
(let ((name nil) (position nil))
(cond
((and (listp symbol) (imenu--subalist-p symbol))
(addsymbols symbol))

((listp symbol)
(setq name (car symbol))
(setq position (cdr symbol)))

((stringp symbol)
(setq name symbol)
(setq position (get-text-property 1 'org-imenu-marker symbol))))

(unless (or (null position) (null name))
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))
(addsymbols imenu--index-alist))
(let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
(position (cdr (assoc selected-symbol name-and-pos))))
(goto-char position))))



I have bound it to C-t, because I realized that I don't use transpose-chars (or whichever transpose method was there..I don't use any of those, really).

I found this trick on the imenu wiki page.

My first AVR-based project

I have always been fascinated by electronics. As a child, I tore apart several rather expensive appliances to see how they worked. Much to my parents' grief, of course.

However, since I got into software development, I haven't given it much thought. Moving several levels of abstraction away from the hardware, your focus shifts quickly to completely different areas.

But recently, this project caught my attention for some reason. So even though I ended up implementing it completely differently, I couldn't stop thinking about the potential of being able to write code for tiny, cheap embedded processors.

I'm not sure why I have never thought of this before. I have considered writing software for PDAs, but they're pretty expensive, and the platform choices are poor. Windows Mobile is a joke, and Palm OS is not very appealing either.

So I decided to take a big step closer to the iron. Knowing nothing about the state of this field, I simply googled for a few starting points. I ended up buying the very cool USBtinyISP programmer kit (and absolutely enjoyed the process of assembling it).



Also, I got the ATtiny26 development board from Active Robots.



This last item, I have later discovered, is probably somewhat outdated. What you want for electronics prototyping these days is the Arduino.



Anyway, the great thing about the ATtiny is that it's cheap (the processor itself is about $4) and it doesn't consume a lot of power.

OK, so what did I do for my debut project? Nothing very interesting, I'm afraid. I wrota a program that simply morses a sentence using the LED built into the development board. I used the GNU toolchain (avr-libc et al) for writing the program and avrdude for flashing it onto the processor. Works great on both Linux and OSX.

In action, this is what it looks like:



And yes, I realize that the quality of the video is too crappy to distinguish the pulses.

Here is the complete source code for this project (sorry about the formatting):




#include <avr/io.h>
#include <string.h>
#include <stdlib.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

/*
* The morse alphabet.
*
* 0: Short pulse
* 1: Long pulse
*/
const char ltr_a[] PROGMEM = "01";
const char ltr_b[] PROGMEM = "1000";
const char ltr_c[] PROGMEM = "1010";
const char ltr_d[] PROGMEM = "100";
const char ltr_e[] PROGMEM = "0";
const char ltr_f[] PROGMEM = "0010";
const char ltr_g[] PROGMEM = "110";
const char ltr_h[] PROGMEM = "0000";
const char ltr_i[] PROGMEM = "00";
const char ltr_j[] PROGMEM = "0111";
const char ltr_k[] PROGMEM = "101";
const char ltr_l[] PROGMEM = "0100";
const char ltr_m[] PROGMEM = "11";
const char ltr_n[] PROGMEM = "10";
const char ltr_o[] PROGMEM = "111";
const char ltr_p[] PROGMEM = "0110";
const char ltr_q[] PROGMEM = "1101";
const char ltr_r[] PROGMEM = "010";
const char ltr_s[] PROGMEM = "000";
const char ltr_t[] PROGMEM = "1";
const char ltr_u[] PROGMEM = "001";
const char ltr_v[] PROGMEM = "0001";
const char ltr_w[] PROGMEM = "011";
const char ltr_x[] PROGMEM = "1001";
const char ltr_y[] PROGMEM = "1011";
const char ltr_z[] PROGMEM = "1100";

PGM_P alphabet[26] PROGMEM = {
ltr_a,ltr_b,ltr_c,ltr_d,ltr_e,ltr_f,ltr_g,ltr_h,ltr_i,ltr_j,ltr_k,
ltr_l,ltr_m,ltr_n,ltr_o,ltr_p,ltr_q,ltr_r,ltr_s,ltr_t,ltr_u,ltr_v,
ltr_w,ltr_x,ltr_y,ltr_z
};

void sleep_msecs(int msecs)
{
/*
* The argument to _delay_ms must be constant (ie. known at compile-time).
*/
int i;
for(i = 0; i < msecs; i++){
_delay_ms(1);
}
}

void set_led_state(int state)
{
PORTB = (state == 1) ? _BV(6) : _BV(0);
}

/*
* Emit single pulse
*
* Length choices are:
* 0: short
* 1: long
*/
void emit_pulse(int length)
{
set_led_state(1);
sleep_msecs((length == 1) ? 210 : 60);
set_led_state(0);
sleep_msecs(100);
}

/*
* Emit a sequence of pulses, eg. "1000" for the letter "b".
*/
void emit_pulses(char *pulse_str)
{
int pulse_str_len = strlen(pulse_str);
int i2;
for (i2 = 0; i2 < pulse_str_len; i2++) {
emit_pulse(pulse_str[i2] == '1');
}
}

void emit_letter(char l)
{
if (l == ' ') {
sleep_msecs(700);
return;
}

char *buf = malloc(8 * sizeof(char));

int index = l - 'a';
PGM_P p;
memcpy_P(&p, &alphabet[index], sizeof(PGM_P));
strcpy_P(buf, p);
emit_pulses(buf);
free(buf);
}

void morse_msg(const char *msg)
{
int len = strlen(msg);
int i;
for (i = 0; i < len; ++i) {
emit_letter(msg[i]);
sleep_msecs(350);
}
}

void do_morse(const char *msg)
{
for(;;){
morse_msg(msg);
sleep_msecs(2500);
}
}

int main(void)
{
/* Init IO */
DDRB = _BV(6); /* make the LED pin an output */

do_morse("er der mon mere kaffe");

/* Not reached */
return 0;
}



In case you're wondering, the morsed message, "er der mon mere kaffe", is danish for "I wonder if there's any more coffee". Indeed, the first thing that sprang to mind when I finally got the software working.

Nostalgia

Thomas Winding, you will be missed


Not so long ago, Danish author Thomas Winding died, 71 years old.

Thomas was famous for writing a lot of books for children, but even more for reading his stories aloud on the radio. He had a deep, calm voice that was known and loved by all Danish children when I was a child.

The death of Thomas Winding seems to have led to a feeling of "mass nostalgia" in my generation. A Facebook group has been created, and the media has written a lot about how everyone will sorely miss the "soundtrack of their childhood".

This made me think. I'm 33 years old now, and I don't think I have heard the voice of Thomas Winding for almost a decade.

Still, his death is kind of a painful event for me. Of course, I will not miss him as such, but he was a very happy memory of my childhood. So losing him is yet another reminder that I am no longer, and will never again be, a happy and carefree child.

It seems bizarre to feel so sad about the death of a person I didn't even know, and haven't thought about for years. But luckily, I'm not alone, and there is a word for this feeling: Nostalgia.

Feeling nostalgic


According to Wikipedia, the word Nostalgia is of greek origin and refers to "the pain a sick person feels because he wishes to return to his native land".

I think this is a beautiful way to describe a feeling that everybody knows, but which is hard to define. The description is absolute nonsense, I know, but so is the feeling itself.

In fact, I find it highly irrational, especially from an evolutionary standpoint. I mean, what is the purpose of an individual wanting to "return to his home land"? On the surface, it seems regressive and foolish.

However, it is hard to believe that any counterproductive sentiment would have been allowed to survive for countless generations to still be present in the human beings of today. There must be some rational purpose to this feeling, but it eludes me.

If anyone out there knows, please drop me a line.

My father


So, having questioned the rationality of feeling nostalic, I want to convince everyone that I am not a robot.

Three years ago, my siblings and I lost our father. He died of cancer, only 55 years old. Needless to say, this was a terrible time for our family. After three years, it is still hard.

But life moves on, and this is how it should be.

However, life paused for a brief moment when I found this picture on my harddisk.



My father was a man of habit. Every day, he would take his dog for a long walk in the forest. Same route every day. Same sticks that had to be thrown into the water at the same spots on the route along the lake, year after year. He once calculated that he had walked more than a thousand miles on this trail, which is only a few miles long.

Our dog, Luna, was a very loving animal, and she absolutely adored my father. She was half Collie, so the herding instinct was very visible in her behavior. I think this is part of the reason that we loved her so much. She always wanted to keep the family together.

The above picture was taken by me. Luna is clearly worried that I have become separated from the leader of the flock, so she looks ahead to assess the risk.

For me, looking at this 5 year old picture simply defines nostalgia. It forces me to forget the present and focus on the past for a while. Never again will I join my father and Luna for that walk, and my home town seems so far away now.

Cat faucet, crude edition

If you're a cat owner, you know that cats love to drink from the faucet!

Being a cat owner myself, I was pretty excited to learn about this Cat Faucet project by Sixerdoodle Electronics. I have often thought about building something similar myself, but I had never gotten around to it.

However, even though the design of the Sixerdoodle Cat Faucet is very elegant, I find it more complicated than necessary (mainly because they wanted to keep it low voltage, it turns out).

So I started wondering how to build the simplest possible cat faucet. This is what I came up with:


(Open above image, with notes, in a new window)


(Diva enjoying the running water)

The complete list of components:


  • a solenoid from an old dishwasher

  • a movement sensor (the kind usually used to light up a driveway)

  • a few bits of plumbing

  • a piece of gaffer tape to limit the area monitored by the sensor




(Solenoid from an old dishwasher)


(The movement sensor, pointed straight down)

That's it. The flow of water is controlled simply by adjusting the position of the red valve that lets water into the system. The sensitivity and timeout of the sensor can be controlled with small knobs on the underside.

My wife put a little bowl underneath the faucet to allow the cats to drink from a surface of water as well as from the running water. Excess water simply spills down the drain below.

Contrary to the Sixerdoodle design, my cat faucet is not low voltage (it runs on 230V, our mains voltage in Denmark). However, because both components were designed to be safe and withstand pretty rough conditions, this does not worry me at all.


(The finished setup, tucked away under a small shelving unit)


(Obviously, it takes a little practice!)

My CEFSSPPSSS was in the mail this morning



WTF? Headlines that long are usually reserved for doctoral dissertations...! :-)

Why I don't like Microsoft

As anyone who follows the virtualization business know by now, this has been a tough week for us at VMware.

CEO Diane Greene stepped back, effective immediately, and was replaced by ex-Microsoft employee Paul Maritz.

This event led to a brief discussion with one of my collegues, who is also a former MS employee, about whether or not Microsoft is an evil company.


(Photo: batmoo)


As he pointed out, MS has invested huge sums in research, and has hired some of the brightest people out there. These people come up with excellent ideas and they receive the funding to put those ideas into practice.

So what is the problem? One word: Windows.


(Photo: aralbalkan)

I am not at all a religious man, and I certaintly don't want to be religious about this either. But the fact of the matter is, I find Windows completely ridiculous as a platform for anything but gaming. This is my honest opinion.

I was frustrated to read an article about Silverlight 2 in the August issue of DDJ. This is actually pretty cool stuff, but it is not for me. I know it runs on my Mac, but you need Windows to do any serious development.


John Lam - what a waste of talent (Photo: timheuer)

I don't have the patience for running Windows, because it sucks terribly. This is hardly a controversial opinion. I tolerate it at work, because the job is otherwise great, but I wouldn't dream of running it on my home computers. Over the last few years, I have come to realize that OSX is the only OS that doesn't suck one way or the other. For a few years, I was running Ubuntu on my laptop, but I was never very happy with it. I was wasting far too much time fixing small problems and trying to get basic stuff like suspend/resume working.

On my MacBook Pro, everything works. I have been using it daily for a few years now, and the number of times is has crashed is still below ten. You would never get that kind of milage from a Windows box, probably not even if you left it idle.

So while I really like .NET, C#, LINQ and all that, I can't use it, because I can't stomach the OS that comes with it. I really don't care very much about whether Microsoft is good or evil, but I'm sad to see so much talent go to waste. This is why I don't like Microsoft.

In the Zoo

Recently, my friends and I spent an entire day at the Zoo.

It was a beautiful day. The sun was shining, and everyone else seemed to have hit the beach, so the place was almost deserted.

We were hung over, most of the animals were drowsy from the heat and we thoroughly enjoyed ourselves!

I mean, just take a look at this guy. If such a creature can't bring out the giggles in you, what can?

Also, many of the animals are just breathtaking. Check out this photo. These are by no means lucky shots...Siberian Tigers just are that beautiful.

Actually, the resemblance to our cat Diva is clear, although Diva may be slightly less intimidating...

Looking back, I am surprised to say that the animal that fascinated me the most was the brown bear. There were two of them, and they were very restless.

Watching them from a distance of only 10 feet, their restlessness was contagious. They breathed heavily and kept following the same pattern back and forth in their cage. Maybe it was just before their scheduled feeding, or maybe something was bothering them. We never found out.

Everytime they paused in front of me and looked straight into my eyes, I couldn't help looking down at their claws and imagining the kind of damage they could do to human flesh...those thoughts left quite an impression on me.

The bear is truly an awesome creature, and as I discussed with my younger brother, there is not much you can do to avoid it in the wild. It will certainly run, swim and climb much better than you. This is clearly an instance of the human being superior only with a rifle in his hand.

Spending an entire day in the Zoo was therapeutic to me. It gave me time to process the impressions from the concert we attended at a festival the day before, and it inspired me to ponder life, the universe and everything. I need to do that sometimes.