Monday, June 1, 2015

Endless extracting of tar.bz2 archive

Funny story. Over a year ago I've backed up a project directory to tar.bz2 archive. Today I've decided to check what's inside. I've encountered a frozen window of 'extract here' option from file context menu.

I've killed the extract process and rerun it from a terminal:
tar -xvvf archive.tar.bz2
After few normal lines i've seen smth (in fact thousands of such lines):
hrwxr-x--- user/group       0 2013-02-06 23:20 workspace/a/b/a/b/f.go link to workspace/a/b/f.go
hrwxr-x--- user/group       0 2013-02-06 23:20 workspace/a/b/a/b/a/b/f.go link to workspace/a/b/a/b/f.go
This clued me, that probably the archive kept the symbolic links. After Googling and reading tar manual I had this idea: let's remove a symlink from an archive:
tar --delete -f archive.tar workspace/a/b/a
This worked just well :-)

Thursday, May 28, 2015

pep8

I've got very comfortable with clang-format for C++ and gofmt for Go. Every time I have to use some other language i'm missing them very much. Today I've found a solution for Python. It makes life so much easier. The two awesome tools are:

pep8

pep8 is a tool to check your Python code against some of the style conventions in PEP 8.
https://pypi.python.org/pypi/pep8

autopep8

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pep8 utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pep8.
https://github.com/hhatto/autopep8

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")