]]>https://asleepfromday.wordpress.com/2013/11/19/rxvt-xterm-freetype-%e4%b8%ad%e6%96%87%e9%a1%af%e7%a4%ba-chinese/feed/1Johnfont-testTwo-Finger Scrolling on ThinkPad X220 + Ubuntu 12.04 (precise)https://asleepfromday.wordpress.com/2013/11/16/two-finger-scrolling-on-thinkpad-x220-ubuntu-12-04-precise/
https://asleepfromday.wordpress.com/2013/11/16/two-finger-scrolling-on-thinkpad-x220-ubuntu-12-04-precise/#respondSat, 16 Nov 2013 02:18:01 +0000http://asleepfromday.wordpress.com/?p=368Continue reading →]]>The TrackPoint on a ThinkPad laptop is one of the main reasons why I kept buying laptops from them. However, as a heavy laptop user who refused to carry around one extra mouse, the constant usage of TrackPoint can cause a significant amount of pain to my fingertip, which is very unpleasant. An once-in-a-while quick movement is okay, but scrolling up/down takes longer and requires more pressure, which is the main cause of discomfort.

As a possible solution, I’ve tried to enable TouchPad and two-finger scrolling. However, for some reason it didn’t work by setting it in gnome-control-center, so instead I used the old faithful xinput. From the output of xinput list-props "SynPS/2 Synaptics TouchPad", it’s easy to spot “Synaptics Two-Finger Scrolling”, and the two parameters can enable vertical and horizontal scrolling, respectively.

The default setting of two-finger scrolling was far from intuitive — normally people would expect it to work just like the way it works on touch devices: you touch the screen, then you can push the document up by moving your finger up. That means scrolling down when your finger is moving up. But on my laptop, moving two fingers up means scrolling up, which causes the document to move down!

To make this problem worse, there is no setting in gnome-control-center to inverse this. Again, this can be solved with xinput by simply changing the values of “Synaptics Scrolling Distance” from 100 100 to -100 -100.

]]>https://asleepfromday.wordpress.com/2013/11/16/two-finger-scrolling-on-thinkpad-x220-ubuntu-12-04-precise/feed/0JohnRun Pencil on Ubuntu 12.04 / 12.10https://asleepfromday.wordpress.com/2013/02/20/run-pencil-on-ubuntu-12-04-12-10/
https://asleepfromday.wordpress.com/2013/02/20/run-pencil-on-ubuntu-12-04-12-10/#respondTue, 19 Feb 2013 19:36:05 +0000http://asleepfromday.wordpress.com/?p=359Continue reading →]]>Pencil is simply the best (open) sketchy mockup solution on Ubuntu. However, as described on its download page, you cannot install it as a Firefox extension because it’s not compatible with the Firefox 18.x that comes with Ubuntu 12.04. The standalone version runs okay but some features such as export as PNG fails silently because of the same compatibility issue.

Turns out you don’t need to install the deb package provided on its website. Simply download the latest tar ball from the download page on google code, then download xulrunner (Mozilla runtime) from ftp.mozilla.org. I used the latest supported version: 16.0.2.

Now extract these to a preferred place, then add a file called pencil anywhere in your $PATH with the following content:

]]>https://asleepfromday.wordpress.com/2013/02/14/how-to-print-a-list/feed/0Johnvirtualenv, python-rope and pylinthttps://asleepfromday.wordpress.com/2012/11/28/virtualenv-python-rope-and-pylint/
https://asleepfromday.wordpress.com/2012/11/28/virtualenv-python-rope-and-pylint/#respondTue, 27 Nov 2012 18:37:57 +0000http://asleepfromday.wordpress.com/?p=334Continue reading →]]>python-ropemac is really useful for developing python in emacs, and pylint is also very handy as a analyzer. However, they both don’t work very well with virtualenv, especially because I always run emacs in server mode, and the server instance is usually not under virtualenv.

Here is how to make things work:

Edit .ropeproject/config.py:

# You can extend python path for looking up modules
prefs.add('python_path',
'/your-virtualenv-dir/lib/python2.7/site-packages/')

This is because if sum is to be modified, Python must decide which variable to change. sum += x is the same as sum = sum + x, and sum = suggests it’s a local variable, since all variable is by default local in Python. Given that, expression sum + x can not be evaluated because sum, as a local variable, is still undefined here.

If the sum += x line is removed, and sum + x is returned directly, the result will be:

0 0
1 -2
2 -4
3 -6
4 -8
5 -10
6 -12
7 -14
8 -16
9 -18

It runs okay, but the result is wrong. Where does function f get the value of sum? If Python cannot find a variable in locals(), it will try to find it from the scope above it, i.e. function adder, and sum is indeed defined in it. The real Python equivelent of the Go program above will be:

Functions are already first class objects in Python. Here we create a class that its instance behaves like a function, so it is a function because of duck typing.

]]>https://asleepfromday.wordpress.com/2012/10/08/curious-case-of-closure-in-go-and-python/feed/1JohnSwap every windows between workspaces in awesome wmhttps://asleepfromday.wordpress.com/2012/09/05/swap-every-windows-between-workspaces-in-awesome-wm/
https://asleepfromday.wordpress.com/2012/09/05/swap-every-windows-between-workspaces-in-awesome-wm/#respondTue, 04 Sep 2012 19:09:11 +0000http://asleepfromday.wordpress.com/?p=280Continue reading →]]>awesome is the tiling windows manager I use daily and I just wrote a very useful (at least for me) function for it. Basically it swaps every client (similar to windows) between the current tag (similar to workspace) and the target tag. Normally I put terminal clients for my current task at tag#3, right next to my Emacs-only tag#2 so I can quickly switch between browser (#1), editor and terminals. Now if I want to switch to a different task I just need to swap in terminals from another tag while swap out current terminals to that tag.

-- i is the index of target tag in variable `tags'
function ()
local screen = mouse.screen
local from = client.focus:tags()[1]
local to = tags[screen][i]
if to then
t = to:clients()
for i, c in ipairs(from:clients()) do
awful.client.movetotag(to, c)
end
for i, c in ipairs(t) do
awful.client.movetotag(from, c)
end
end
end

I put this under

-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, keynumber do
globalkeys = awful.util.table.join(globalkeys,
awful.key({ modkey }, "#" .. i + 9,
function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewonly(tags[screen][i])
end
end),
awful.key({ modkey, "Control" }, "#" .. i + 9,

in my copy of default rc.lua.

]]>https://asleepfromday.wordpress.com/2012/09/05/swap-every-windows-between-workspaces-in-awesome-wm/feed/0JohnMulti-thread testing in Pyramidhttps://asleepfromday.wordpress.com/2012/08/30/multi-thread-testing-in-pyramid/
https://asleepfromday.wordpress.com/2012/08/30/multi-thread-testing-in-pyramid/#commentsThu, 30 Aug 2012 06:39:27 +0000http://asleepfromday.wordpress.com/?p=275Continue reading →]]>If you want to do multi-thread testing in Pyramid, it probably won’t work the first time because request and registry are thread local, and things like get_renderer will call get_current_registry. When it happens in a thread, it won’t get the same value as it would have in the main thread.

There is no guarantee that pyramid.threadlocal.manager will always be there. Even if it’s there, there’s no guarantee it can be used this way. So, this should only be considered as a temporary workaround.