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?

Friday, March 27, 2009

SafariStand downloads and the Terminal

I love SafariStand. I love SafariStand's ability to organize downloads by date. I hate trying to navigate to the current day's download directory via the terminal. I typically don't delete downloads very often so my Downloads folder tends to get cluttered with a bunch of folders titled '2009-03-11', '2009-03-15', etc.

If you're a heavy terminal user, it can be a pain to get into the current day's folder because tab-completion always stops at '2009-03-' if your folder spans just one month, '2009-' if it spans multiple months, or '200' if it spans multiple years.

I decided to rectify this situation by making an alias to the date command to generate the current date in the same format. It's pretty simple:

In your .profile or .bash_profile file in your home directory simply add the line:

alias today='date "+%Y-%m-%d"'

Then when you're in the terminal, go to your downloads folder and type

cd `today` (note the back quotes around today) (the back quote is shift-tilde)

and it will automatically generate the proper date string and take you right into your folder.

Friday, December 5, 2008

Quickly Adding SSH Keys

Here's a quick way to create and add ssh keys to a server:

  1. Generate your ssh key on your client machine:
    ssh-keygen -t dsa Note: Set a password for your key. (see note)
  2. Secure Copy (scp) the key to your ssh server:
    scp .ssh/id_dsa.pub username@server.com:.ssh/id_dsa.pub
  3. Add the key to your authorized_keys2 file:
    ssh username@server.com 'cat .ssh/id_dsa.pub >> .ssh/authorized_keys2'
  4. Shortcut: Combine steps 2 and 3:
    cat ~/.ssh/id_dsa.pub | ssh username@server.com 'mkdir -p ~/.ssh && cat - >> ~/.ssh/authorized_keys2'

Note on SSH Key Passwords

On step 1, you have the option to add a password to your key. If you don't add a password and someone gets ahold of your private key, they will be able to access any server that you have given that key access to. By setting a password, the user still has to know your key password to use it. Though the purpose of this tutorial is to speed up and secure your login, you will still have to type in that password you set in step 1 every time you log in to an ssh server. This is where SSH Keychain comes into play.

SSH Keychain on the Mac

Leopard has this functionality built into the Keychain, but if you are on 10.4 or older, you can use SSH Keychain on the Mac to manage your SSH passwords. This great little app lets you store your ssh passwords in your computer's Keychain so you're not constantly having to type it in. Download it at http://www.sshkeychain.org/ and add your keys to it.

Why Use SSH Keys Anyways?

When you log into an SSH server , you have to send your password over the network at least once. Any network traffic can be potentially captured and, given a long enough time span, decrypted.

SSH keys work on the principle of Public Key Cryptography, which is beyond the scope of this article. In general it allows the server to verify who you are based on this key trust you just set up. Since your keys are cryptographically strong (usually 1024+ bit), it's much more difficult to hack than a short, memorable password.

Multiple Users

SSH keys also allow you to give multiple users access to a single account on your SSH server by simply adding everyone's keys to the single account.

For more in-depth information on SSH keys, see Authentication by Cryptographic Key by O'REILLY.