Monday, September 23, 2013

Toggle a MacBook's Wifi with a Bash One-Liner

Sometimes the easiest way is a bash one-liner.  (Think Alfred shortcuts, BetterTouchTool gestures, Terminal.app.)  Running an applescript is all fine and dandy, but it's heavy.  Here's how to toggle your MacBook wifi on or off, where the wifi interface is en0.

( networksetup -getairportpower en0 | grep On ) \
   && ( networksetup -setairportpower en0 Off ) \
   || ( networksetup -setairportpower en0 On )

This is one of those messed-up bash-isms that uses conditional logic in the "wrong" way, elegantly.

Tuesday, September 17, 2013

Setting Processing's User-Agent for loadXML

In Processing, I'm fetching Yahoo's weather forecast for my location.  The loadXML() function is perfectly happy to take a URL, so I can just point it at my location's RSS feed.

In its default mode, this sends a user-agent string of "Java/1.6.0_51" which reflects my current Java version.  But I want to set my User-Agent, to something more descriptive.  If my project misbehaves, or an operator gets curious, it would be polite to have a more descriptive string with some contact info.

You can prepend a string to the user-agent by specifying it in your setup() function.

void setup () {
  System.setProperty("http.agent", "abstractForecast; https://github.com/fnaard/abstractForecast;");
}

Which results in the web server logging a user-agent of:

abstractForecast; https://github.com/fnaard/abstractForecast; Java/1.6.0_51

Oracle has some documentation on the network properties you can set.  There are more, notably: proxy settings, IPv4/v6 preference, and DNS caching behavior.

Sunday, September 1, 2013

Types of PS3 Hard Drive Caddies

I sent a friend's PS3 in for service, and they ask you to pull out your hard drive if you've upgraded it.  I did, but then at some point I discarded or lost the caddy that it belongs in.  There are four generations of PS3, and each has its own style of caddy.  Here's how it goes.

Generation
Models
Caddy
Old Fatty

CECHA01
CECHB01
CECHG01
CECHE01
Wire Pull-Tab

Newer Fatty


CECHH01
CECHK01
CECHL01
CECHP01
Flat Metal Pull-Tab

Slim

CECH-2001A
CECH-2001B
CECH-2101A
CECH-2101B
CECH-2501A
CECH-2501B
CECH-3001A
CECH-3001B
Side Flange

Slimmer


CECH-4001B
CECH-4001C
Swing-Out Tab