Archive

Archive for the ‘Computers’ Category

Disable same-origin policy in Firefox

October 2nd, 2008

Just throwing up a quick post in the same vein as this gentleman who also lacked the Google-fu to quickly find it using the obvious search.

General, Web

Building Wine on Mac OS X

June 8th, 2008

There are probably a bazillion of these posts out there, but I wanted to play with DTrace and Wine in OS X (post on this to come) and had to get the thing built first. This is mainly a “here’s what I did” post, with some “and this is why” sprinkled in.

I grabbed the dependency I was missing (you might need others, like libjpeg and libpng3 that I already had around) and the latest source from git

sudo fink install fontforge git
git clone git://source.winehq.org/git/wine.git \
wine-git

Of course, it’s good practice not to muddy up your source tree, so build in a separate directory

mkdir bwine-git
cd bwine-git

Running just `configure` generates complaints about missing libxslt, libpng, and libjpeg. For libpng and libjpeg, I just needed to point to Fink’s libraries and headers under /sw. It took a little digging to figure out pkg-config had been installed by Fink, but since I wanted to use the system libxml and libxslt under /usr, I had to point pkg-config to the .pc files in /usr/lib/pkgconfig[1].

PKG_CONFIG_PATH=/usr/lib/pkgconfig \
CPPFLAGS=-I/sw/include \
LDFLAGS=-L/sw/lib ../wine-git/configure

I’m directed by configure to `make depend && make`; I purposely leave out a -j2 since 1) it’s a hot day and I don’t want to kill my poor MacBook Pro, and 2) I don’t remember if it works correctly

make depend && make

And finally, test it works

./wine notepad.exe

Unfortunately, I get the message that “Wine cannot find the FreeType font library. To enable Wine to use TrueType fonts please install a version of FreeType greater than or equal to 2.0.5.” Let’s point dyld to our X11 libs (where FreeType lives), and try again

DYLD_FALLBACK_LIBRARY_PATH=/usr/X11/lib \
./wine notepad.exe

Success!

[1] It seems that Wine’s autoconf script takes the value returned from pkg-config, if pkg-config exists, without trying the alternative (values from xslt-config and xml2-config, in this case), even if pkg-config returns an empty string. I might get around to submitting a patch.

Computers, General, OS X ,

Upgrading a RAID-1 array…in only a week

June 8th, 2008

750GB hard disks have been at the $/GB sweet spot for a while now, and now that they’ve hit $100, I decided to upgrade my home directory RAID-1 from 250GB to 750GB. I really dread these upgrades, as there’s always a chance you can really screw things up. So, for when I upgrade to 2TB or whatever in two years, I wrote up some notes.

In my configuration, sdb1 and sdc1 are the partitions currently part of my RAID-1 md0. sdd is one of the 750GB disks. I’m adding one 750GB disk at a time, because 1) I want at least two copies of my data to be available at all times and 2) I only have one free drive bay and don’t want disks dangling next to the machine for hours.

  1. Change the number of active devices in the array from two to three. This will cause any newly added drive to become active (i.e. actually write the array’s data onto the new drive)

    mdadm -G /dev/md0 -n 3

  2. A little burn-in testing for the new disk

    badblocks -svw -t random -p 2 /dev/sdd

  3. Partition, not forgetting to set the partition type to 0xfd, Linux raid autodetect
  4. Add the new drive as a spare to the existing array

    mdadm /dev/md0 --add /dev/sdd1

  5. Once recovery is done (check `mdadm -D /dev/md0`), fail and remove one of the old disks from the array

    mdadm /dev/md0 -f /dev/sdc1 -r /dev/sdc1

  6. Shred the removed drive

    shred -v -n 2 -z /dev/sdc

  7. (Physically) swap out the removed drive and replace it with the second new one
  8. Repeat steps 2-5 above for the second new disk. Hold off on the shredding, as this is going to be our backup
  9. Reset the number of active devices in the array to two

    mdadm -G /dev/md0 -n 2

  10. Grow the array

    sudo mdadm -G /dev/md0 --size=max

  11. Let it resync, then unmount and resize the filesystem

    umount /home
    resize_reiserfs /dev/md0
    mount /home

  12. Finally, if everything seems okay, shred that second old disk

    shred -v -n 2 -z /dev/sdb

…and we’re done! The one annoying thing is that with testing and a couple of resyncs, you end up with loads of down time between really short and simple tasks. So it’s possible (and I speak from experience) to stretch this weekend project out over a whole week.

Computers, General, Linux , ,

OpenID-enabled two-factor authentication on the cheap

May 11th, 2008

I ran across this nine-month old post at cavemonkey50.com and I’m kind of left wondering where I was when this idea made its round on the blogs. Basically, PayPal will sell you a SecurID-like fob that can be OpenID-enabled using VeriSign as the OpenID provider (eh, VeriSign…sketchy? maybe.) The two key observations:

While PayPal is providing the Security Key, the key is actually a VeriSign Identity Protection (VIP) device … VeriSign is actually an OpenID provider and allows you to link your Security Key to your OpenID.

So give PayPal $5, get one of these SecurID-like devices in the mail 10 days later, link it to VeriSign’s OpenID provider, and boom you get two-factor OpenID authentication. Assuming your email, blog, photo sharing site, etc are hooked into OpenID, you have a little less to worry about when you’re on the road using some random internet cafe terminal.

Computers, General

Learning Mandarin Chinese with Mac OS X

April 19th, 2008

I use a Mac probably 90% of the time, so I wanted to share some tips for OS X I picked up that (I hope) are really helpful to the Mandarin Chinese learner.

As a bit of background, let me tell you where I’m coming from: I went to Chinese school for years as a kid and didn’t really learn much of anything. I was never fluent, never really learned enough characters to sufficiently read (let alone write), and then I just stopped caring for some amount of time. Now, I’m back for more learning.

So, here are the tips:

  • ITABC Input Method

    I haven’t really used Windows in years, but last time I tried, I don’t think it had the pervasive Unicode support to even display Chinese characters in most apps. That said, I was nicely surprised when I found OS X 10.5 comes with a slew of Traditional and Simplified Chinese Input Methods built in. The one I use, ITABC, is dead simple. You just enter pinyin without tones and choose from candidate matches. There are plenty of places online (here’s one at Yale) that can walk you through setting it up.

  • CEDICT for Apple Dictionary

    Apple includes a dictionary application in OS X. No big deal, right? Well, it’s actually pretty cool, because you can add your own custom dictionaries that integrate as seamlessly as the built-in dictionaries. CEDICT is a Chinese-English dictionary project (here’s an online dictionary based on CEDICT) that’s available as a user dictionary for Dictionary.app. Even better, it also has pronunciations (little sound bites you can play) embedded in dictionary entries.

    Here’s CEDICT for Apple Dictionary at Apple Downloads. Just download it and drop it into your /Library/Dictionaries (or ~/Library/Dictionaries).

  • Dictionary.app integration throughout OS X

    I mentioned seamless integration in that last bullet point. Well, in the Apple way, the dictionary is integrated throughout the system. Hover over some text, hit a hotkey (defaults to Cmd-Ctrl-D, but might I suggest F1), and a little panel pop up (inline, in your application) with the definition.

    This hint at Mac OS X Hints reminds us that we can hold down the dictionary hotkey to continuously get the definition of whatever word is currently under the cursor. Say you’re scanning news.google.cn and there are a handful of words you don’t know. Just hit that hotkey, the dictionary entry panel pops up in Safari, and it moves with you as you move the cursor across the sentence.

  • If the default popup panel is too small for your tastes, this post has a link to a modified DictionaryPanel.app (drop it in /Applications/Dictionary.app/Contents/SharedSupport) that enlarges the popup panel window. Alternatively, you can open up DictionaryPanel.app/Contents/Resources/English.lproj/PopupWindow.nib in Interface Builder and just need to change the size of both the popup window and its content. Be sure to make a backup first!

  • ChinesePod on iTunes

    Alright, so this last one might be a strech, but I found out about ChinesePod, which is a podcast with lessons in spoken Mandarin. It helps that the podcasters are pretty amusing. How does this tie in? Well, iTunes is setup to scrape the newest lessons and syncs them automatically with my iPod, so I can listen on my way to work. Zero effort necessary!

Alright. That’s it for now. If you know of any other tips, please do share!

Note: This might seem like one big rave for OS X, but I tried really hard to keep that to a minimum. Apple’s just too cool :)

Computers, General, OS X ,

Stressing disks in OS X for burn-in

March 19th, 2008

Sounds simple, you’d think doing drive burn-in for reliability is something people do everyday on Macs, but either my Google-foo is off or there’s just not an easy way to stress test disks. A drive just died from under two weeks use (note to self: don’t buy Iomega), so I’m forcing myself to put the replacement I received this morning through its paces before committing any data to it.

This external drive, for reasons of compatibility and account restrictions, needs to eventually be formatted on my Mac to ext2, using ext2fsx (another post on the bugginess of ext2fsx later). Below is a list of ways I ran across to stress the disk.

Ideas for stressing a disk on OS X:

  1. format the disk with “secure erase” to write dummy data to the entire disk
  2. just format the disk ext2/fsck it; the inode placement should give good coverage of the disk without taking SO LONG*
  3. run `e2fsck` (fsck_ext2) with the -c -c option which invokes badblocks to read/write each block to find and track bad blocks.

I started with the first, but realized badblocks is probably a better tool for the job (is there a native BSD equivalent?) save for the fact that you don’t get much seeking going on. The second one might address that, or maybe reading the disk’s block device while doing something else might induce the contention to give you the necessary seeking.

*A side gripe: since disk capacities (I have a 500GB external drive) have been growing faster than disk bandwidth (perhaps my fault for using 480Mbps USB2), reading or writing an entire drive takes on the order of HOURS (over two hours twenty minutes best case for my setup, and easily twice that from my experience today). It just never really affected me until now, and I’m kind of annoyed.

Computers, General, OS X

FreeBSD 7.0 worth it just for ZFS?

March 14th, 2008

I’m a diehard OS X user, but keep around a desktop for nightly jobs and file storage. I’m rather unlucky with disk drives (killed one just yesterday), so I’ve been meaning to move to ZFS. FUSE on Linux doesn’t feel too trustworthy right now (right, I’ll trust drivers not in the mainline kernel), and having finally gotten used to BSDisms, I’m not sure starting fresh with Solaris is the right path.

Long story short, I decided to try FreeBSD 7.0 (ZFS built in!). The last time I used FreeBSD was to shape traffic in a network testbed. This time, I’m looking for dead-simple usability. I want my WinPrinter to work plug and play, X to start outta the box in high res, and all that jazz.

First step, downloading the cd images and making a dvd image from that.

More later…

Computers, General ,

Dear God, why do we use fully qualified domain names so often?

October 30th, 2007

I login daily to servers with names like xx.xxxxxxxxxx.berkeley.edu* or xxxxxx.xxxx.berkeley.edu, and it annoys me to no end that in 2007, there’s no standard mechanism for personal namespaces. I want shorthands like q and r6 that allow me to name this small set of machines from whatever terminal I may be using.

Alas, here’s how I solved it:

I have a relatively short domain name (tkho.net), and my dirt cheap webhost (NearlyFreeSpeech.NET) lets me create virtually unlimited CNAME records, allowing me to creating mappings from x.tkho.net, xx.tkho.net, etc to the names of servers that I frequently use. I add tkho.net. to the list of search domains that my DNS resolver checks (if it can’t find the record q., it’ll try q.tkho.net.), and now, `ssh tkho@q` works perfectly, across all my machines, and `ssh tkho@q.tkho.net` when I’m not on my machine.

* names removed to protect the innocent.

Computers, General

Calling conventions

August 2nd, 2007

The Intel x86 Function-call Conventions - Assembly View page has saved my ass a countless number of times. Thank you, Steve Friedl.

Computers, General, Software Development

Automating library book renewals

March 19th, 2007

I probably should be grateful that Berkeley lets you telnet into a machine and renew your library books. Unfortunately, I couldn’t stand to waste 45 seconds every two weeks doing this manually, so I instead spent 20 minutes writing a small script [txt] that renews books checked out from the UC Berkeley library. It’s easy to use: just plugin your CalNet ID and pin (birthday) and you’re all set. It probably needs a recent Python with the pexpect library.

In about a year, I’ll have saved time on this endeavor.

Computers, General, Software Development

duplicity with Amazon S3

January 25th, 2007

Goal: I want cheap backups

Reality: Online storage generally isn’t cheap

That is, until Amazon’s S3 came onto the scene last year. I’d heard of duplicity and knew it had backend support for S3, so I figured that it couldn’t be too hard to setup. Unfortunately, I couldn’t find a place online that ties everything together, so I’ll try to do that here.

Background: Amazon’s S3 (Simple Storage Service) is cheap, available storage. How cheap? $0.15 each GB-month, and $0.20/GB transfer. duplicity gives you “encrypted, bandwidth-efficient backup using the rsync algorithm.” Well, good enough for me. Let’s start.

On my Ubuntu Linux 6.10 (Edgy Eft) machine, I first had to get librsync-dev:

sudo apt-get install librsync-dev

Then, I got duplicity-cvs and installed it:

cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.org:/sources/duplicity \
co duplicity

cd duplicity
dist/makedist 0.4.3
tar xzf duplicity-0.4.3.tar.gz
cd duplicity-0.4.3
python setup.py install ??prefix=/home/tkho

If you install into your home folder, make sure to set the PYTHONPATH:

export PYTHONPATH=/home/tkho/lib/python2.4/site-packages

For duplicity to use the S3 backend, you need the BitBucket library. Once downloaded, install it:

tar xzf BitBucket-0.4a.tar.gz
cd BitBucket-0.4a
python setup.py install ??prefix=/home/tkho

Now, everything is installed so we can start a sync. On a side note, it took about half an hour for my S3 account to start working.

export PASSPHRASE=password
export S3KEY=your_s3key
export S3SECRET=your_s3secret
duplicity /home/tkho/sync s3+http://duplicity_sync

That’s it! Add that to a daily or weekly cron and you have cheap, off-site backups. And, since you’re using duplicity, you get snapshots for free!

Lastly, don’t forget to grab Jets3t Cockpit–it’s a GUI file browser for your S3 data.

Computers, General, Linux, The Pursuit of Happiness ,

GAH Annotated Hex Viewer

November 11th, 2006

I promised a former coworker, Dan Hipschman, that I’d advertise his GAH Annotated Hex Viewer to my expansive audience. GAH lets you annotate binary data, like Wireshark’s packet prettifier on acid. Plus, you know it’s good because it’s got the requisite recursive acronym.

He’s still out there making the world a better place for millions of hackers. Here’s part of an email I got from him the other day:

Anyway, you know how you were always complaining about diff generating hard to read patches because the lines get intermingled? I’m working on that problem now, so if you have any really horrible looking patch files you think should look better in the next version of diff (assuming my work gets in), feel free to send them to me so I can be sure to cover those cases.

Computers, General, Software Development

Stacked GIT

June 18th, 2006

I spent part of Friday moving into the 21st century and learning my way around GIT. Not long after, I found out about Stacked GIT, which makes it an order of magnitude faster and easier to use and maintain code over CVS. It keeps a series of interdependent changesets organized a stack–you push and pop to switch the active changeset you’re working on, and pushing clues you in to any necessary conflict resolution. How cool is that?!

Computers, General, Linux, Software Development

offlineimap

May 28th, 2006

Since I abandoned Fastmail for Gmail’s intuitive keyboard shortcuts and conversation views a couple of months ago, I’ve been putting off the task of backing up the old account. I ran across offlineimap today, which has simple configuration and seems to be doing a good job of syncing about 500mb of email.

Update 12/9/2006: I found an even better way to get IMAP backups with the aptly named imapbackup.py script.

Computers, General, Linux

ptrace(2)

May 24th, 2006

I was trying out the sample ptrace‘ing code from this article [Playing with ptrace, Part II] today and ended up wasting a bunch of time trying to figure out why the int80, int3 code injection example would fail with strace showing an EIO error. Then it hit me that I was trying to write over the sleep library function…great…

Computers, General, Linux, Software Development

FTP with TLS/SSL client on Linux

April 28th, 2006

I’ve run into this before–my school’s web space is only accessible via FTP with TLS/SSL, and the problem is that I don’t know of (and I can’t find) a Linux client that lets me do that. I wasted about 5 minutes trying to find something I could apt-get, but ended up downloading FileZilla and running it in Wine (I also tried three versions of CuteFTP, all of which failed to run properly).

Update 12/11/2006: See if this works.

General, Linux

Google Calendar

April 16th, 2006

The last time I tried to use Google Calendar, I couldn’t successfully import my Apple iCal calendars; all the events would end up time shifted 8 hours. I finally found some time to try again this afternoon, and the import works flawlessly. Goodbye Apple iCal!

Now that I have all my calendars imported (also did some cleaning–I have just six calendars now), I’m thoroughly impressed. I’m always in month or week view, and both are on par with Apple iCal in terms of look and usability. I’d almost miss iCal’s todo list, were it not the fact that I label all emails from myself starting with “todo:” in GMail.

On the other hand, I have one more reason to regret buying a Mac. It’s really just turned into an iTunes jukebox and a recharger for my iPod.

Computers, General

QEMU and the network bridge

February 18th, 2006

QEMU’s user networking won’t do UDP out of the box, so I poked around online for a solution. What’s out on the web is a hodge-podge of tutorials, all of them different, and most of them for a non-current (read: not QEMU 0.8.0) release. This is a (equally poor) guide to get bridged networking working. FYI, my distro du jour is Ubuntu 5.10, and I hope to revise these instructions should the need arise to re-configure my setup.

First, check out How to install QEmu on Ubuntu Linux (Breezy) for some aptly named instructions.

From the tun/tap on ubuntu thread on Ubuntu Forums (probably not necessary?):

# apt-get install uml-utilities
# tunctl

From qemu ‘networking howto’:

# ifconfig eth0 down
# brctl addbr br0
# ifconfig eth0 0.0.0.0 promisc up
# ifconfig tun0 0.0.0.0 promisc up
# ifconfig br0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 up
# brctl stp br0 off
# brctl setfd br0 1
# brctl sethello br0 1
# brctl addif br0 eth0
# brctl addif br0 tun0
# route add default gw 192.168.1.1

From djw’s qemu network bridge page, modify your /etc/qemu-ifup to something like:

#!/bin/sh echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2

Finally, what they never tell you is how to start up QEMU. Little did I know that when you connect TAP to a VLAN, it doesn’t create the NIC for you. I wasted about a hour until I realized you need to append another `-net nic`. Here’s how I start QEMU:

qemu debian.img -kernel bzImage-2.6.14 -append "root=/dev/hda1" -net tap -net nic

Voila, mon ami. C’est tout!

Update: You’ll want to chmod 666 /dev/net/tun, and make sure you have the bridge-utils package.

Update 2: I have kernel config files for Linux 2.4.20, 2.6.11 (found these first two online), and 2.6.14. These build decently small kernels without modules that boot up in QEMU.

Computers, General, Linux ,

SCALE 4X

February 12th, 2006

After a couple years of putting it off, I can finally say I’ve gone to the Southern California Linux Expo (SCALE). I spent this weekened listening to a handful of really interesting speakers. Here were my highlights:

  • Zend’s Andi Gutmans talked about PHP 5 and the future of PHP. I haven’t done significant PHP work since 4 was released, so I found a lot of the new stuff pretty amazing. I was espeically impressed by a 2-line example of accessing the Google API via SOAP. TWO LINES.
  • David Schachter from Sleepycat (the makers of Berkeley DB) talked about how pervasive Berekley DB is in Linux systems. One thing I definitely walked away with was that a lot of people (myself previously included) myopically think relational databases are the only kind of databases around. Obviously, they’re not. I wish this was ingrained in me a couple years back.
  • Adam Leventhal, a Solaris kernel guy, talked about using DTrace to find hotspots in Linux apps. DTrace is purely a Solaris thing, but by running your Linux app in Solaris’ Linux sandbox, you get most of the interesting metrics.

And of course, Dan Kegel and Chris Dibona had interesting things to say.

Computers, General, Linux

RSI

February 12th, 2006

When I used OS X full time, I found a nifty little tool named AntiRSI. True to its name, it prevents you from working too long on the computer by eclipsing your screen and forcing you to take a break.

Fast forward about a year, and today I found out about Workrave. It reminds you to take breaks just like AntiRSI, but improves on the idea by giving suggestions of stretches. Even better, all it took was an `apt-get install workrave`:)

Postscript: Also saw this short article: Alleviate RSI the Hacker Way

Computers, General, Linux