Python SDK for PhoneFactor

A first (and very alpha) attempt at creating a Python SDK for PhoneFactor.

Link: http://github.com/silas/graveyard/tree/master/python-phonefactor/

Universal Feed Parser to JSON

My attempt at wrangling a Universal Feed Parser object into JSON.

import feedparser

def json_make_normal(obj):
    if type(obj) in [str, unicode, int, float, bool, dict, set, list, tuple]:
        return obj
    try: return dict(obj)
    except: pass
    try: return list(obj)
    except: pass
    return None

def json_handle(obj):
    obj = json_make_normal(obj)
    if type(obj) in [str, unicode]:
        obj = obj.replace('\\', '\\\\')
        obj = obj.replace('"', '\\"')
        obj = obj.replace('\b', '\\\b')
        obj = obj.replace('\f', '\\\f')
        obj = obj.replace('\n', '\\\n')
        obj = obj.replace('\r', '\\\r')
        obj = obj.replace('\t', '\\\t')
        return '"%s"' % obj
    elif type(obj) in [int, float]:
        return obj
    elif type(obj) is bool:
        if obj: return 'true'
        else: return 'false'
    elif type(obj) is type(None):
        return 'null'
    elif type(obj) is dict:
        temp = ''
        for key in obj.keys():
            temp += '%s:%s, ' % (json_handle(key), json_handle(obj[key]))
        return '{%s}' % temp[:-2]
    elif type(obj) in [set, list, tuple]:
        temp = ''
        for value in obj:
            temp += '%s, ' % json_handle(value)
        return '[%s]' % temp[:-2]
    return 'null'

data = feedparser.parse('http://digg.com/rss/index.xml')

print json_handle(data)

Link: feed_parser_to_json.py

Update: According to John Paulett jsonpickle now supports Universal Feed Parser objects. Thanks for letting me know!

OS X’s GNU Screen – Open in the Current Working Directory

How to get GNU Screen working properly in Mac OS X.

~/.bashrc

alias screen='export SCREENPWD=$(pwd); /usr/bin/screen'
export SHELL='/bin/bash -rcfile ~/.bash_profile';

case "$TERM" in 
    'screen')
         cd $SCREENPWD
         ;; 
esac

~/.screenrc

startup_message off
shell -$SHELL

Four Ways to Make Safari Better

Post a Get

I've created a PHP script called Post a Get which can be copied to any PHP capable server and used to created a POST request using GET syntax.

Let's say you use GoDaddy as your domain registrar and you would like to see if a domain is available using Firefox keywords, but they don't offer a GET search.

For a traditional keyword, you could construct a GET request like:

https://www.godaddy.com/gdshop/registrar/search.asp&checkAvail=1&fblur=1&tld=.com&domainToCheck=%s

But as of right now Firefox doesn't offer a way to create POST keywords. What Post a Fix does is allow you to construct a POST request using GET syntax and pass it to the Post a Get code.

So if you wanted to submit the above GET as a POST, you would construct the URL and append the special __action parameter with target URL. So the final URL would look something like:

OS X GNU Screen Proper Bash Prompt

How to get GNU Screen working properly in Mac OS X.

~/.bashrc

alias screen='export SCREENPWD=$(pwd); /usr/bin/screen'
export SHELL='/bin/bash -rcfile ~/.bash_profile';

case "$TERM" in
    'screen')
         cd $SCREENPWD
         ;;
esac

~/.screenrc

startup_message off
shell -$SHELL

Gracefully restart Apache in Debian

alias graceful="sudo /usr/sbin/apache2 -t && sudo /etc/init.d/apache2 stop && sleep 2 && sudo /etc/init.d/apache2 start"

Simple Shell Script to Manage SSH Tunnels

Manage SSH Tunnel is a simple shell script to start and stop ssh tunnels from the terminal.

Setup

Note: the setup assumes bash as the default shell

  1. Download tunnel.sh and save it to ~/bin/
  2. Add to ~/.bash_profile or ~/.bashrc

    alias tunnel_home='/bin/sh ~/bin/tunnel.sh example.net sam 22 8888'
    
  3. Replace example.net with the hostname of the server, sam with the username on the server, and 8888 with the local tunnel port

  4. Type source ~/.bash_profile or source ~/.bashrc

Usage

  1. To open the tunnel

    tunnel_home start
    
  2. To close the tunnel

    tunnel_home close
    

Better Terminal Font in OS X (GNOME)

With the release of Leopard (OS X 10.5) came a sufficiently usable Terminal (aka tabs). The only real complaint I had was the font.

Terminal

I ended up tracking down the default font used in the GNOME terminal and installed it using the steps below:

  1. Download Bitstream Vera Mono 1.10
  2. Extract the archive
  3. Double click on VeraMono.ttf
  4. Click Install Font
  5. From Terminal click Terminal->Preferences
  6. To the right of Font click Change...
  7. Select Bitstream Vera Sans for the Family
  8. Select 12 for the Size
  9. Close the Fonts window
  10. Enable Antialias text under Text
  11. Restart the Terminal

iGoogle – Hide Google Search

NOTE: This gadget will no longer work, Google has deprecated the inline property which this gadget required.

Hide Google Search (source) is a gadget which hides the search area of iGoogle.

I've tested the gadget with the latest versions of Firefox, IE and Safari.

Hide Google Search

The above image is how the iGoogle page will load by default. You can toggle the hidden area by clicking the line right below the navigation bar.

Hide Google Search Expanded