Code ricing

I was chatting with a co-worker the other day about unnecessary code optimizations that make your code look like it’s going to run faster. Here’s an example:

int x = x * 2;  // x *= 2

And here’s the riced up version:

int x = x << 1;  // x <<= 1

If you think the second version will run faster you too may be a code ricer.

Got more examples? Leave a comment.

Fun with VIM conceal

Not that I think that it’s a good idea to actually edit code this way but I figured I’d give it a try and see how easy it would be to use VIM conceal to cut down a bit on Java’s verbose syntax.

https://github.com/has207/vim-java-conceal

Doesn’t actually look half bad..画像

 

 

Python builtin I wish existed

def indexes(List):
    for index in xrange(len(List)):
        yield index

python REPL improved

I’ve gone a surprisingly long time not knowing this, but python (the interactive shell) has an rc file it can read on startup. This means you can preload commonly used modules such as sys and os as well as spice things up a bit by doing an import readline which will automatically add the sorely-missing readline capabilities to the python interactive shell.

It’s pretty easy to set up:

  • add export PYTHONSTARTUP=~/.python to your ~/.bashrc
  • add import sys, os, readline to ~/.python
  • PROFIT!!

For bonus points, you can also add set editing-mode vi to your ~/.inputrc to enable vi key bindings. Note that on OSX this will also require installing the GNU readline compatible version of the readline module (available here).