Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

2009-08-28

Podcasts I listen to

For the last couple of years I've been listening a lot of podcasts, and some of them I still listen to as soon as they have a new episode. Once you get up to a few hours of newly produced podcasts per week you have to find every possible time you can to listen to them. The time it takes to walk, bike or commute somewhere is great. I usually put my headphones on as soon as I go out alone, or if working on my own on something mundane like laundry or dishes. Listening while working is pointless since I either stop writing code, or stop listening. The podcasts listed below all demand full focus from the listener if you are to learn anything from them.

Digital Planet
Digital Planet from BBC is an easy going technology podcast that will discuss the latest general news in the IT area. Usually quite short and not very technical, but a good news update anyway.

In Our Time With Melvyn Bragg
This is another high quality BBC podcast, but it is quite "high brow" compared to Digital Planet and very broad in it's content. The episodes usually consist of a small group of British professors, together with the fast speaking host Melwyn Bragg, talking for an hour about anything from quantum mechanics to philosophy, or some major historic event. Very educating, but not a podcast to listen to when you are tired.

Linux Outlaws
Linux Outlaws is produced by Dan and Fab and is a humorous show about all kinds of Linux related news. It's lighthearted and I usually laugh out loud several times per episode. It is a fun way to keep updated on new releases (System Rescue CD?) and other Linux community information. The typical discussions usually include something like this:
Fab - "It's crap! I'll cut their balls off!"
Dan - "Yeah, let's keep an eye on that! Hmm, ok, lets move on then shall we."

LinuxLink Radio
LinuxLink Radio is a podcast about embedded Linux development produced by TimeSys. It is a highly technical show and usually each episode goes through a solution to a specific problem that you might run into when working with embedded Linux devices. Very informative and a news update on the embedded world.

SALT - Seminars About Long Term Thinking
The Long Now Foundation invite some great speakers and they always have very interesting speakers. The podcasts are usually over an hour and usually start with Stuart Brand introducing the speaker and topic of the evening. Unfortunately some presentations are a bit too image focused and because of that hard to follow as a podcast. At the end of each presentation Kevin Kelly asks the questions collected from the audience during the presentation. The shows are not that many, and they are all worth listening to. They will make you think about time with a different perspective.

Science Talk - The Podcast of Scientific American

This podcast is closely connected to the Scientific American magazine and usually discuss the articles comming in the next paper issue with the author of each article. My favorite part every week is the bogus news quiz where they list four strange news stories and you have to guess which one is false.

Software Engineering Radio - The podcast for professional software developers
If deep and highly technical podcasts about software development suits your taste, this is your podcast. Sometimes it might feel a bit too abstract or a very narrow topic, but you will defenitely learn a lot. There's quite a big archive over at the SE-radio site.

The Java Posse
Java Posse is one of the longest running podcasts I listen to and currently they're at episode number 276! Tor Norbye, Carl Quinn, Dick Wall and Joe Nuxol do the talking and the episodes vary from recordings of discussion panels and interviews, to theme episodes and pure news updates. The tone is cheerful and full of jokes and not always on topic, but that's a good thing.

This American Life
If you like long detailed stories, this is the podcast for you. The show consists of one or more interviews per episode about a certain type of life changing event. A high quality production.

Three Moves Ahead
This is a strategy gaming podcast from Flash of steel where Troy Goodfellow, Tom Chick, Bruce Geryk and Julian Murdoch discuss boardgames and computer strategy games. There's a lot of "in-jokes" and references to old games and the tone is very casual. Even if I'm not much of a gamer any more, it's still interesting to stay up to date on what is happening in that area.

WNYC's Radio Lab
This extremely well produced podcast from WNYC is hosted by Jad Abumrad and Robert Krulwich. They talk about a wide variety of scientific subjects and use a lot of sound effects and music. It is a podcast suitable to everyone since the language used is very clear and the topics are all interesting.

Word of Mouth
This is the podcast version of the long running Word of Mouth radio show from NHPR. It feels more like a normal radio show than a typical podcast and have a good mix of quick news and deep interviews.

I gladly recommend all the podcasts mentioned above and they are worth every minute it takes to listen to them.

2008-12-22

Beyond basic Vim usage

I have used Vim for about 8 years now, but for quite a while I didn't use the "vee-eye" key mapping the way it should be used. All I did was press i to go to Insert mode, type the text and then Esc:wq to save and quit. That's completely the wrong way to use this wonderful text editor. If you are in that situation I hope this Vim introduction can get you past it. After an overview of some settings for the configuration file I will list the commands everyone should know (and some you probably don't really need to know).

Basic configuration

To be able to use Vim efficiently you have to have some basic configuration set up. In Linux or Unix you should edit
~/.vimrc (Windows specifics last in the post) to include at least the following lines:
set nocompatible      " This is vim, not vi (Put this line first!)
colorscheme koehler " Optional, but I like a black background
set smartcase " Only do case sensitive match on Upper Case
syntax on " Syntax highlight on
set showcmd " Show the command you have typed in
set showmatch " Show matching brackets or parentheses
set wildmenu " Show possible command tab completions
set ruler " Show useful information on the command line
set incsearch " Incremental searching
set hlsearch " Highlight search results. Clear with :nohl
Besides these settings I have some more things, mostly related to tabs and indentation:
set expandtab         " Expand tabs to spaces
set tabstop=4 " 4 spaces is one tab
set shiftwidth=4 " Should be the same as tabstop
set softtabstop=4 " Makes the spaces feel like real tabs
set smarttab " Backspace over expandtab
set autoindent " Use current indentation on next line
set nocindent " Don't use cindent
set nosmartindent " Don't break filetype indent scripts
filetype on " Try to figure out the right filetype
filetype plugin on " Filetype specific plugins
filetype indent on " Filetype specific intenting
There's a lot more you can configure in the rc-file and there are plenty of good examples on the net, just search.

File handling

The file handling commands you need to know are:
:w         " Write changes to disk
:w newfile " Write changes to newfile
:w! " Force write
:q " Quit
:q! " Really quit!
:wq " Save and quit
:wqa! " Really save all files and quit.
Also, opening a file with vim + filename will position you at the end of the file.

Movements


A great way to getting started with vim is the built in
vimtutor, a text file tutorial you can follow to learn all basic commands in Vim. But to get you up to speed I'll list the basic moves here. Just one comment first. Even though the arrow keys probably work, don't use them! They are slow and you have to move your fingers from the keyboard.
h      " Left - Moves the cursor one step
j " Down
k " Up
l " Right

gg " Go to the start of the file
G " Go to the end, just like in less

w " Move one word forward
W " Move to next blank delimited word
b " Move one word backwards
B " Move to previous blank delimited word

0 " Go to the beginning of the line
$ " Go to the end of the line

H " Move to the top of the visible screen (Head)
M " Move the cursor to the middle of the screen
L " Move to the end of the screen (Last)

fc " Forward onto the character c on this line
Fc " Backwards onto the character c on this line
tc " Forward to the character c on this line but not on it
Tc " Back to the character c but not on it
nfc " Forward onto the nth c character on this line
All these moves can be used together with the commands I will describe below and will be referred to with a m. Most moves and actions can be performed with a number in front. 5w means move five words forward. I'll note that number n and a single char with c.

Normal mode and Insert mode


Vim has six basic modes, the most important two being Normal och Insert. Normal mode is the default where you do all the commands and movements and Insert is when you actually type in text
. There are many commands related to changing between these two modes:
i      " Go to insert mode before the cursor position
I " Go to insert mode at the beginning of the line
a " Go to insert mode after the cursor position
A " Go to insert mode at the end of the line
o " Insert a new line below and go to insert mode
O " Insert a new line above and go to insert mode
c
m " Delete from the cursor to m and go to insert mode
cc " Delete the whole row and go to insert mode (Change)
C " Change from current position to the end of the line
rc " Replace the character under the cursor with c
Esc " Go back to Normal mode
Ctrl-c " Go back to Normal mode
Ctrl-o " Do one command in normal mode, i.e Ctrl-o$
Search and Replace

Usually the fastest way to navigate the cursor is to search for the text you want to go to:

/regex " Search for a word or a regular expression
* " Search forward for the word under the cursor
# " Search backwards for the word under the cursor
n " Next search match
N " Previous search match
'' " Two back ticks; Move cursor to where you were before the search

:n " Go to line number n
:%s/oldtext/newtext/g " Replace oldtext with newtext in the whole file
:%s/oldtext/newtext/gc " The same, but confirm each replace
When doing a replace the %s means search every line in the file and the /g means replace all occurrences on the line. Omitting the g means you will only change the first occurrence on the line and. Without the % you only search the current line.

Cut, Copy and Paste


As expected there are many ways to copy and paste text in Vim. The "must know" ones are:
x   " Delete the character under the cursor
dd " Delete the current line and put it in the clip board
dw " Delete the word under the cursor
ndj " Delete n rows down and put them in the clip board
D " Delete from here to the end of the line
yy " Yank a line, meaning to copy it
yw " Yank a word
ym " Yank from the cursor to m
p " Paste below or after the cursor
P " Paste before or above the cursor
np " Paste
n copies of what you have in the clip board
Undo and Redo

Another great feature with vim is that you can do multiple undo or redo. The commands are:
u            " Undo once
uu " Undo two times
Ctr-r " Redo

:earlier n " Go to older text state n times
:earlier ns " Go to about n seconds before
:earlier nm " Go to about n minutes before
:earlier nh " Go to about n hours before

:later n " Go to newer text state n times
:later ns " Go to about n seconds later
:later nm " Go to about n minutes later
:later nh " Go to about n hours later
If all these normal mode commands is too much to remember at once there's a great printable cheat sheet at viemu.com that can help you practice them. There's a good quick reference available here.

Fun tricks

A fun thing about vim is that there's always more to learn and a quicker way to do the kind of edit you are trying to do. Some of my favorite tricks are:
.            " The simple dot replays your last command. Very powerful!

r[enter] " Insert linebreak without going into insert mode
J " Append the line below to the current line

qq[do stuff]q " Record the stuff you do in command register q
@q " Replay the action saved in q
@@ " Replay last used action

ci> " Delete between previous <> and go to insert mode
da> " Delete from previous <>, including the tags

^r=(3+4)*5 " Use when in insert mode. Will insert 35 at the cursor
Ctrl-A " Increase the number closest to the cursor with one
Ctrl-X " Decrease the number closest to the cursor with one

~ " Toggle case of the character under the cursor
gu
m " Lowercase from the cursor to m
gUi> " Uppercase between the previous <>

:TOhtml " Generate html that looks exactly like what you see in vim

g?
m " Do rot13 on the movement

z[Ret] " Scroll the window so that the cursor is at the top
zz
" Scroll the window so that the cursor is in the middle
z- " Scroll the window so that the cursor is at the bottom

gf " Go to the file under the cursor
K " Look up man page for the word under the cursor

!ls " Run ls in the current working directory
!!date " Replace the current line with the date. Use date /T on Windows
:set number " Show line numbers

:reg " Show what you have in the registers (The clip boards)

Ctrl-g " Show filename and position in file

:Ctrl-r Ctrl-w " Copy the word under the cursor to the : line
Split windows

In vim you can have more than one file visible in the editor at the same time, either by opening a file in split view or by using
vimdiff.
:split       " Split the windows horizontally
:sp myfile " Open myfile in a split view
:vsplit " Split the window vertically (:vs works as well)
Ctrl-ww " Move the cursor to the other window
Ctrl-w= " Resize the windows as equally as possible
Ctrl-wc " Close the current window
Custom mappings

Vim has a lot of key mappings available and it is easy to add your own to your vimrc-file. An example to make pasting text into Vim easier when you have autoindent/smartindent on:
map <C-s> :w<CR>
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>
set pastetoggle=<F2>
The first line sets a mapping so that pressing in normal mode will invert the 'paste' option, and will then show the value of that option. The second line does the same in insert mode (but insert mode mappings only apply when 'paste' is off). The third line allows you to press when in insert mode, to turn 'paste' off. This tip and lots of others can be found at the great Vim Wikia.

Vim on Windows

On windows the configuration file is called _vimrc and can be found in your Vim install directory. By default it has some settings already, but you can still add the basic settings mentioned in the beginning of this post. In addition to that you should set nobackup and for fun, remap Ctrl-A and Ctrl-X key bindings to be Ctrl-+ and Ctrl-- on the numpad so that they work. They are used to increase and decrease numbers:
set nobackup
noremap <C-kPlus> <C-A>
noremap <C-kMinus> <C-X>
Thanks for reading this far. These settings have been found during a long time and from all kinds of sources and there are almost infinitely many to be found.

After this post I understand why the Daily Vim blog has a black background everywhere. It is a pain to get black block quotes in blogger to show your nice vim highlights. (Hint; edit the html to use <blockquote style="font-family: courier new; background-color: black; color: white;"><pre></pre></blockquote> around the html generated by TOhtml. Also, remember to remove the superflous tags, :s%/
<br>//g.)

(The post has been updated after graywh's comment.)

2008-05-24

Roguelike revival

I played my first roguelike JAMoria on a Mac Classic II somewhere around 1993. It's a classic black and white ASCII game where you run around with a @ using the numpad on the keyboard. In JAMoria you start in a small city, just like the classic Moria. But instead of just having one dungeon, it has multiple dungeons to descend into, both in the town and in the wilderness that surrounds it.

Like all roguelikes, if you died you had to start over again and create a completely new character to play with. Already being familiar with regular table top role playing games, rolling new stats and trying out new race and class combinations was a major part of the fun.

In early 1996, using a blazingly fast 28.8 baud modem I managed to download ADOM 8.1 and install it on my first non Macintosh pc, a Pentium 75Mhz. At first I found the game really hard, and all new characters died after just a few minutes, but I kept trying. After some newsgroup searching I found help in rec.games.roguelike.misc, and later rec.games.roguelike.adom. And I've been playing ADOM ever since. It's a very very difficult game to "win", but just trying to is fun enough. Not much has happened to ADOM since version 1.1.1 in 2002, and by that time the development of all the other rougelikes I knew had gone into maintenance mode or ceased completely.

Adom: Terinyo

One reason might be that graphical games were making it impossible to compete. One of my favourites, Dungeon Hack, was early and most roguelike of them all. The much more popular Diablo came later and was not turn based, even if the game mechanics was kind of the same. Of course people tried making graphical front ends to the classic roguelikes with varying success. Falcon's Eye was probably the most known. A fork of that project called Vulture's is still under development and it's a game I have yet to try. (The demo video looks good though!)

To get back to the title of this post; It feel there is a huge revival going on in the roguelike scene. There's new blogs, columns, news pages and games showing up everywhere and older newsgroups and pages like RogueBasin seem to have a surge in activity and popularity. Even the ADOM homepage has gotten a face lift with a new blog about Thomas Biskups new roguelike JADE, and a brand new forum.

I guess that the main reason people enjoy making roguelikes is that the games are full of tricky algorithms like dungeon generation, field of vision, monster AI and more, but still small enough for a single developer to make by themselves. The main reason is of course that there's no graphics and no sound (well, DoomRL has sound), so all the programming effort and processing power can be spent on actual game play instead of bells and whistles. If you know what to do, creating a new game from scratch can be pretty quick. 7 Day Roguelike competitions seems to be more and more popular.

Some are more ambitious than others. The crazy guys behind Dwarf Fortress have quit their jobs to work full time on their ASCII dwarf game simulator. It's not really a classic roguelike, but the features are impressive. Julian Mensch has been working on his Incursion since 1999 and the planned release is in 2011!

All in all, it's a genre of games worth trying, and I guess it's a nice way to learn a new language trying to implement a 7DRL in it. (My attempt in J2ME was never completed though. Take a look at Dweller instead.)

Also, I wonder what's the best way to control a roguelike when you only have a touchscreen. Would be nice to have one for the OpenMoko phone.

2007-09-03

Vala and Vim

I'm a Gnome user and like reading Planet Gnome (In Google Reader of course!) to see what is going on. There's been quite some buzz around Vala lately so of course I had to check it out. Having used Java and C# quite a lot I've learned to like the syntax. Vala is still in early development, but it's improving quickly and already works well enough to play with.

To make the code look better in vim, add this to your vimrc file. I'm using Gentoo so I put it in /etc/vim/vimrc.local (Ignore the numbers, they are needed because Blogger sucks when you try to show code.)
  1. augroup vala
  2. au!
  3. au! BufRead,BufNewFile *.vala set filetype=vala
  4. au! Syntax vala source /usr/share/vim/vim71/syntax/cs.vim
  5. augroup END
Vala's syntax is similar enough to C# for this to look quite ok.

2007-08-19

OpenMoko 2007.2

A few weeks ago I ordered the Neo1973 phone and have been playing around with it a bit since. The software is currently early alpha state and often fails to even build correctly, but that's what we all expect at this early phase of development.

The easiest way to build a complete image to flash on the phone has been to use Rod Whitby's MokoMakefile. Basically all you have to write is "make openmoko-devel-image" and wait a few hours. To compile the whole OpenMoko distribution from scratch takes about 10 hours on my AMD64 3000+, so it's not something you just do in a heartbeat.

The OpenMoko Wiki is really working well and it's still expanding quickly. #openmoko on Freenode is also a very busy channel, currently around 320 people in it. There's always someone there to point you in the right direction if there's some trouble with your Neo.

I have yet to make any applications on my own to install or include in the rootfs, but I'm trying to keep up with the latest development and I'm still learning how bitbake works.

I haven't even been able to make a call with the phone yet, or been able to use the GPS. But that's fine for now, I did order a development sample of a phone. The battery on the Neo doesn't last long either since the power management isn't really working yet. Basically it can be on for a few hours, then it dies completely.

The screen looks great though, and the size is nice. The touchscreen feels good, but is a bit difficult to use near the edges. It's definitely a bit slow to use still, but the GTA02 version (mine is GTA01) will have some nice additions, including WiFi, 3D Graphics accelerators and a faster processor.

There's still a lot of people ordering the developer version of the phone and I'm sure that we'll see a lot of interesting applications fairly quickly. I do worry a bit about the stability and quality of it though. Hopefully they will lock down a stable release in good time before the public release of the phone so that there's enough time to test and bugfix without introducing more problems.

I have no doubt that there will be lots and lots of games and utilities for this phone in a years time. The Neo1973 is still only for tinkerers who like to mess around, but the future is promising.

2007-08-08

Good programmers and getting things done

Now I'm back from vacation and have been catching up on my blog feeds. I'm sharing all the posts and articles I feel are truly interesting in my Google Reader feed (and page), but the following two deserves a special mention:

Jeff Atwood's "Yes, But What Have You *Done*?" makes me want to "Do it f***ing now"!

The blog post at RevSys called "A Guide to Hiring Programmers: The High Cost of Low Quality" talks about expert programmers and really makes me want to be one.

Both touch on the subject of getting things done and being able to show some finished work. I feel like I'm doing too little at too many places, only touching the surface of the projects and communities I'm involved in and spending too much time reading and talking. Guess it's time to start getting things done!

P.S If anyone cares, I've given in and can now be found on the infamous Facebook.

2007-02-07

The k programming language

Found an old but interesting and well written article about the k programming language over at kuro5hin. It's a descendant from APL that I have the unpleasant experience to work with. k looks a lot more sane though, using normal ascii-characters and having some more advanced features than APL.

Still, no one can say that k is an easy language to read. Just take a look at this example from the company that owns k. It's an xhtml-parser, basically full of lines like these:

pre>x:_ssr/[x;"\"'<>";(""";"'";"<";">")]
:[#i:&159<_ic>


The APL legacy is clear, readability is totally missing.

But for the right task, I'm sure k is an excellent language. I believe in using the right tool for the job. You don't write an OS in ruby, but I wouldn't suggest writing a web-app in c either. (Just take a look at the Hula project. It's not exactly speeding along, look at Rails instead)

I still recommend reading the well written article on kuro5hin, you might just learn something.