New Vim Colorscheme

Posted Sat Nov 26 @ 01:10:31 PM PDT 2011

I've been using the default vim colorscheme every since I started using vim. It's not the best looking colorscheme, but it gets the job done, except for one thing. When you use the ctrl n command in insert mode, the little autocomplete popup appears. The problem is that with the default color scheme, it is hard to know which item is selected. See what I mean:

Ugly autocomplete menu

Since I use autocomplete a lot more now, I figured it was time for a change. People on stackoverflow recommended the Wombat scheme. I downloaded it, dropped it in my .vim/colors directory and tried to use it. Of course it didn't work. Turns out I needed the 256 color version of Wombat. Now it worked*. You can see some screenshots here.

I like it, but I made a few changes. First, I like a totally black background, not grey. And second, I like my error bar white text on red (so it stands out more).

I opened up the colorscheme file to make the changes, and was a little confused by the color codes. They go from 0-255, but there is no real pattern to them (as far as I could tell). 0 is black (makes sense), but white is 15. Go figure.

It was actually hard to find, but eventually I landed on a list of the 256 colors available in a terminal (and vim), with their byte codes, and hex codes.

The only changes had to make were:

hi Normal ctermfg=25 hi ErrorMsg ctermfg=15

Now I get a black background, and a really highlighted error bar:

My vim colorscheme

* if the 256 version still doesn't work, make sure you add:

let &t_Co=256

to your .vimrc file

Shattered Dreams

Posted Wed Nov 16 @ 07:14:02 PM PDT 2011

NASA is on the hunt for an astronaut.

I would have applied, but apparently NASA doesn't make jumpsuits for people over 75 inches tall.

So much for my dream of being the first man on Mars...

SQL is Designed to Ruin Your Day

Posted Sun Nov 13 @ 04:31:04 PM PDT 2011

I had my first run in with the notorious UPDATE-query-without-a-WHERE-clause catastrophe a few weeks ago. I'm surprised that in the ~5 years I've been writing SQL queries, it has never happened to me.

If you don't know what I'm talking about, here's the scoop: When you write an UPDATE query and you forget to specify the WHERE clause, every row in the table is updated. For example, this query will change Bob's email to 'bob@example.com':

UPDATE User SET Email = 'bob@example.com' WHERE Name = 'Bob'

However, if you get hasty, and forget to put in the WHERE clause:

UPDATE User SET Email = 'bob@example.com'

everyone's email gets set to 'bob@example.com'. That's definitely not something you want to do!

In my case, I wasn't querying the production database directly, so all I had to do was DROP the table and import it from a SQL dump. No big deal.

But it got me thinking. It seems like the better way to handle an UPDATE or DELETE query without a WHERE clause is to throw an error. How many cases do you really want to UPDATE or DELETE every row in a table? And in those rare cases, is it really that much more work to specify a WHERE clause like 'WHERE 1=1'?

Easily Transfer Public Key to Another Machine

Posted Wed Nov 09 @ 08:37:00 PM PDT 2011

If you want to enable key based authentication to a (*nix) computer, instead of:

  • copying your public key
  • logging into the other machine
  • pasting it into the "authorized_hosts" file

You can just use the ssh-copy-id command.

For example, if I want to move my public key over to machine1.example.com, I can just do this:

ssh-copy-id username@machine1.example.com

You will be prompted to login and your public key will be transferred to the host. After that, you can just login with your key.

Jump Back to Previous Position After Visual Selection

Posted Sat Oct 29 @ 06:36:20 PM PDT 2011

When you use visual mode in Vim to apply some transformation to the selection (for example, indenting it), Vim jumps you back to the top of the visual selection (after performing the transformation).

In most cases, that's the opposite of what I want. Usually, I want my cursor to stay exactly where it was before applying the transformation.

To do that, use '> (to jump back to the line) or `> (to jump back to the line and column).

I was hoping '' or `` would do the trick, but they don't.

Use Dynamic DNS Without a Long Hostname

Posted Sun Oct 23 @ 05:46:44 PM PDT 2011

My DIR-655 router comes with a cool feature that allows you to sync up your current IP address with a dynamic DNS provider like dyndns.com. Because my ISP (Comcast) can change my IP at any time, I can always use my dynamic DNS address to reach my computer on the internet.

The first thing you need to do is create an account at dyndns.org, and get a hostname setup, and pointing to your IP. Then you plug that information into your router like so (on my router, it is under Tools > Dynamic DNS):

The only problem is that you have to use a long hostname since all the short ones are taken.

To fix that, I created a CNAME record on one of my domains with the hostname me.example.com aliased to myhostname.dyndns.org. So if you have a short domain name, you can have a short dynamic DNS hostname too.

Accessibility > Security

Posted Fri Oct 14 @ 06:24:02 PM PDT 2011

But I'll argue that Accessibility is actually more important than Security because dialing Accessibility to zero means you have no product at all, whereas dialing Security to zero can still get you a reasonably successful product such as the Playstation Network.

Steve Yegge (source)

Man Page for ASCII

Posted Sun Oct 09 @ 03:18:53 PM PDT 2011

Every time I need to lookup the ASCII value for something, I end up launching my web browser and searching for an ASCII table.

But there's a man page for that.

man ascii

Who knew?

Fix Compiler Warnings in OpenGL on Linux

Posted Sat Oct 01 @ 07:06:27 PM PDT 2011

Here are all the nice warnings GCC gives me when I try to compile an OpenGL program:

warning: implicit declaration of function "glGenBuffers" warning: implicit declaration of function "glBindBuffer" warning: implicit declaration of function "glBufferData" warning: implicit declaration of function "glCreateShader" warning: implicit declaration of function "glShaderSource" warning: implicit declaration of function "glCompileShader" warning: implicit declaration of function "glGetShaderiv" warning: implicit declaration of function "glGetShaderInfoLog" warning: implicit declaration of function "glCreateProgram" warning: implicit declaration of function "glAttachShader" warning: implicit declaration of function "glLinkProgram" warning: implicit declaration of function "glGetProgramiv" warning: implicit declaration of function "glGetProgramInfoLog" warning: implicit declaration of function "glGetUniformLocation" warning: implicit declaration of function "glUseProgram" warning: implicit declaration of function "glUniform2f" warning: implicit declaration of function "glUniform3f"

To fix it, add:

#define GL_GLEXT_PROTOTYPES

before your includes:

#define GL_GLEXT_PROTOTYPES #include <GL/glut.h> #include <GL/gl.h> #include <GL/glu.h>

That should do it.

Can't Use Index Operator on Strings in JavaScript

Posted Fri Aug 05 @ 03:48:20 PM PDT 2011

If you're using the index operator [] to get a char out of a string in JavaScript, your script will fail in Internet Explorer.

var str = "Hello World"; var e = str[1]; alert(e); // "undefined" in IE <= 7

You need to use the charAt method instead:

var str = "Hello World"; var e = str.charAt(1) alert(e); // "e"
Newer Posts Older Posts