Thursday, November 29, 2012

One Liners

Time an HTTP request:

curl -w "%{time_total}\n" -o /dev/null -s {URL}

for a HEAD request:

-I


Tuesday, November 1, 2011

Siri on the Bus

I have a fairly long bus ride to work, it typically takes around an hour. Sometimes I like to sleep on the bus, but I'm always scared of missing my stop. With the introduction of iOS 5, Apple added location-based reminders that can be activated with Siri, or manually if you're on an iPhone 4. Location-based reminders don't work on the iPhone 3GS.

My solution is to create a contact just before my bus stop and set a reminder to alert me when I've reached that spot. It's a 2-step process, but it's fairly easy:

Step 1: Create a contact a mile or so before your stop

  1. Open the Maps app and drop a pin by touching and holding in one spot until the pin drops.
  2. Touch the right arrow and select "Add to Contacts"
  3. Name your new contact something easy. I called mine "Mills and 50"


Step 2: Tell Siri to wake you up

When you get on the bus, simply tell Siri to wake you up when you reach your contact. I just have to say "Remind me to wake up when I reach Mills and 50". If you're on an iPhone 4, just open the Reminders app and add a reminder manually.


That's it! Get some rest without worrying about missing your stop!



Friday, October 21, 2011

Use Siri to Update Facebook and Twitter

I got my iPhone 4S on launch day and I absolutely love Siri! Unfortunately there is no Twitter or Facebook integration for Siri out of the box. There are some fairly straight forward workarounds, though.

Facebook
To update your Facebook status:
  1. Create a new contact in your address book and name it something other than "Facebook". "Facebook" is a reserved word and Siri will tell you it can't interact with it. I named mine "Face".
  2. Find your Facebook email address on the Facebook Mobile site and set that as the email address.
  3. Now you can just email status updates to Facebook using Siri. Facebook uses the Subject line as the status update.



Twitter
Twitter doesn't have native email updating capability so, instead, use SMS to send Twitter updates:
  1. Link your phone to Twitter on the Devices page.
  2. Create a new contact in your address book and name it something other than "Twitter" or "Tweet". These are both reserved words for Siri. I named mine "Toot"
  3. Set the phone number to 40404.
  4. Send a text message to your contact.

Wednesday, October 19, 2011

Python, Virtual Environments, and cx_Oracle on Lion

As of this writing, the 64-bit Oracle Instant Client segfaults under Lion. There is a fairly lengthy discussion thread on the Oracle support forums and the only solution currently is to use the 32-bit version.

While the problem is fairly easy to overcome if you use the system python, it presents a problem when using virtual environments. For the system Python, simply install the 32-bit Instant Client and tell the system to use the 32-bit python install:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

or

export VERSIONER_PYTHON_PREFER_32_BIT=yes

Python in a virtual environment, on the other hand, bypasses the Prefer-32-bit flag and will always run in 64-bit mode. As suggested by Ned Deily on StackOverflow, you can remove the 64-bit binary from the virtual environment python to force it to use 32-bit.

To remove the 64-bit binary, use lipo:

$ which python
/path/to/virtualenv/bin/python
$ file /path/to/virtualenv/bin/python
python: Mach-O universal binary with 2 architectures
python (for architecture x86_64): Mach-O 64-bit executable x86_64
python (for architecture i386): Mach-O executable i386
$ cp /path/to/virtualenv/bin/python /path/to/virtualenv/bin/python-universal
$ lipo /path/to/virtualenv/bin/python-universal -thin i386 -output /path/to/virtualenv/bin/python
$ file /path/to/virtualenv/bin/python
/path/to/virtualenv/bin/python: Mach-O executable i386

If you take this approach, you will probably need to reinstall any python libraries like mysql-python with their 32-bit versions. To install mysql-python 32-bit, make sure you are running the 32-bit MySQL server.

Good luck!

Thursday, April 2, 2009

Finding text in files from the Command-Line

This tip is posted everywhere, but for my love of copying and pasting, here's how to find any text in a directory of files quickly from the command line:

find . -name "*.php" -print | xargs grep "text_to_find"

To break this down:

find . -name "*.php" -print finds all files in the current or sub-directories that has the filename *.php and print out the file name

| This is the pipe. It sends the output of the above find command to the next command:

xargs takes the input from the find command and passes those files to the next command:

grep "text_to_find" searches in each of the files for the text "text_to_find"

Tuesday, March 31, 2009

Kensington Slimblade

Trackballs seem to be a sensitive subject when it comes to computer users. When I mention to people that I use trackballs regularly, I typically get a face of disgust. The usual excuses are: "I can play games 10 times faster with my regular mouse!" or "Trackballs are so awkward!"

For me, I've never found a mouse that gives me the level of control when working in Photoshop or doing any precision work as I have with my trackball. But I don't use just any trackball. Most trackballs have a tiny ball that you maneuver with your thumb, which is totally awkward for me. The rest have a tiny center-mounted ball that's just not large enough to really get any precise control out of.

My trackball of choice is the Kensington series with the large center-mounted ball. Over the years I've owned the Turbo Mouse, Expert Mouse, and as of recently, their new Slimblade.

I was selected to be part of their Slimblade testing program so they sent me one to review and I absolutely love the design of this thing! It's low profile, feels very well-built, and the color scheme is gorgeous.

They've moved the mouse lasers to the side walls so dust doesn't build up inside of it, and they made the ball bearings even smoother than the Expert Mouse.

Scrolling About.

One of the greatest features of the Expert Mouse was the scroll wheel. It was an incredibly intuitive and elegant solution for the lack of scrolling on the Turbo Mouse. The Slimblade took a different approach. They decided to remove the scroll wheel and let you just spin the ball to scroll. I was very skeptical about spinning the ball causing the cursor to move a lot, but it's actually pretty stable during scrolling. It does take some getting used to compared to the scroll wheel, but after a few days it felt very natural. The mouse cursor does move around slightly when scrolling, but overall it's pretty stable.

Ergonomics.

I waited to write this part because I wanted a longer experience with the mouse. At first it was very uncomfortable. The way my hand sat on the Expert Mouse was tilted slightly to the right. When I did that on the Slimblade, since my hand is sitting on the desk instead of the cushion, that hits a pressure point in my hand and it kinda hurt. I seem to have either adjusted my grip or it went away because I don't notice that anymore. I think they really should've shipped this with a wrist rest to help with this problem.

The Software.

One of the things I've always liked about the Kensington trackball series has been the quality of driver software. The previous versions were infinitely customizable, being able to make any button do anything you want. You could even assign multi-click actions so hitting the left and right buttons simultaneously would trigger an event.

The Slimblade has, unfortunately, strayed from this path. In fact the only way you even know the software is installed is a menubar icon. The buttons are all preset functionality: Left-Click, Right-Click, View Mode, and Media Mode. In the two weeks or so that I've been using this mouse, I really haven't found myself using either View or Media Mode.

Media Mode (upper left button) lets you control iTunes. If you use iTunes and don't already use hotkey apps like SizzlingKeys or Synergy, this is nice. I listen to Pandora much more than iTunes lately so this button isn't all that useful for me.

View Mode (upper right button) lets you zoom and pan in apps that are supported. For some apps, like Photoshop, this is useful, yet for other apps, like Safari, not so much. This mouse is very sensitive so it's hard to avoid zooming while you're panning around. I don't think this mode adds a lot of value and I would really like to be able to change the behavior of this button.

Overall, there is almost no customizability in the software and the customization options you are given require editing a text file. Not cool, Kensington. Not cool.

Final Thoughts

If this was my first interaction with Kensington trackballs, I don't think I'd be as much of an enthusiast as I am. The software is severely lacking and the ergonomics really leave something to be desired. If Kensington improves the software and starts shipping this mouse with a wrist rest to match the angle of the mouse, it will be a dream come true, but in it's current form, it feels unfinished.

Monday, March 30, 2009

Python Shell Class Caching

I'm learning Python right now and one of the things that I thought was strange behavior was how, when you first imported a module in the shell, it would essentially be cached for the rest of your shell session. Any changes you made to your class file would not be reloaded until I exited the shell and reopened it.

There is a much simpler way to reload your class file, using the reload() command: reload(module) It would be nice if there were a 'development' mode where it never cached the class files while you were in the shell. Any suggestions?