selfjungle Just another WordPress weblog

12Aug/090

String templates with Perl

Here is a nice thing with perl.

  1. You have a string template, like an e-mail, with fields to change.
  2. This fields are stored in a CVS file.
  3. Perl changes this fields with hashes and regular expressions in no time.

Note: the field names are the keys in the hash, lines of the CVS are an array with hash refs.

#!/usr/bin/perl

use warnings;
use strict;

my @data = ();

# data.csv:
# bela,fired
# julcsi,killed
# jani,promoted

my $string_template = <<EOF;
Dear <name>,
   You have been <action>.
Br: Someone.
EOF

# CSV to hash
open FILE, "data.csv" or die $!;
while (my $line = ) {
    my %temp_hash = ();
    ($temp_hash{"name"}, $temp_hash{"action"}) = split (",", $line);
    chomp $temp_hash{"action"};
    push @data, \%temp_hash;
}
close FILE;

# replace & print
foreach (@data) {
    my $s = $string_template;
    $s=~s/<(.*?)>/$$_{$1}/g;
    print "$s\n";
}
Tagged as: No Comments
12Aug/090

qdict new release r19

New release of qdict, (r19 - as it's the 19th commit in SVN)

Changes:

  • Completer-aided input combobox (for gcide)
  • Better parsing (for gcide)

Download:
Source code: qdict_r19.tar.bz2

Link:
Check the "project page" for screenshots and more info: qdict

Tagged as: , No Comments
3Jun/090

bash shortcuts

A good set of shortcuts speeds up usage of every program, this applies to bash too.

My favourites
Home Move to the start of the line.
End Move to the end of the line.
Left Move back one character.
Alt + Right Move back one word.
Right Move forward one character.
Alt + Right Move forward one word.
Ctrl + u Delete from the cursor to the beginning of the line.
Ctrl + k Delete from the cursor to the end of the line.
Ctrl + w Delete from the cursor to the start of the word.
Esc + d Delete from the cursor position to the end of the word.
Ctrl + l Clear the screen leaving the current line at the top of the screen.
Alt + r Undo all changes to the line.
Ctrl + r Incremental reverse search of history.

Some more (incomplete lists)

CTRL Key Bound
Ctrl + a Jump to the start of the line.
Ctrl + b Move back a char.
Ctrl + c Terminate the command.
Ctrl + d Delete from under the cursor.
Ctrl + e Jump to the end of the line.
Ctrl + f Move forward a char.
Ctrl + k Delete to EOL.
Ctrl + l Clear the screen.
Ctrl + r Search the history backwards.
Ctrl + R Search the history backwards with multi occurrence.
Ctrl + u Delete backward from cursor.
Ctrl + xx Move between EOL and current cursor position.
Ctrl + x @ Show possible hostname completions.
Ctrl + z Suspend/ Stop the command.
ALT Key Bound
Alt + < Move to the first line in the history.
Alt + > Move to the last line in the history.
Alt + ? Show current completion list.
Alt + * Insert all possible completions.
Alt + / Attempt to complete filename.
Alt + . Yank last argument to previous command.
Alt + b Move backward.
Alt + c Capitalize the word.
Alt + d Delete word.
Alt + f Move forward.
Alt + l Make word lowercase.
Alt + n Search the history forwards non-incremental.
Alt + p Search the history backwards non-incremental.
Alt + r Recall command.
Alt + t Move words around.
Alt + u Make word uppercase.
Alt + backspace Delete backward from cursor.
Other keybindings
2T All available commands(common).
(string)2T All available commands starting with (string).
/2T Entire directory structure including Hidden one.
2T Only Sub Dirs inside including Hidden one.
*2T Only Sub Dirs inside without Hidden one.
~2T All Present Users on system from "/etc/passwd".
$2T All Sys variables.
@2T Entries from "/etc/hosts".
=2T Output like ls or dir.

Here "2T" means Press TAB twice

Escape Keys combinations
esc+d delete from the cursor position to the end of the word.
esc+f move forward a word.
esc+b move backward a word.
esc+t transpose two adjacent words.
Tagged as: No Comments
27May/090

qdict

Preface

About a month ago I started to play with QT. I just wanted to quickly pick some random subject and begin instead of waiting for a big idea and doing nothing.

The main idea is a GUI for dict. Edit field, output layout, nothing fancy, trying to be as minimalistic as possible.

Features

  • Html (formatted) layout of dict for better readablility
  • The entry field is a combobox which stores the previous entries
  • Parsing the gcide hits for lists, notes and links.
  • Unit tests for some core functions

Download

source: qdict_r15.tar.bz2

Compile & run

qmake qdict.pro
make
qdict

Todos

  • Forward/backward buttons if following links
  • Support for more database
  • TCP connection with the server instead of parsing the output of dict
  • Configuration dialog
  • Text autocompletetition
  • Bigger test coverage
Tagged as: , No Comments
25May/090

Bash history

I took a look around recently how to make life with bash easier and the help of the history is definitely a key issue.

.bashrc:

# enable bash history
set -o history
# bash history file length
export HISTFILESIZE=10000
# multi-line commands are stored in the history
shopt -s cmdhist
# no duplicates and empty lines
export HISTCONTROL=ignoreboth
# do not store lines:
export HISTIGNORE="&:ls:[bf]g:exit"
# append the history to the histfile instead of overwriting it.
shopt -s histappend
# update & re-read histfile after every cmd so terminals will share
export PROMPT_COMMAND="history -n; history -a"

Useful keys

ctrl + r : search in history backward
Page up/down : complete command due to history.

For page up/down part, you need to have the following lines in /etc/inputrc:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Links

Bash-History-Facilities
Searching for Commands in the History
Keeping bash history in sync on disk and between multiple terminals

Tagged as: No Comments
24May/090

Give

My thesis:

It was about a program I wrote, a maemo statusban plugin, the documentetion and the process I took.  That time I thought that GTK is going down and I my knowledge in it is going to be obsolete soon. But I doubted that at the and of the Uni even with 1-2 years of working experience in the field, one can make some significant research with usable output. So I wrote a small applet and used all my knowledge and help of my friends and ex-colleges I gained.

I got ~1.600 downloads, well, I think it was a success. Other than me and my consultant, I don't thing anyone has ever read my thesis...

link: maemo page

Details:

Statusbar plugin for easy drag & drop data sending via Bluetooth, just drag data to the icon.

The following applications are supported yet:

  • osso-notes
  • osso-filemanager
  • dates compiled with dnd
  • osso-addressbook.

TODOs:

  • patch modest to dnd support
  • make pand work.
23May/090

sefljungle::selfjungle();

Ok, here it comes.

This is just another techblog, mainly for fooling around and posting  programming related stuff in order to create a “code portfolio”. But who knows, maybe I'll find this "public jotter" beneficial one day.

So I'm going to post my coding projects and some findings in C, C++, linux, gentoo, QT and KDE.

Tagged as: , , , No Comments