Monday, August 29, 2005

Using screen: splitting screens

It's been a long time since I wrote about screen, but here is another one

It sometimes is useful to show two screen next to each other. In screen you can split the screen with C-a S. You're terminal will be split in two parts, one above the other.

The screen you were using is shown in the top part. The other part will be empty. To move to the other part press C-a TAB. You'll notice that this screen is empty. To make this screen useful you can switch to another screen by pressing one of the screen switch keys.

C-a TAB should also be used for switching back. The only thing that's left to say here is when you've created to many splits, you can type C-a Q to reset the screen to have only one screen visible.

Saturday, August 27, 2005

How to get better at something?

In my previous post I wrote about personal development. Probably the best way to get better at something is to do it (or more often, if you already do it).

I would like to be a better writer. Because of that I started to write this blog and articles about stuff I know. Other ways to get better are to read, practice and reflect. But the do it part is probably the most important.

Another important idea about learning, that it isn't a problem to fail at something, just stand up and try again, until it works.

Research even shows that you can learn new things, even if your not that young anymore. It's all about doing and wanting to learn.

Friday, August 26, 2005

Personal development for programmers

This is all about you keeping your programming job.

What it all comes down to is this. What can you do to be more than just a coding monkey?

Sunday, August 21, 2005

Problems with online concert information

In a previous post I wrote about a way to create better concert information by using up-to-date information from concert websites. Today I write about the problems.

The biggest problem is that it may be a long time before the system will be used by websites. There are some costs involved to set it up. The websites have to create a to generate the files, and the best way to do this is to use an automatic system.

The other way around, other websites may create other equivalent system that are just a little bit different. This way there will be multiple systems for specifying this information, and probably the only way to solve it, is support all different ways, as feed based systems, like FeedBurner do today.

Another problem that can comes is probably the content of the file. Questions like, what can be in there? and which url shall I use to identify the artist? A good way to solve this is to create good documentation, and good software to support this system.

I don't think that I've exposed all problems here, but it's a start and it will be a little bit easier for me to start the creation of the format. On of the things that I will have to do before I start with it is to search for equivalent systems, so I won't have to create it.

Friday, August 19, 2005

Online concert info

For some time I have been working on a system for searching, browsing and adding concert information. Using this system is not very efficient, because every concert has to be added to the database, the biggest part of the problem is de searching, and typing of the items.

Because I'm not very happy with this I have been thinking about a system that uses the internet. For this to work, concert organizers and artists could put a file on their webserver. This file will contain inforamtion about concert in some format. Every week or month, a bot will download that file and integrate it into the database.

The nice thing about this approach is that the files can be automatically generated from the concert information on the websites of the places and artists using their concert information system or content management system.

Also being human, not everyone will write the name of an artist the some way. There could be problems, when there are artists with the same name or if artists use 'The' in front their name, but not everywhere, or maybe not by everyone.

This last problem could of course be solved by using the url of the band's homepage in the file, because that is unique.

By creating something like this, we are already a step closer to the semantic web.

Addressbook online

I'd like to have a way to have updated contact information of peopl I know. This could be done by putting a file on a webserver, containing this address information. This file should be updated when you move, etc. Your friends and bussiness associates could then, using a PIM program like Evolution, import this file, or actually the link.

One problem would be that everyone can find your address info, and I'm not comfortable with that. But it wouldn't be a problem for my friends to have this info.

This means that it should be possible to restrict access to parts of the file. In practice this could mean that you create a second file, containing not all information, like only name and e-mail address. The first file should then be protected, but how can that be done.

Thursday, August 18, 2005

Flag questionable Blogger websites

I'm not sure when it was the first I could flag a blogger website as questionable, but it problably is a good way to get rid of all the spam blogs that are on Blogger.

Stupid information posts

OK, so the previous two post were a little crappy. But while they were used to get the ideas out there, it problably helped me to get the stuff a little better organized in my head, or something.

I still am very interested in people who write an application like this.

Information and stuff

When you use subversion to update, for example the addressbook, you can send a ping (like in rss services) to the gui application, that's used to manage this stuff, with some inter process communication system.

When using Linux and Gnome, dbus comes to mind. It would be easy to let subversion send the ping by using a post-commit script when the repository is changed.

The only problem that is left, how can this be integrated into other applications like Evolution.

What information?

  • E-mails
  • Addressbook
  • Todo-lists
  • And much more, of course...

Why subversion?

It's distributed, and can be secured, using ssh or something. And it's open source. So it solves a big part of the problem.

Productivity/Information Tool support

About a year and a half ago I heard about a product called Near-Time Flow. It's a publishing and collaboration tool, that can be used for researching, gathering information, searching, organizing and more. The problem for me is that it's a OSX program. And I don't use that.

But now the question. What programs are there for linux that can do this, or part of it?

One thing that comes to mind is the scrapbook extension for Firefox. This can be used to research webpages. But Flow does a lot more, some of which is really useful like version control and collaboration. Here I think of subversion, which can help with that.

Are there other programs that help to organize information? Maybe evolution, but that's very specific for PIM stuff. Maybe some kind of wiki, can be used, but then you will miss the special functionality that's so useful.

I'm not really sure where this is going. These are just ideas and stuff.

Another link with ideas about this is on 43folders: I want a pony.

Monday, August 15, 2005

Boost 1.33.0

The fine folks at Boost have created a new release of their fine C++ libraries. Boost is an opensource library that can be used to extend C++.

This new release includes all kinds of new features on top of the things it could already do. It includes a parser, portable threads, math classes and functions, program_options, smart pointers, different containers, string formatting and <function> stuff that C++ is missing. Just take a look at the library, and probably somethings is that you could use.

Mini icons

We all know these little icons for new, updated to show changes in the content of a website. These items are like small (31x14 px) to show some a changed condition a the page.

Just some time ago, I noticed these little icons, that are used by amazon.com to show some extra information about a review, like realname. Today I saw a little sale icon.

Is this a new pattern? And how can it be used on websites?

Sunday, August 14, 2005

Useful Tools: wget

wget is one of those tools that I use almost every week at least five times. It's not that I can't life without it.

wget downloads files from websites or ftp servers. Most of the time I use it for downloading screencasts or podcasts from websites when I'm using the terminal (which is like always), when it's to big to get it streamed.

What tools do you use all the time?

Saturday, August 13, 2005

Using screen: Key combinations

In the last few days I wrote about screen. And this is probably not the end yet. I'm not yet sure, about what else to write about screen.

I will write this summary post and we'll see about the stuff that's later to come out.

Key combinations

C-a ccreate a window
C-a C-aswitch to previous open window
C-a nswitch to next window
C-a pswitch to previous window (numerically)
C-a Nwhere N = 0-9, switch to screen N
C-a ddetach screen
C-a _monitor silence
C-a Mmonitor activity

Screen invocation

screen -qstart screen without warranty screen
screen -rreattach screen or exit if not available
screen -Rreattach screen or start one if not available

These are the screen commands I use most frequently.

Friday, August 12, 2005

Emacs Keyboard Macros

Keyboard macros are one the most useful tools in Emacs. I will start with a simple example.

Let's assume you have a website, and on one of the pages you have lists of fruit. The typing of these lists is becoming a lot of work, but you don't have database and programming skills.

Let's see how to create these lists with emacs. First type the list of items you would like in the lists. This is still needed because, it is the changing part in the lists.

apple
banana
pear

Something like that. Now to create the list items li, you have to type only one of those.

  1. Move point (the cursor) to the first item in the list, apple.
  2. Type C-x ( (start macro). All the keystrokes after this will be recorded.
  3. Type the begin tag, <li>.
  4. Go to the end of the line with C-e.
  5. Type </li> here.
  6. To make the macro even more useful, move to beginning of the next line with C-n C-a.
  7. Now type C-x ) (stop macro) to stop the recording of the macro.

With C-x e you can now execute the macro again. Do this until you are at the end of the list. That was all. Now you have a list that looks like this.

<li>apple</li>
<li>banana</li>
<li>pear</li>

As you may have noticed, the pattern is create a list of the text that is different on every row. Then create a macro for one line and move to the next line. Apply the macro on all the lines.

Of course there is still a lot more to learn about emacs keyboard macros, but I will save that for another time.

Using screen: Monitoring

For some programs it's not needed that you stay to watch every line of text it shows. On unix, most programs don't even show text until something happens.

To take advantage of this fact, screen has two functions. The first is monitoring for inactivity.

Inactivity is when a program doesn't do anything for a certain amount of time. It can be used to show when a compile is ready, but you don't want to wait or check. Monitoring for silence can be started or stopped by pressing C-a _.

The other function is monitoring for activity. This is problably useful for tail-ing log messages. With the key combination C-a M, you can start or stop the monitoring. Whenever there is activity on the window, it will be shown in the status line when you're on another window.

Thursday, August 11, 2005

Emacs tips

For me emacs is about doing less. Doing less is something computer programmers like, because most of the time it's duplication that we're removing and it's always easy to have a editor that helps us with that.

I will make a little list of the features that I think are useful.

just-one-space: removes all but one space from the text. If you have code that looks like:

int i =       0;

Calling just-one-space when the cursor is on the whitespace between the = and the 0, will make it int i = 0;. It removes all but one space.

keyboard macros: If you like to convert some data, but don't want to create a script in Perl or Ruby, you can use keyboard macros.

To start recording a marco use C-x (. Now type some commands. Type C-x ) to stop the recording. With C-x e you can rerun the macro. Macros are really usefull, so I will probably write about keyboard macros some more later.

html-helper-mode: This major mode contains a lot of nice key combinations for inserting html code. It uses tempo, so you could take a look at the code for the creating of the templates. To get syntax highlighting use the html-font module.

This is all for now. Maybe someone knows some nice stuff or links to good tips or useful modules. Please share!

Using screen: part 5

Screen is like a little, big tool, that can do all these nice things. But still there are some things about it, that aren't that nice. Every time the screen program is started a warranty message is shown. This is not really useful.

So I will show two ways to stop this behaviour. The first is to use the -q option when you start the program.

The second way is to use the startup_message off command in your .screenrc file. Just create a file called .screenrc and put the line in it. The next time you start screen you won't see the message.

There are many other options, which you can set in the .screenrc file. All these are documented in the info file that is included with your screen distribution.

Wednesday, August 10, 2005

Great Perl Modules: part 1

In this series I will try to list perl modules, that are useful or nice.

I use CGI::Untaint for one of my website, and it is really useful. It helps untaint cgi parameters. Part of the usefulness of this module comes from the fact that you can extend the kinds of input it will untaint.

First I will show a little example:

use CGI;
use CGI::Untaint;

my $cgi = CGI->new;
my $params = CGI::Untaint->new($q->Vars);

# now you can extract variables.
my $number = $params->extract(-as_integer => 'id');

If a parameter can't be extracted by the extractor undef will be returned.

Without extensions this module can extract three types: printable, hex and integer. But on CPAN there are many more modules in CGI::Untaint namespace, that can extract URLs, dates, hostnames, isbn and postal codes.

If you need another extractor, you can always write one yourself.

Using screen: part 4

In this fourth part of using screen, we'll look at the stuff that makes screen better, than just using multiple terminals in a windowmanager.

The thing is that when you're working with screen and have to log out, you don't have to close the current screen process. You can just detach the screen from the terminal and it won't stop, but will go on in the background.

When you later login again, the same screen process will still be running. You can then reattach to that process. To use this behaviour you only need te know two commands.

The first command you need to know is C-a d (mnemonic: detach). It will close screen, but will keep the applications inside it running.

The second command you need to know is screen -r (mnemonic: re-attach). It will reopen the screen you have started before, with all the applications still running inside it.

This can be used with irssi, or tail or any other program you can think of.

Programmer's Fonts

Programming fonts, as much an art as it is a science, probably. In the past I was always pretty satisfied with the 10x20 font that's usable trough emacs. But since some time I like to use the same font for my terminal and my editor.

At first this font was the Vera Monospace font, that is usable for programming, but I couldn't use it in emacs. Now I use the codingtobifont that can be found at the Proggy Programming Fonts website. Probably I tried all the fonts that are available on that website.

Emacs and templates

We all know GNU Emacs is a powerful editor. But when I see the editor used in the rails movie I really think that there are missing some things (or maybe they're there and I'm not aware of it). The editor that is used is TextMate and it does things that I would like to do more often with Emacs.

The most obvious missing thing in the movie is the template based code insertion. Sometimes only the method name or a class name is typed. And with a push of a button the rest of the code is inserted. I think it is easy to do this with emacs.

With some research I found two template system that enable me to create a similar piece of functionality. The first is skeleton and the other is tempo. Both libraries do the same thing: create a function that asks questions and inserts text.

I will show how to create a template that inserts a method definition for ruby. The inserted code should look like this:

def method_name|
end

The cursor should be where the | is, because you may want to insert arguments instead of just a body and no arguments.

The code for the skeleton library is:

(define-skeleton ruby-insert-def-method
  "Inserts a ruby function"
  "Method Name: "
  "def " str _ \n
  "end" \n \n)

When you call the function, it will ask you for a method name. Then it will insert the text using you answer for str and putting point at the place of _.

The tempo version of this same template looks like this:

(tempo-define-template "ruby-def-method"
   '("def " (p "Method Name: ") ~ n "end" n))

But the name of this function will be tempo-template-ruby-def-method. A problem with this code is that the ~ won't work in the standard version. You should take a look at EmacsWiki TempoMode page for a solution to this problem. Also be sure to require the tempo library before you try to use this code.

There are probably more templates that would be useful. Maybe I will show some more later.

Tuesday, August 09, 2005

Using screen: part 3

There are some ways to switch between screen windows. First you can switch to a window with a number. When we used C-a w last time, it showed some numbers in the window list. These numbers are the window numbers of the windows.

If you want to switch to window 1, you should type C-a 1. To switch to the first windows type C-a 0. You can switch to every screen from 0 to 9 this way.

The next way to switch to another window is by using the next and previous window key combination. These are C-a n for next and C-a p for the previous window. On the screen info page there are more ways shown to switch the window.

The last way to switch a screen is by using C-a C-a which will switch to the previous screen that was shown.

Next time I will show even more things you can do with screen.

Using screen: part 2

First you will need your copy of the screen program. On debian you'll need the screen package. For other system I'm not sure how to get it, but you take a look at the screen website.

To use screen start your favorite terminal program. Like rxvt, gnome-terminal or xterm. Then type on the command line:

# screen

It will now show some warranty blurb (which it won't show if you use the -q option).

You're now in a screen session. You can do everything you could do in a normal terminal, like typing commands, or using direction keys. Let's try that by typing some commands.

# ls
bin doc src

Ok, so it shows some directory like we expect. Type C-a c to create a new screen. That's control and a, followed by a c. Again we see an empty screen. Something like:

#

In this screen we can also type some commands. Type C-a w to get a list of all the screens that are currently open. The list at the bottom of the screen looks like this:

0-$ bash  1*$bash

This line shows the screen that are open at this time. The number is the screen number that is open. The - shows a screen that's not visible and the * shows the currently visible screen. The bash is the title of the screen.

Next time I will show some more tips on using screen, like switching between screens.

Using screen

Screen is a program that let's you keep multiple programs running in one terminal. But it's not all this small program does. According to the website:

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.

It may not yet be clear to you, how much power this program has, but it has, a lot.

In the next time, I will show some examples of using screen. This will include keybindings, but also examples of how and when to use screen.

Table of contents

  1. Introduction
  2. Starting screen and creating windows
  3. Switching windows
  4. Detach and Re-Attach
  5. Options and Configuration
  6. Monitoring
  7. Key combinations summary

Thursday, August 04, 2005

All this backup stuff has a reason

Everybody likes backups. But not everybody makes them. Still its a good idea to create backups. It happend to me and I didn't like it. It happened more times than I'd like to remember, but it shouldn't. So create backups, test them, and have a nice day.

Mark W. Shead has a horrorstory that we all should think about, especially if your a programmer. Also his tips at the end, are something to think about and implement.

Ruby script for subversion backups

My subversion backups are automatically created after a commit. I use the post-commit script to do this. In the hooks directory of your repository there is a file called post-commit.templ that explains how the post-commit script works. Take a look at it for more information about this.

The post-commit script is called with two arguments, repository and revision. These two arguments contains information you may want to use.

My backup script looks like this.

#!/usr/bin/ruby
# post commit script for backing up the source repository

repository = ARGV[0]
revision   = ARGV[1]

# create dump file
date = Time.new.strftime("%Y-%m-%d")
filename = "/home/peter/subversion-#{date}-r#{revision}.dump"
system("svnadmin dump /var/lib/svn > #{filename}")

# upload file
remote = "peter@allerhande:/home/peter/backup/subversion"
ssh = "ssh -i /home/peter/.ssh/rsync-key"
system("rsync -e '#{ssh}' #{filename} #{remote}")

It should be obvious that this is one of those script that is called secret software.

To create a backup, I first create a filename with the current date and the revision number. Then I use svnadmin to create a dumpfile with that filename. Then I use rsync to upload it to another computer.

More information about rsync can be found in my previous post.

Wednesday, August 03, 2005

Subversion Backups

In my previous post I wrote about making backups of subversion repositories. Only there is a problem. If you create a copy of the files in the repository directory, there is the possibility that the backup is incomplete or unusable. The solution is to create a dumpfile.

A dumpfile contains all the files in the repository. A dump file can be created with the command svnadmin dump /var/lib/svn > dumpfile. It uses svnadmin to create a dump file of the repository in /var/lib/svn and writes it to dumpfile.

I used a ruby program to create a dumpfile. The filename of the dumpfile that I created is based on the date and the revision: subversion-backup-<year>-<month>-<day>-r<revision>.dump. By using this filename, all files are sorted by date and contain the revision, which is also useful, when you have more than one revision a day (which you probable have).

Use rsync to create backups on other computers

It's a good idea to create backups of your source code. Today I've created some simple scripts that create a subversion dump file and upload it to one of my other computers. The scripts use ssh and rsync.

The tutorial I used is Using Rsync and SSH it explains how you can transport automatically and save/secret.

Each time I commit the source code to the repository, a post-commit hook is executed. This post-commit script creates a dump file of the repository and then uses rsync+ssh to upload it to the other computer.