Tag: Tips

Manage Unblock-Us on OS X

September 2, 2014 » Consume, Geek

Sometimes you need to pretend to be in another country.

VPN’s are great for this, but one novel approach is Unblock-Us which changes the location of your DNS server, instead. You use your IP, but you make DNS requests against in-country DNS servers, thus directing you to the application servers supporting that country. There is no anonymity, but you don’t have to worry about bandwidth caps, and it’s worked for every service I’ve tried it on.

I use this when I need to access video that is region limited. However, changing your DNS servers through the Mac settings app is a pain when you have to do it over and over again. On Windows they have an app to download which can manage the change for you.

So what I did on my Mac was create a script to use the built in networksetup command to change my DNS as needed.

networksetup -setdnsservers "Wi-Fi"

And one to un-set it.

networksetup -setdnsservers "Wi-Fi" "Empty"

To top it off, I built a simple Alfred workflow, making it even quicker and cleaner.

Unblock-Us Alfred Workflow

You can download that here: Unblock-Us Alfred Workflow.

Note that if you are using a wired network interface, you’ll need to change the service name from “Wi-Fi” to, well, whatever it is you are using.

Thinking Functionally In PHP

November 22, 2011 » Geek

I’ve noticed a trend in PHP code to shy away from function application and closures. I understand to some extent. Useful, inline anonymous functions were not available until 5.3.0, which is relatively new. And create_function is an abomination.

Still, I think that PHP programmers just don’t think in this mindset, but it can be very useful.

Here is a rather contrived example, but one I’ve honestly seen an analogue of before.

$accumulator = array();
foreach( $this->tags->all() as $tags ) {
  $accumulator[] = htmlspecialchars( $tag->name );
return implode( ', ',  $accumulator );

Easy to understand, simple, does the job, but it is far more verbose than it needs to be.

Here is a version using array_map.

$tags = array_map( 'htmlspecialchars', $this->tags->all() );
return implode( ', ', $tags );

The array_map function is doing all the work of the loop, but you don’t have to write it and you don’t have to manage the accumulator.

Doesn’t that feel better?

Next time you mangle an array, first think if array_map or it’s friends array_filter or array_reduce could do it better.

Tags: , ,

HP TouchPad Developer Mode

July 20, 2011 » Geek

The online docs for testing and deploying your Enyo apps to the TouchPad are woefully weak. I finally found how to get the TouchPad into developer mode, and thought I’d share.

  1. Start “Device Info”
  2. In the menu, pick “Custom Application”
  3. Enter “##devmode#”
  4. Done!

You’ll need to do a restart before you can install any packages, or at least I did.

Compiling CPython Modules with XCode 4

April 7, 2011 » Geek

I’ve had trouble compiling native extensions on the Mac before, but I finally found a fix.

You just need the correct ARCHFLAGS environment variable. You can set this in your .bashrc or use it right before python setup.py build

ARCHFLAGS="-arch i386 -arch x86_64"

This works because XCode dropped the PPC compiler in v4, and with that variable we tell the setup script not to bother trying to compile for that arch, just i386 and x86_64.

Much thanks to Y.H. Wong in this Super User thread.

Tags: , , ,