Archive for the ‘languages’ Category

Pseudothreading with BASH

January 20, 2010

It’s more like a trick, but it’s better than repeat the same operation linearly. Some explanations:

TH_NUM=`ps aux | grep Python | grep -v "grep" | wc -l`

  • TH_MAX is the maximum number of “threads” that can be executed at the same time.
  • The first grep selects the threads that make use of python (you can change this, it depends on your script)
  • The second grep excludes the command you issued above 😉
  • wc counts the number of lines. The first time the result of the pipe is empty, so wc gives “0” as result.

#!/bin/bash
TH_MAX=10
for sample in `ls ./data`
do
while [ TRUE ]; do
TH_NUM=`ps aux | grep Python | grep -v "grep" | wc -l`
if [ "$TH_NUM" -le "$TH_MAX" ]
then
echo $( ./analyze_sample.py -s ${sample} ) > /dev/null &
echo -en " ${sample} "
break
else
echo -en "."
sleep 1
fi
done
done

Decode command line arguments given to a BASH script

August 25, 2009

Try the elegant way, at last!

For instance, imagine that your programme has the following arguments:
./myprog -s /source/directory -d /dest/directory -c deep

Then, the script myprog should contain a piece of code like this:


if [ $# -eq 0 ] ; then
echo "Usage: $0 -s -d -c"
exit 1
fi
while [ $# -gt 1 ] ; do
case $1 in
-s) source_dir=$2 ; shift 2 ;;
-d) dest_dir=$2 ; shift 2 ;;
-c) copy_mode=$2 ; shift 2 ;;
*) shift 1 ;;
esac
done

Of course, this is only a hint. Just tailor the decoding according to your needs.

Lectures about Gödel Escher and Bach

July 7, 2009

Here, they’re free and they look nice 🙂

Translator bots

December 19, 2007

Google has just announced that you can add some (hopefully) useful translation bots to your gtalk contacts. The format is “[from language]2[to language]@bot.talk.google.com”, and the supported language pairs are: ar2en, bg2en, de2en, de2fr, el2en, en2ar, en2de, en2el, en2es, en2fr, en2it, en2ja, en2ko, en2nl, en2ru, en2zh, es2en, fi2en, fr2de, fr2en, hi2en, hr2en, it2en, ja2en, ko2en, nl2en, ru2en, uk2en, ur2en, zh2en. So, for French to German translation, talk to fr2de@bot.talk.google.com.Western languages are working quite well, but according to Panxueni an expert of Chinese Languages at the University College of London the Chinese translation kind of… sucks 🙂 Well, it’s still an excuse to have a laugh with your Chinese friends 🙂