Code for Concinnity


Thunderbird hanging with 100% CPU usage — culprit discovered — the Google Contacts add-on

Several months ago I started using the Google Contacts add-on for Thunderbird and it’s been hanging periodically ever since. I just thought it’s Thunderbird and tried all those compacting folder, resetting the cache thing.

Today it hang again and I was frustrated, so I did dtruss (strace) on it and found that it seemed to be stuck in an infinite loop trying to access my Google contact feed.

I replaced it with the gContactSync add-on and it’s working smoothly now.

Published by kizzx2, on May 6th, 2013 at 9:35 pm. Filled under: Uncategorized Tags: , , No Comments

Install R <= 2.13 with Homebrew

Probably Homebrew has changed much since then, with Superenv and stuff. If you are stuck at an old R version and need to install it using Homebrew, you need to add depends_on :x 11 to /usr/local/Library/Formula/r.rb, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# /usr/local/Library/Formula/r.rb
class R < Formula
  url 'http://cran.r-project.org/src/base/R-2/R-2.13.1.tar.gz'
  homepage 'http://www.r-project.org/'
  md5 '28dd0d68ac3a0eab93fe7035565a1c30'

  depends_on 'valgrind' if valgrind?
  depends_on :x11 # Add this line

  def options
    [
      ['--with-valgrind', 'Compile an unoptimized build with support for the Valgrind debugger.']
    ]
  end


# ...
Published by kizzx2, on April 25th, 2013 at 11:29 am. Filled under: UncategorizedNo Comments

tmux-sync — Open a dozen of synchronized tmux panes easily

While managing server clusters I often want to open SSH session to a dozen of machines and have them run the same set of commands, interactively. So I wrote tmux-sync to do this:

1
tmux-sync my-session 'ssh host1' 'ssh host2' 'ssh host3' 'ssh host4'

The above command drops you into a tmux session like below. Your input will be sent to all the panes in tmux:

The source code:

Published by kizzx2, on February 8th, 2013 at 10:28 pm. Filled under: Uncategorized Tags: , , , , , No Comments

A Clean Approach to Partial Object Validation with Rails + Wicked Wizard

This is cleaner than the official method IMO, because it involves zero / minimal model object modification. The wizard logic clearly belongs to the controller only.

The basic ideas are:

  • Derive from the ActiveRecord
  • Override save to make Wicked behave. You can do arbitrarily complex thing there without wrangling with validation conditions.

Here’s the code:

Here is another version using a partial flag to persist the partial object in database:

Published by kizzx2, on February 6th, 2013 at 11:00 pm. Filled under: Uncategorized Tags: , , No Comments

Performance benchmark for Windows EFS, and BoxCryptor

Didn’t have the time to do a very serious benchmark but in case this is useful:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Some SSD, unencrypted
$ dd if=/dev/zero of=zero bs=500M count=1
1+0 records in
1+0 records out
524288000 bytes (524 MB) copied, 4.42172 s, 119 MB/s

# Some SSD, with EFS
$ dd if=/dev/zero of=zero bs=500M count=1
1+0 records in
1+0 records out
524288000 bytes (524 MB) copied, 13.4115 s, 39.1 MB/s

# Some SATA HDD, unencrypted
$ dd if=/dev/zero of=zero bs=500M count=1
1+0 records in
1+0 records out
524288000 bytes (524 MB) copied, 8.64324 s, 60.7 MB/s

# Some SATA HDD, BoxCryptor
$ dd if=/dev/zero of=zero bs=500M count=1
1+0 records in
1+0 records out
524288000 bytes (524 MB) copied, 17.8249 s, 29.4 MB/s

Another run using a Mac with some SSD hard disk. CoreStorage vs. TrueCrypt vs BoxCryptor:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Unencrypted, SSD
$ dd if=/dev/zero of=zero bs=500m count=1
1+0 records in
1+0 records out
524288000 bytes transferred in 1.431038 secs (366 MB/sec)

# CoreStorage (AES-XTS, default), SSD
$ dd if=/dev/zero of=zero bs=500m count=1
1+0 records in
1+0 records out
524288000 bytes transferred in 3.975945 secs (131 MB/sec)

# TrueCrypt (AES-XTS, default), SSD
$ dd if=/dev/zero of=zero bs=500m count=1
1+0 records in
1+0 records out
524288000 bytes transferred in 3.984627 secs (131 MB/sec)

# BoxCryptor, SSD
$ dd if=/dev/zero of=zero bs=500m count=1
1+0 records in
1+0 records out
524288000 bytes transferred in 8.353867 secs (62 MB/sec)
Published by kizzx2, on February 5th, 2013 at 1:44 am. Filled under: Uncategorized Tags: , , , , , No Comments

EFS causing lsass.exe Local Security Authority Process using 100% CPU

So I was using Windows EFS the other day to encrypt some files. This is surprisingly easy to use and beats TrueCrypt and Mac’s disk encryption in the usability department:

1
cipher /E /S:MyFolder

I encrypted AppData, which is a good thing to do since many applications leave its trace there. When I rebooted and logged in, I got lsass 100% CPU and a black desktop.

TL;DR If you changed your password via MMC, you need to re-import your EFS key

The way that EFS works is by protecting your EFS certificate with your login password. That implies some work needs to be done when you change your password. MMC’s “Set Password” doesn’t do it (it warns specifically against this, but this is the first time I actually read what it says :P ).

It turns out that EFS spends quite a lot of CPU cycles for the wrong password case. Because I encrypted AppData lsass would just spin itself with the obsolete password, trying in vain to decrypt the EFS cert.

So the way out was to remove the EFS key from certmgr.msc, and then reimport it. You may need to refresh the credential cache by

1
cipher /flushcache

If it worked, you should be able to display some encrypted text files transparently:

1
type test.txt

Tip: Use another account to runas /user:Victim cmd to do the above.

It’s been reported that the 100% CPU usage be related to the large number of SID files in AppData\Microsoft\Protect. I suspect it’s another consequence of this cause.

(The correct way to change password is to select Change Password in Ctrl+Alt+Del. I don’t know of a command line way to do it :/ Feel free to post in the comments)

Published by kizzx2, on February 3rd, 2013 at 5:15 pm. Filled under: UncategorizedNo Comments

“One-click” Rakefile to build .framework for iOS

This technique is based on Jeff Verkoeyen’s method. I find that modifying .xcodeproj files to be rather inconvenient so I whipped up a Rakefile that can be easily copied and pasted into new projects:

Published by kizzx2, on December 17th, 2012 at 12:50 am. Filled under: UncategorizedNo Comments

Ultimate Mac keyboard trick

After two years of using Mac, I just discovered the wonder of the Help menu item.

⌘ + /

If you are like me and regard yourself as a “pro” user you’d probably discard Help as something you’ll never need. But the fact is that you can access every menu item from the search field:

I have always thought that Windows does a better job at serving “pro” users due to menu access shortcuts (Alt + something). This thing from Mac is arguably more hacker friendly.

Published by kizzx2, on December 7th, 2012 at 9:14 pm. Filled under: UncategorizedNo Comments

Vim keybindings in Xcode

Finally @JugglerShu stepped up and wrote the wonderful XVim. I just have the spread the word and personally report that it worked right out of the box. Thanks JugglerShu!

Published by kizzx2, on November 26th, 2012 at 11:30 pm. Filled under: UncategorizedNo Comments

Install Passenger nginx on OS X with Homebrew

A clean and hack-less way to do it.

If you got the Undefined symbols for architecture x86_64: "_pcre_free_study", this is for you:

1
2
3
4
5
6
7
8
9
10
11
12
# Let Homebrew install the required dependencies
$ brew install nginx

# Remove it because we're using Passenger's ngnix
$ brew uninstall nginx

$ sudo mkdir -p /opt/nginx
$ sudo chown -R $(whoami):admin /opt/nginx

$ LIBRARY_PATH=/usr/local/lib CC=gcc passenger-install-nginx-module

# Done!
Published by kizzx2, on September 18th, 2012 at 3:20 pm. Filled under: Uncategorized1 Comment