OS X Snow Leopard Bugs: Audio gets reset to mute on reboot.

While my upgrade to OS x 10.6 Snow Leopard has been mostly smooth, there are a few annoying bugs I’ve come across. This one has to do with audio – upon reboot, audio gets set to mute no matter what settings I had the volume on before. Not a big problem, but annoying none the less. Here’s how to fix it:

  1. In Finder, navigate to Macintosh HD > Library > Preferences > Audio
  2. Delete the following files:
    •      com.apple.audio.DeviceSettings.plist
    •      com.apple.audio.SystemSettings.plist
  3. Open System Preferences > Sound
  4. Set your sound to your preferred settings
  5. Exit System Preferences and Reboot

There you go! After deleting those files, they will be re-created when you go into System Preferences and your audio will no longer be muted upon reboot.

Windows XP: How to cancel a chkdsk or scandisk scheduled upon reboot

If you have a chkdsk or scandisk scheduled to run on a drive after your next reboot, normally you’d be able to cancel it by pressing any key 10 seconds before the scan starts. Unfortunately, my bluetooth keyboard/mouse combo didn’t seem to work at this stage of bootup, so I was unable to cancel any scan. After some research I found out that the scheduled scan is simply a registry entry and that if you remove it, the scan wouldn’t execute next time you reboot. Here’s how:

  1. Start > Run > regedt32
  2. Navigate to HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager
  3. Open the BootExecute key
  4. Remove the line that says: autocheck autochk /r \??\E: where “E:” is your drive letter
  5. Exit Regedit and reboot, and no scan will execute

Slicehost: Setting up a Tor relay on Fedora to help keep Iran connected #IranElection

As many of you know, most of the information from within Iran is coming from on-the-ground new-media and social networking sites such as Twitter, YouTube, and Facebook. This is happening despite crackdowns on communications networks by the Iranian government. The way this information is able to escape the firewalls of Iran is via proxies which relay and “hide” the destination of the communications so that it becomes difficult to block. This allows those on the ground in Iran to communicate with the world instantly and effectively, without fear of government crackdown. But it is a constant arms race. As soon as a relay becomes known by the Iranian government it gets shut down. The only way to keep the lines of communication open are to strengthen the distributed Tor network by adding more relays and bridges, making it more difficult for the Iranian government to block them all.

There have already been great write-ups on how you can contribute to the distributed proxy network Tor:

Please read over those documents for an overview. I wanted to provide detailed instructions on how to get a Tor network set up quickly, easily, and cheaply for those of you who would like to contribute. You can provide invaluable assistance to the people of Iran for as little as 15 minutes of your time and $20/month.

First off, this document assumes you have some system administration knowledge with Linux (Fedora) and are comfortable installing and configuring packages from the command line. If that’s you, you can have a Tor relay up and running in about 15 minutes.

Shell commands are in purple
Config file settings are in blue

  1. Register at Slicehost

    Slicehost is a VPS provider that allows you to quickly build/deploy webservers very cheaply. Sign up here and purchase the cheapest $20 slice to get started. Pick Fedora 10 as your Linux Distribution. Do not pick Fedora 11, as it is incompatible with the current version of Tor. Once you are registered, Slicehost will email you your IP and root password. It can take a few minutes to build your new slice, so be patient.

  2. Slice Security

    Log in to your new slice. Please note that this document covers the bare minimum of commands to get Tor up and running. You should follow due diligence when it comes to securing your new slice, something which is outside the scope of this document. Common practice security configurations are recommended. Security is your own responsibility, and I will not be held liable for any security issues with your slice. There are a few bare-minimum security things you should do to your slice:

    Change the root password:
        passwd root

    Create your own account & set password:
        adduser yourusername
        passwd yourusername

    Disable root login to ssh
        vim /etc/ssh/sshd_config
        Change to this: PermitRootLogin no
        service sshd restart

    These steps are the BARE MINIMUM you should do to secure your slice.

  3. Update Your System

    yum -y update

  4. Install Prerequisites

    yum install wget vim-enhanced gcc make libevent libevent-devel openssl openssl-devel zlib zlib-devel rpm-build

  5. Download Tor & Signature

    wget https://www.torproject.org/dist/rpm/tor-
    wget https://www.torproject.org/dist/rpm/tor-

  6. Verify Packages

    Follow directions at http://www.torproject.org/verifying-signatures.html.en to verify that you have an authentic RPM and not a fake.

  7. Build & Install Tor

    rpmbuild --rebuild tor-
    rpm -i rpmbuild/RPMS/x86_64/tor-

  8. Configure Tor

    vim /etc/tor/torrc

    Change the following settings, substituting your own values for Nickname and Address:

    DataDirectory /var/lib/tor
    ORPort 9001
    DirPort 9030
    Nickname YOUR_NICKNAME

    Save & Exit

  9. Set Bandwidth Limits for Tor

    These settings are largely dependent on which slice you have purchased. The ones you see below are for a 20GB slice, and they allow 2GB of transfer per day, so you should be well within the 20GB slice limit of 100GB/month. If you have purchased a larger slice, these settings can be increased accordingly. Be careful here, incorrect settings can push you over your monthly bandwidth limit very quickly! I did over 12GB of transfer in a little over 8 hours before limiting bandwidth with these settings.

    vim /etc/tor/torrc

    RelayBandwidthRate 64 KBytes
    RelayBandwidthBurst 128 KBytes
    AccountingStart day 12:00
    AccountingMax 2 GB

    Save & Exit. The AccountingStart and AccountingMax settings will limit 2GB max transfer per day, resetting at 12:00 every day. The RelayBandwidthRate and RelayBandwidthBurst settings throttle the bandwidth so that you don’t reach AccountingMax after only a few hours. Normally AccountingStart and AccountingMax would be enough to stay within your bandwidth limits, but I want my relay to be available all day rather than reaching AccountingMax and shutting down after a few hours.

  10. Configure Your Firewall

    iptables-save > /etc/sysconfig/iptables.default
    iptables-save > /etc/sysconfig/iptables.test
    vim /etc/sysconfig/iptables.test

    Insert the following settings:

    # tor ORPort & DirPort
    -A INPUT -p tcp –dport 9001 -j ACCEPT
    -A INPUT -p tcp –dport 9030 -j ACCEPT

    # tor Allow all outbound traffic

    Save & Exit.

    iptables-restore < /etc/sysconfig/iptables.test iptables -L
    (verify the rules are correct)
    iptables-save > /etc/sysconfig/iptables

  11. Increase the number of open file descriptors

    vim /etc/security/limits.conf

    Add this line:

    _tor hard nofile 32768

    Save & Exit

  12. Start up the Tor Service

    service tor start

  13. If everything starts correctly, you should see output like this:
    Starting tor: Jun 21 15:44:04.219 [notice] Tor v0.2.1.15-rc. This is experimental software. Do not rely on it for strong anonymity. (Running on Linux x86_64)
    Jun 21 15:44:04.219 [notice] Your ContactInfo config option is not set. Please consider setting it, so we can contact you if your server is misconfigured or something else goes wrong.
    Jun 21 15:44:04.223 [notice] Initialized libevent version 1.4.5-stable using method epoll. Good.
    Jun 21 15:44:04.223 [notice] Opening OR listener on
    Jun 21 15:44:04.223 [notice] Opening Directory listener on
    Jun 21 15:44:04.223 [notice] Opening Socks listener on
    /usr/bin/torctl start: tor started [ OK ]

    Also, you should view the tor.log and verify that you see the following (after 20-minutes):

    cat /var/log/tor/tor.log

    Jun 21 15:44:13.835 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
    Jun 21 15:44:13.835 [notice] Bootstrapped 100%: Done.
    Jun 21 15:44:13.835 [notice] Now checking whether ORPort XXX.XXX.XXX.XXX:9001 and DirPort XXX.XXX.XXX.XXX:9030 are reachable.. (this may take up to 20 minutes -- look for log messages indicating success)
    Jun 21 15:44:18.492 [notice] Self-testing indicates your DirPort is reachable from the outside. Excellent.
    Jun 21 15:44:18.492 [notice] Not advertising DirPort (Reason: AccountingMax enabled)
    Jun 21 15:44:26.804 [notice] Self-testing indicates your ORPort is reachable from the outside. Excellent. Publishing server descriptor.
    Jun 21 15:44:43.813 [notice] Performing bandwidth self-test.. done.

    If you see some errors or it doesn’t start correctly, post in the comments and I’ll see if I can help you out. Here are some references to help you get it going:

That’s it! You now have a fully functioning Tor Relay and are helping the Iranian people get news and information out to the rest of the world. The cool thing about Slicehost is that you can easily upgrade your Slice with the click of a button to allow more bandwidth, RAM, and other resources. They also have a Clone option so that once you have your initial Tor slice running, you can clone it multiple times so that you can have multiple Tor servers at a time.

More good reads on Tor and its effect in Iran:

Update 1 – Preventing Abuse by BitTorrent Users

A couple of days after setting up my Tor slice, I received a Digital Millennium Copyright Act (“DMCA”) notice that my relay was hosting copyrighted material and that I would be required to remove it or face having my Slice shut down. Turns out that there are people out there using BitTorrent over the Tor network to transfer copyrighted material. Philosophical debates about BitTorrent and copyright law aside, the whole reason why I am running Tor is to help those in Iran stay connected — not to assist in the distribution of copyrighted material. So, after a few minutes of research, I found out we can prevent Tor being used by BitTorrent by adjusting your ExitPolicy:

vim /etc/tor/torrc

Add the following:
ExitPolicy reject *:1214
ExitPolicy reject *:4661-4666
ExitPolicy reject *:6346-6429
ExitPolicy reject *:6881-6999

Save & Exit
Restart Tor: service tor restart

You should also probably follow the advice at http://blog.torproject.org/blog/tips-running-exit-node-minimal-harassment

http://www.torproject.org/faq.html.en#ExitPolicies – Exit Policies in Tor
https://www.torproject.org/eff/tor-dmca-response.html – DCMA Response Template
http://www.orient-lodge.com/node/3622?dsq=11687593 – A Slicehost user who also received a DCMA notice
http://www.chrisbrunner.com/?p=119 – Why You Shouldn’t Run BitTorrent Over Tor

Update 2 – Slicehost Responds

After making the adjustments above, I notified Slicehost of my changes and they have responded:
Thank you for your response. We will go ahead and consider this matter resolved. Thank you for your attention to this matter.
Gotta give them credit for understanding that we’re trying to help people in Iran — not to pirate movies. Thanks Slicehost!

Update 3 – Upgraded to & Config Adjustments

I received some configuration recommendations from Andrew Lewman of The Tor Project, and have updated the steps above accordingly.

Dojo: How to get the ID of an element.

To get the ID of an element using Dojo Framework, you need to use the dojo.attr function.

Given the following HTML:

<img src="/path/to/imageA.jpg" id="myImage1" />
<img src="/path/to/imageB.jpg" id="myImage2" />
<img src="/path/to/imageC.jpg" id="myImage3" />

You can get the IDs of each image in Dojo like so:

dojo.query("img").forEach(function(currentNode) {
    var theElementId = dojo.attr(currentNode, "id");
    console.log("id: ", theElementId); // debug

If you have debugging on and something like Firebug, the console output would be like so:

id: myImage1
id: myImage2
id: myImage3

iPhone Wishlist – Form Input

Added to my list of iPhone annoyances that I hope are someday fixed:

When entering text into a form input, the first letter defaults to uppercase. This is fine for textboxes and most other inputs, but it is annoying for username/password inputs because more often than not these fields are case-sensitive. Perhaps the iPhone could be more intelligent with the auto-caps by disabling it when you’re on a text input named “username” or “login.”

CSS: Removing extra space underneath an image.

If you’ve ever tried to wrap an image in a div, you’ve surely came across the layout issue where an extra couple pixels of blank space are inserted underneath the image. Trying to get rid of this extra space has caused me to pull my hair out many times, but the fix is rather easy. All it takes is a basic understanding of the type of element that images are, and how they interact with the layout around them. First, some sample code:

<div style="border: 1px solid #000;">
    <img src="someimage.jpg" width="270" height="184" alt="yo" />

This will result in something like this:


Notice the 3 pixels of whitespace underneath the image. The reason this happens is because images are by default inline elements. Inline elements of course do not force new lines and act like text flowing along a line. The most well-known inline element is of course plain text — such as this very paragraph that you are reading now. The fonts that make up text have attributes named descenders, which are basically the part of a font that extends below the baseline on characters such as y, g, and j. Even though images aren’t like fonts and don’t have descenders, when your browser is rendering an image it treats it as an inline element and adds some space under the baseline to compensate for descenders. The easiest way to get rid of the space underneath an image is to convert it to a block element so that the browser doesn’t add extra room for descenders like so:

<div style="border: 1px solid #000;">
    <img src="someimage.jpg" width="270" height="184" alt="yo" style="display: block;" />

If for some reason you’re unable to convert your image to block mode, another way to fix it is to hard-code the height of the wrapper div to match the height of the image like so:

<div style="border: 1px solid #000; height: 184px;">
    <img src="someimage.jpg" width="270" height="184" alt="yo" />

Either of these methods will tightly and correctly wrap your image without the descender space below it like so: