Tuesday, January 18, 2011

muscling through a minor migraine while staring at a monitor

i woke up with a a headache this morning. what a way to start the day, eh? and it didn't let up when i finally arrived at the office, as late as i already was. what's worse is that any sort of light in my eyes made my head pound more. now, i can't afford to take the day off of work, or even just an extended morning break, i've got deadlines to meet.

here's how i muscled through that mildly malicious migraine:

step 1: treat the damn thing

everything you learned on how to treat a hangover is fair game here. this morning's recipe for success:
  • two tabs of tylenol (your preferred headache medicine will do)
  • get something to eat, the fattier the better (all i had was a bit of pound cake, but that's better than an empty stomach)
  • hydrate hydrate hydrate, and when you're done with that, hydrate some more
  • if you drink coffee, by all means chug that coffee!! you can kick that caffeine habit some other day

step 2: take it easy while still being productive

with a headache even thinking hurts, which is a problem if your job relies on brain activity. in my line of work, even the most menial of coding task takes some brain power. the solution: don't think. while you wait for the drugs-food-water-coffee concoction to kick in, do your busy-work tasks. answer some emails. fire off that email to HR that they've been houding you about. make some notes in your pivotal tracker issues. or hell, just catch up on some lifehacker posts. =]

step 3: turn down the lights

i don't know about you, but when that headache kicks in i just can't stand bright light. i'm lucky that the fluorescent tubes in my section of the office have been out for the past two weeks. i still have a big bright iMac monitor i have to stare into, though, and it seems like every application and every web page insists on having a bright white background color. never to fear, there's ways to tame it the beast:

  • start with your desktop background. you can go the quick-and-dirty route with simple all back, or go with any dark wallpaper of your choosing (my personal favorite is the cli cheat-sheet useful wallpaper).
  • any text editor worth its salt will let you change the font and background color scheme. Some MacOSX favorites: in Xcode head over to Preferences : Fonts and Colors, and go with the Midnight theme

    In TextMate try out the Twilight theme (no sparkly vampires here, sorry ladies). While you're at it, try out the Homebrew theme in Terminal
  • try out arc90's Readability bookmarklet with the Inverse style to tame website's colors, not to mention make pages more, well, readable with no more cruft and clutter around a page's actual content
  • if all else fails, invert your screen's colors. this option is usually buried in your computer's accessibility setting, sometimes called "high contrast" mode. If you're on a Mac you can go into inverted color mode with a ctrl-opt-command 8

Tuesday, January 11, 2011

how Dropbox saved my command line - extended

i came across a clever blog post on the 'tubes. it described how one could harness the file-syncing powers of Dropbox to keep one's bash shell config files all lined up across several machines. this was just the ticket to keep my mac laptop, my work imac, and my linux box command lines all in harmony with each other.


of course, i couldn't just leave well enough enough alone.


MacOSX hostname discrepancies

the first problem i ran into was reliably getting a machine's hostname on the MacOSX side. the network at the office insists on setting my imacs's hostname dynamically, and it's never the same between bootups. luckily i stumbled on a command that'll get the local hostname of a MacOSX computer:


Listing 1: getting the local hostname in MacOSX:

$ scutil --get LocalHostName


this will spit out whatever name you have set in System Preferences -> Sharing -> Computer Name, regardless of what the local networks says.


why not synced bin directories, too?

i have a handful of utility shell scripts that i had spread out across my different machines. similar to syncing up the config files, i came up with a way to consolidate all those scripts into a single shared ~/Dropbox/sh/bin directory. i also have a ~/Dropbox/sh/bin/Darwin directory for my MacOSX-specific scripts, and a ~/Dropbox/sh/bin/Linux for my Linux scripts, all of which my PATH environment variable appropriately points to. See Listing 2 to see it in action.


older Dropbox versions can't remember which scripts are executable

the official stable version of Dropbox on Linux maxes out at 0.7.x, which unfortunately doesn't sync the executable bit on files. that means all that effort getting my bin directories would be for naught. all is not lost! there exist Dropbox beta builds that go up to 1.0.10, which do support executable-bit syncing. the easiest way to get the latest dropbox beta builds for Linux is with a utility by the name of dbupdate. Note: if you have Dropbox installed for a single user (e.g. not system-wide, like how crunchbang linux does it by default) you'll have to run dbupdate manually from the command line. problem solved!


the goods

without further ado:


Listing 2: bashbootstrap:

# bashbootstrap
if [ -z "$PS1" ]; then
 return
fi

localhostname() {
 case $(uname) in
  "Darwin" )
  echo $(scutil --get LocalHostName)
  ;;
  "Linux" )
  echo $(hostname)
  ;;
  * )
  echo $HOSTNAME
  ;;
 esac
}

dropboxshelldir=~/Dropbox/sh
dropboxdir=$dropboxshelldir/etc

masterbashrc=$dropboxdir/bashrc
masterbashrcpost=$dropboxdir/bashrcpost
osbashrc=$masterbashrc-$(uname)
localbashrc=$osbashrc-$(localhostname)

masterbin=$dropboxshelldir/bin
osbin=$masterbin/$(uname)
localbin=$osbin/$(localhostname)

echo -n "Applicable shell configs: "
for bashfile in "$masterbashrc" "$osbashrc" "$localbashrc" "$masterbashrcpost"; do
 if [ -r $bashfile ]; then
  . $bashfile
  echo -n "$(basename $bashfile) "
 fi
done
echo

echo -n "Applicable bin directories: "
for bindir in "$masterbin" "$osbin" "$localbin"; do
 if [ -d $bindir ]; then
  PATH=$PATH:$bindir
  echo -n "$(basename $bindir) "
 fi
done
echo

# Set convenience aliases
myed=${VISUAL:-${EDITOR:-vim}}
alias editbashrc="$myed $masterbashrc"
alias editbashrcpost="$myed $masterbashrcpost"
alias editosbashrc="$myed $osbashrc"
alias editlocalbashrc="$myed $localbashrc"

a few odds-and-ends

  • MacOSX gets confused with .bash_profile and .bashrc, check bash_profile vs. bashrc for a solution
  • need some idea on how to spruce up you command line? lifehacker terminal tweaks is a good place to start
  • Don't have a Dropbox account yet? Why not use this dropbox referral link to get an extra 250MB of sync space gratis! (full disclosure: i'll get and extra 250MB of space, too =] )