23 September, 2010

SSH git access behind a proxy

To tunnel over tor put this in ~/.ssh/config:
Host git.assembla.com
  User git
  Hostname git.assembla.com
  Compression yes
  ProxyCommand nc -X5 -x 127.0.0.1:9050 %h %p
  IdentityFile ~/.ssh/my_private_key.rsa
Export GIT_PROXY_COMMAND in ~/.bashrc
export GIT_PROXY_COMMAND=~/.torgit
and create an executable ~/.torgit
exec nc -X5 -x 127.0.0.1:9050 "$@"

21 September, 2010

Color highlighting in less

To enable syntax highlighting in less, place this script in ~/.lessfilter and make it executable.
#!/bin/bash

ext="${1##*.}"
name="${1%.*}"
#[ "${name##*.}" == "$name" ] || ext="${name##*.}.$ext"

# enscript --color --language=ansi --highlight=eiffel -o - -q "$1"

if [ -n "$(grep "\(\*\.$ext)\)\|\(\*\.$ext|\)" /usr/bin/lesspipe)" ]; then
  # echo handle $ext by lesspipe"
  exit 1
else
  # echo "hadle $ext by source-highlight"
  source-highlight --failsafe --infer-lang -f esc --style-file=esc.style -i "$1"
  exit 0
fi
and than export LESSOPEN, LESSCLOSE and LESS in your ~/.profile:
# use highligting in less
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";
export LESS='-R --tabs 2'

01 April, 2010

Read/Write Performance Benchmark with dd

Trying to measure the read/write performance of a Patriot Xporter XT Boost 16GB USB Flash drive, I came up with a bash script. The Xporter XT Boost performance is:
  write:  13.40 MB/s
   read:  27.27 MB/s
Note: above 1 MB/s corresponds to 1024*1024 bytes/s. In dd 1 MB/s corresponds to 1000*1000 bytes/s. Interesting to note is that the sync mount option kills the performance, therefore the script:
#!/bin/bash

GB_COUNT=3
GB_SIZE=1000
MOUNT_OPTIONS="-o flush,uid=$UID"

flash_device=$1
flash_mount_point=/tmp/$RANDOM

READSPEED=0
WRITESPEED=0

function mount_flash {
  mounted=$(mount -l | grep $flash_device)
  if [ -z "$mounted" ]
  then
    echo "mounting..."
     sudo mount $MOUNT_OPTIONS $flash_device $flash_mount_point
    fi
}
function umount_flash {
  UNMOUNTING=$(date +%s)

  mounted=$(mount -l | grep $flash_device)
  while [ ! -z "$mounted" ]
  do
    echo "unmounting $flash_device ..."
    sudo umount $flash_device
    mounted=$(mount -l | grep $flash_device)
  done


  UNMOUNTED=$(date +%s)
  echo "! device $flash_device unmounted in $(($UNMOUNTED-$UNMOUNTING)) sec"
}

function init {
  mkdir -p $flash_mount_point
  if [ -z "$flash_device" ] || [ ! -b "$flash_device" ]
  then
    echo "Invalid device specified:[$flash_device]"
    exit
  fi

  umount_flash
  mount_flash
  echo ""
  echo "     Read/Write Benchmark"
  echo "=============================="
  echo "!   device:  $flash_device"
  echo "!  mounted:  $(sudo mount -l | grep $flash_device)"
  echo "!" 
  echo "=============================="
  echo ""
}

function write_test {
  mount_flash

  START=$(date +%s)

  for i in $(seq 1 1 $GB_COUNT)
  do
    echo "  writing $GB_SIZE MB: $i of $GB_COUNT"
    dd count=$GB_SIZE bs=1M if=/dev/zero of=$flash_mount_point/test.$i
  done

  echo "! unmounting.."
  umount_flash

  END=$(date +%s)
  TIME=$(($END-$START))

  echo "! writting $(($GB_COUNT*$GB_SIZE)) MB  done in: $TIME sec"
  echo ""

  integ=$(($GB_SIZE*$GB_COUNT/$TIME))
  frac=$((100*$GB_SIZE*$GB_COUNT/$TIME-100*$integ))
  WRITESPEED=$integ.$frac
  echo "! write: $WRITESPEED MB/s"
}

function read_test {
  mount_flash
  START=$(date +%s)

  for i in $(seq 1 1 $GB_COUNT)
  do
    echo "  reading $GB_SIZE MB: $i of $GB_COUNT"
    dd count=1000 bs=1M of=/dev/null if=$flash_mount_point/test.$i
  done

  umount_flash

  END=$(date +%s)
  TIME=$(($END-$START))

  echo "! reading $(($GB_COUNT*$GB_SIZE)) MB done in: $TIME sec"
  echo ""

  integ=$(($GB_SIZE*$GB_COUNT/$TIME))
  frac=$((100*$GB_SIZE*$GB_COUNT/$TIME-100*$integ))
  READSPEED=$integ.$frac
  echo "! read: $READSPEED MB/s"
}


init
write_test
read_test

echo "======================"
echo "  Benchmark Result:"
echo ""

echo "  write:  $WRITESPEED MB/s"
echo "   read:  $READSPEED MB/s"

echo ""
echo "======================"
Worth reading - http://www.hjreggel.net/cardspeed

22 March, 2010

An .emacs File

Here it is:
(display-time)

(custom-set-variables
 '(inhibit-startup-screen t)
 '(load-home-init-file t t)
 '(standard-indent 2)
 '(tab-width 2))


; UTF-8 compatibility
(prefer-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)

; turn syntax coloring
(global-font-lock-mode t)


(pc-selection-mode )
(pc-bindings-mode )


(require 'php-mode)

;(add-to-list 'load-path "~/.emacs.d/plugins/color-theme-6.6.0/")
(require 'color-theme)
(color-theme-initialize)
(setq color-theme-is-global t)
(color-theme-dark-laptop)

22 February, 2010

IPv6 Configuration

The following procedure seems to work for me: First convert the existing IPv4 address to IPv6 address:
kpe@somewhere# ipv6calc --ipv4_to_6to4addr 10.1.208.11
2002:a01:d00b::
Then change static configuration in /etc/network/interfaces like this:
auto eth0
iface eth0 inet6 static
address 2002:a01:d00b::
gateway 2002:a01:d001::
network 2002:a01:d000::
netmask 40
up route -v add default gw 10.1.208.1 dev eth0
To let avahi resolve the IPv6 addresses change the hosts line in /etc/nsswitch.conf:
hosts:          files mdns6_minimal [NOTFOUND=return] dns mdns6
to:
hosts:          files mdns_minimal [NOTFOUND=return] dns mdns

20 April, 2009

Dvorak DE Layout

Followind the idea described here I defined a Dvorak Keyboard Layout extension allowing me to input the german umlauts and sharp 's' by pressing AltGr. To use, create a file /usr/share/X11/xkb/symbols/us_dvorak_de containing this:
// us_dvorak_de: Custom extended us keymap

default
partial alphanumeric_keys
xkb_symbols "dvorak-de" {
  name[Group1]= "USA - Dvorak DE";


  include "us(dvorak)"
  include "level3(ralt_switch)"

  key <AC03> {[ e,            E,           EuroSign,       U2203           ]};
  key <AD09> {[ r,            R,           registered                      ]};
  key <AC08> {[ t,            T,           trademark                       ]};
  key <AC04> {[ u,            U,           udiaeresis,     Udiaeresis      ]};
  key <AC02> {[ o,            O,           odiaeresis,     Odiaeresis      ]};
  key <AC01> {[ a,            A,           adiaeresis,    Adiaeresis       ]};
  key <AC10> {[ s,            S,           ssharp                          ]};
  key <AC06> {[ d,            D,           degree                          ]};
  key <AD08> {[ c,            C,           copyright,     cent             ]};
  key <AB07> {[ m,            M,           mu                              ]};
  key <AD02> {[ comma,        less,        lessthanequal, lessthanequal    ]};
  key <AD03> {[ period,       greater,     ellipsis,      greaterthanequal ]};
};
The most reliable way to activate the layout seems to be:
setxkbmap -option lv3:ralt_switch,grp:lwin_toggle us,bg,us_dvorak_de ,,dvorak-de
Better is to specify this in /etc/default/console-setup, e.g.:
XKBMODEL="pc105"
XKBLAYOUT="us,bg"
XKBVARIANT="dvorak-intl,"
XKBOPTIONS="grp:lwin_toggle,lv3:ralt_switch"

09 May, 2008

Fixing the Sun Java Crash in Eclipse on 64 bit Linux

After a lot of easy reproducible crashes of the Sun JVM when running eclipse, I found a way of fixing them, add -XX:-PrintCompilation to the -vmargs of your eclipse.ini. When eclipse crashes, take a look at the hs_err_pid<pid>.log file. Somewhere inside you will find a line like this (search for Current CompileTask):
Current CompileTask:
C2:2393      org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding.<init>(Lorg/eclipse/jdt/internal/compiler/lookup/ParameterizedTyp
eBinding;Lorg/eclipse/jdt/internal/compiler/lookup/MethodBinding;)V (435 bytes)
Now you can exclude the method from being compiled by the HotSpot:
-XX:CompileCommand=exclude,org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding,<init>
My eclipse.ini looks like this:
-showsplash
org.eclipse.platform
-vmargs
-Xms256m
-Xmx1024m
-XX:MaxPermSize=128m
#-XX:-PrintCompilation
-XX:CompileCommand=exclude,org/eclipse/core/internal/dtree/DataTreeNode,forwardDeltaWith
-XX:CompileCommand=exclude,org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding,<init>
Some more HotSpot VM Options could be found here.