Sunday, 16 May 2010

Remap some kyes

In awesome I left the "Mod4" (Win-key) as modifier, but the keyboard on my laptop has only one suck key. Moreover, there is an useless "Context-Menu" key. Let's remap it to the another Mod4:

Content of .Xmodmap:
keycode 135 = 133

(you can get keycodes from xev)
then add to autostart:
xmodmap ~/.Xmodmap

Wednesday, 5 May 2010

Awesome: keycodes instead of symbols in rc.lua

For people working with two keyboard layouts as me for instance, it always borrows, then an awful.key doesn't work on the second (ru) layout. You could look for the keycodes pressing the keys while xev is running, but I found it slow:

xev &>/tmp/keycodes
...press needed keys...
cat /tmp/keycodes | grep keycode | awk '{print $7 " = \"#" $4 "\""}' | tr -d '),' | uniq
...
PROFIT!

I got:
a = "#38"
b = "#56"
c = "#54"
d = "#40"
e = "#26"
f = "#41"
g = "#42"
h = "#43"
i = "#31"
j = "#44"
k = "#45"
l = "#46"
m = "#58"
n = "#57"
o = "#32"
p = "#33"
q = "#24"
r = "#27"
s = "#39"
t = "#28"
u = "#30"
v = "#55"
w = "#25"
x = "#53"
y = "#29"
z = "#52"

The bindings look like this
awful.key({ modkey }, z, function () awful.util.spawn("ncmpcpp prev") end),
awful.key({ modkey }, x, function () awful.util.spawn("ncmpcpp play") end)
...
and so on


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)