Sunday, 25 April 2010

chmod -x chmod

It's funny, but reversible. Ask your guru, if he knew this :)
The solution is:
# /lib/ld-linux-so.2 /bin/chmod +x /bin/chmod

Sunday, 18 April 2010

The heavest packages on your Gentoo (bash)

Pretty simple
qsize -C $(qlist -I -C) | cut -f 6,1 -d ' ' -s | sort -k2 -n | awk '{printf "%-55s%s\n", $1, $2}'
needs gentoolkit package, of course.

This | tail shows:
dev-libs/boost-1.39.0: 97424.678
dev-libs/boost-1.41.0-r3: 100898.250
media-gfx/picasa-3.0.0.57.4402.0_beta: 101253.355
net-fs/samba-3.5.2: 105293.911
dev-java/icedtea6-bin-1.7.2: 114997.25
dev-vcs/git-1.7.0.2: 119868.18
dev-java/sun-jdk-1.6.0.19: 170550.662
sys-kernel/vanilla-sources-2.6.34_rc4: 369523.572
dev-lang/ghc-6.10.4: 417348.438
app-office/openoffice-bin-3.2.0: 480966.851


Having seen, which size they have on Ubuntu (OOo - 124 Mb, kernel - 94 Mb), I find it awesome. Perhaps its the consequence of -O2 instead of -Os

Sunday, 4 April 2010

Python one-line scripts

It's not so crazy as it could be with perl, but still weird with a little of functional magic:

to get the recurcive list of full-path-names under working directory:

python -c 'import os; print map(lambda x: os.sep.join(x), reduce(lambda x,y: x+y, map(lambda x: zip(*x), [((l[0],)*len(l[2]),l[2]) for l in os.walk(os.getcwd())])))'

python3 differs a little: there is no built-in reduce, map returns a map-object, not a list, print is a function.

python3 -c 'from functools import reduce; import os; print (list(map(lambda x: os.sep.join(x), reduce(lambda x,y: list(x)+list(y), map(lambda x: zip(*x), [((l[0],)*len(l[2]),l[2]) for l in os.walk(os.getcwd())])))))'

Now let's use it to get a list of dicts like {file name: md5}

python -c 'import hashlib, os; print map(lambda x: {x.name : hashlib.md5(x.read()).hexdigest()}, [open(f) for f in map(lambda x: os.sep.join(x), reduce(lambda x,y: x+y, map(lambda x: zip(*x), [((l[0],)*len(l[2]),l[2]) for l in os.walk(os.getcwd())])))])'

python3 -c 'from functools import reduce; import os,hashlib; print(list(map (lambda x: {x : hashlib.md5(open(x, "rb").read()).hexdigest()}, [f for f in filter(os.path.isfile, map(lambda x: os.sep.join(x), reduce(lambda x,y: list(x)+list(y), map(lambda x: zip(*x), [((l[0],)*len(l[2]),l[2]) for l in os.walk(os.getcwd())]))))])))'

No wonder, it works slower as the simlpest way as it a C-binary:md5sum `find . -type f`

P.S.Early I saw another one example of an 1-line gui(!) application:
type('', (__import__('wx').App,), dict(OnInit=lambda self:__import__('wx').Frame(None, -1, "Hello world!").Show(True)))(0).MainLoop()

(Needs wxpython, of course)