Monday, April 8, 2013

Emacs keyboard delay when switching frame focus

I recently ran into an annoying issue with Emacs; I'm not sure what initiated this problem, but it might be that the default value of focus-follows-mouse changed. Or Ubuntu changed.

Here's the issue that I was seeing:

  • I have multiple Emacs frames, and I like to switch between them often.
  • Switching between them by using Alt-Tab, or clicking, would result in no problems.
  • However, using the interactive function other-frame (via a keybinding) results in a problem that there's an approximately 2 second delay from switching focus to when the keyboard would accept input again. Even worse, Emacs seems to have forgotten what modifier keys I had down, so when it did accept keyboard input, it wouldn't know that I still had the control key held down.
I tried various ways of debugging this to see if anything was going on (xev, strace) but ultimately I figured it out by reading M-x describe-function other-frame. That reveals the following text:


To make this command work properly, you must tell Emacs
how the system (or the window manager) generally handles
focus-switching between windows.  If moving the mouse onto a window
selects it (gives it focus), set `focus-follows-mouse' to t.
Otherwise, that variable should be nil.

When I M-x describe focus-follows-mouse, it shows t, which is wrong. So I instead added the following to my .emacs:

(setq focus-follows-mouse nil)

and now everything is back to normal. Why did that setting break things? Not sure. Maybe Emacs didn't call something it should have called assuming X would take care of it. Or the other way around. Anyhow, it's much better now.

Some details on my setup:
  • Ubuntu 12.04 Precise Pangolin
  • Emacs 23.3.

Sunday, October 21, 2012

Ubuntu 12.10 available?


New release '12.10' available.
Run 'do-release-upgrade' to upgrade to it.

$ do-release-upgrade 
Checking for a new Ubuntu release
No new release found

Hmm....
(Seems 12.10 is released, just not working with do-release-upgrade yet)

Monday, June 11, 2012

Python re.match doesn't guarantee $

When choosing a method to call with Python's re module, it's common to consider search() vs match(). However, note that:

re.match('pattern', s)
is not the same as
re.search('^pattern$', s)

re.match only guarantees that the beginning of the string is matched, not that the entire string is a match. Some simple examples:


>>> re.match('[a-z]+', 'abc123')
<_sre.SRE_Match object at 0x7f92136abc60>
>>> re.match('[a-z]+$', 'abc123')
>>> 

Note that the second match statement guarantees that the match extends to the end of the string.

Saturday, April 14, 2012

TurboTax 2011 and AMT Credits

Disclaimer: I am not a Tax Advisor, CPA, CFP, or any other type of legal/financial/tax professional.

I've found some AMT credits that TurboTax wasn't giving me, because it didn't fill in values from 2008 and 2009, even though I've been using TurboTax every year since at least 2008.

When filling out your 2011 Taxes, be sure to follow the interview questions for Credit for AMT Paid in Prior Year. You can see it in the Deductions and Credits page as such:



Next check the values on this screen:







TurboTax seems to have carried over the correct values for me from 2010 (I blanked them out in the screenshots, sorry).

And check the 2010 Form 6251 Amounts, which for me also seem to be correct:





















The following screen is, I believe, the reason why I wasn't getting a credit:















These values were blank. Once I looked up all the values from my previous returns, and filled them out correctly, TurboTax computed an AMT credit for me.

There's some discussion of this on the Intuit Community site.

And as always, consult your tax advisor.

Sunday, December 25, 2011

Zoneminder: Got unexpected memory map file size

I'm trying to capture video from a device that's 640x480 24bit color, but I'm getting this in /var/log/syslog:

ERR [Got unexpected memory map file size 9217192, expected 36865192

Google-ing for this doesn't turn up anything except the Zoneminder source code; but it turns out that this is caused by too small a setting in /proc/sys/kernel/shmmax. This is explained the Zoneminder FAQ.

After updating my /proc/sys/kernel/shmmax to the recommended 128MB, it works just fine...

Wednesday, November 9, 2011

EasyCap DC60 and Ubuntu 11.10

I got an EasyCap DC60 from Amazon to see if it would work with my Ubuntu box to capture video. It looked promising at first... The output from dmesg looks like this:

[ 3391.497363] easycap::0adjust_standard: selected standard: PAL_BGHIN
[ 3391.808248] easycap::0adjust_format: sought:    640x480,UYVY(0x59565955),1=field,0x00=std mask
[ 3391.808256] easycap::0adjust_format: sought:    V4L2_FIELD_NONE
[ 3391.808264] easycap::0adjust_format: actioning: 640x480 PAL_BGHIN_AT_640x480_FMT_UYVY-n
[ 3391.832121] easycap::0adjust_brightness: adjusting brightness to  0x7F
[ 3391.856121] easycap::0adjust_contrast: adjusting contrast to  0x3F
[ 3391.880121] easycap::0adjust_saturation: adjusting saturation to  0x2F
[ 3391.904122] easycap::0adjust_hue: adjusting hue to  0x00

and it shows up as a video device just fine:

$ ls -altr /dev/video0 
crw-rw----+ 1 root video 81, 0 2011-11-05 22:58 /dev/video0

But when actually using it, it shows an image at first, and then shows grey bars. Note that the above message shows PAL, but I've tried NTSC, and other encodings with the same result. I found a thread about this on SourceForge.net, but the SourceForge project appears to be empty now. Google Cache currently contains the thread. The interesting pieces of text are:


The vertical grey bars usually mean that the front-end video chip cannot lock onto the analogue input signal.  This can happen if, for example, the video signal is really NTSC while the mplayer command line specifies PAL.  But in these circumstances, I would not expect to see any video output at all (apart from the grey bars).  The puzzling thing is that you do get some valid video, which then disappears.

One possibility is that the SAA7113H chip is raising a hardware "lost signal" flag when in reality the signal remains entirely viable (some aspects of this chip are known to be flaky).  To investigate this, it would be useful if you could reinstall the driver after changing line 31 of the script ./install.sh to
BARS=0
and run ./test4PAL.sh again.  This is a straight go/no-go test:  either it solves the problem or it is doesn't.  We don't need a verbose kern.log this time, so you can set DEBUG=0 in the installation script.
Since the SourceForge project seems to have disappeared, I'm not sure where install.sh is, or how to find it. Maybe the whole thing's moved to kernel.org. I suppose I could start digging around in the kernel source and see if I can figure out what that does...

Update: OK, this was a lot easier than I thought:

  • Google for "easycap site:kernel.org"
  • Find the README.
  • Remove all users of easycap kernel mod (shut down apps/services)
  • sudo rmmod easycap
  • sudo modprobe easycap 'bars=0'
  • Restart and try again...
Update 2: The next thing you should probably do is:
  • sudo vi /etc/modprobe.d/easycap.conf
  • options easycap bars=0
  • :wq
  • sudo reboot

Sunday, November 6, 2011

Zoneminder Memory.pm bug in 1.24.4


If you have Zoneminder installed and you're seeing this in /var/log/syslog:
Nov  6 14:36:11 machine zmwatch[2741]: ERR [Shared data size conflict in shared_data for monitor monitor, expected 328, got 316]
It's probably because of a bug that's been patched. On my distribution (Ubuntu 11.10) the file Memory.pm is at
/usr/share/perl5/ZoneMinder/Memory.pm
and the patch in question was applied at line 130.