Wednesday, April 29, 2015

Torch7 weird error and Google Search without a solution

The below is an error one gets when working with Torch7 from time to time:
/usr/local/bin/luajit: /usr/local/share/lua/5.1/nn/Tanh.lua:4: attempt to index field 'nn' (a nil value)
stack traceback:
 /usr/local/share/lua/5.1/nn/Tanh.lua:4: in function 'updateOutput'
 /usr/local/share/lua/5.1/nn/Sequential.lua:29: in function 'updateOutput'
 /usr/local/share/lua/5.1/nn/Sequential.lua:29: in function 'forward'
 main.lua:93: in function 'opfunc'
 /usr/local/share/lua/5.1/optim/sgd.lua:43: in function 'sgd'
 main.lua:117: in function 'train3'
 main.lua:142: in main chunk
 [C]: in function 'dofile'
 /usr/local/lib/luarocks/rocks/trepl/scm-1/bin/th:131: in main chunk
 [C]: at 0x00406260
Reading a bit about similar errors(1) I've concluded that probably the type of Tensor is wrong. I work on torch.CudaTensor objects, why the problem? I've forgot to import the correct library:
require("cunn")

Wednesday, April 22, 2015

Reflex - trigger an execution of command on a file change event

How many times you were working on some tiny project that needs to be rebuild / restarted after you modify the code? I guess often.

After experimenting with some solutions I found an ultimate one: https://github.com/cespare/reflex
Installation:
go get github.com/cespare/reflex
Automatically recompiling markdown file into html every time the file is changed:
reflex -r '\.md$' blackfriday-tool -page article.md article.html
Or you can restart Go app when saved files:
reflex -r '\.go$' -- go run main.go

Wednesday, April 15, 2015

xmonad and screen off

In Ubuntu with default windows manager it just works, with Xmonad it doesn't, turning the screen off and making the eco-people happy (saving your electricity bill).

The inspiration for solution comes from:
http://superuser.com/questions/590225/disable-screen-turn-off

Checking xset tool in terminal shows smth:
xset
usage:  xset [-display host:dpy] option ...
    To turn bell off:
 -b                b off               b 0
    To set bell volume, pitch and duration:
  b [vol [pitch [dur]]]          b on
    To disable bug compatibility mode:
 -bc
    To enable bug compatibility mode:
 bc
    To turn keyclick off:
 -c                c off               c 0
    To set keyclick volume:
  c [0-100]        c on
    To control Energy Star (DPMS) features:
 -dpms      Energy Star features off
 +dpms      Energy Star features on
  dpms [standby [suspend [off]]]     
       force standby 
       force suspend 
       force off 
       force on 
       (also implicitly enables DPMS features) 
       a timeout value of zero disables the mode 
    To set the font path:
  fp= path[,path...]
    To restore the default font path:
  fp default
    To have the server reread font databases:
  fp rehash
    To remove elements from font path:
 -fp path[,path...]  fp- path[,path...]
    To prepend or append elements to font path:
 +fp path[,path...]  fp+ path[,path...]
    To set LED states off or on:
 -led [1-32]         led off
  led [1-32]         led on
 -led named 'name'   led off
  led named 'name'   led on
    To set mouse acceleration and threshold:
  m [acc_mult[/acc_div] [thr]]    m default
    To set pixel colors:
  p pixel_value color_name
    To turn auto-repeat off or on:
 -r [keycode]        r off
  r [keycode]        r on
  r rate [delay [rate]]
    For screen-saver control:
  s [timeout [cycle]]  s default    s on
  s blank              s noblank    s off
  s expose             s noexpose
  s activate           s reset
    For status information:  q
    To print version: -version

The interesting part is dpms. To force turn off the screen one has to run:
xset dpms force off
And it would be great to integrate it with a 'lock screen' keyboard shortcut in Xmonad configuration:
    -- lock screen
     , ((modm .|. shiftMask, xK_l     ), spawn "gnome-screensaver-command -l && xset dpms force off")