Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
def foo(l=[]):
print l
l.append('hi')
foo()
foo()
index.html:
<div ng-controller="ClickyController">
<a href="#" class="btn btn-primary" ng-click="doSomething()">Click my!</a>
</div>
js/clicky.js:
function ClickyController($scope, $location) {
$scope.doSomething = function() {
@rca
rca / virtualbox.sh
Created August 21, 2012 02:16
VirtualBox shortcuts
VBOX_MANAGE='/Applications/VirtualBox.app/Contents/MacOS/VBoxManage-amd64'
function vautostart() {
cat ${HOME}/.vbox_autostart | while read i; do
${VBOX_MANAGE} startvm --type=headless $i
done;
}
function _vdo() {
buf=$1
@rca
rca / shelltools.sh
Created August 21, 2012 02:26
Semi-useful Shell functions
# Copyright (c) 2004-2008, Roberto Aguilar <berto at chamaco dot org>
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms, with or
# without modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
@rca
rca / iso2unix.py
Created September 11, 2012 21:08
Convert an ISO 8601 timestamp to unix timestamp
import calendar
from iso8601 import parse_date
def iso2unix(timestamp):
"""
Convert a UTC timestamp formatted in ISO 8601 into a UNIX timestamp
"""
# use iso8601.parse_date to convert the timestamp into a datetime object.
@rca
rca / gstash.sh
Created September 30, 2012 10:18
Git stash helper functions.
#!/bin/bash
#
# Helper functions around "git stash"
#
# Use this file by sourcing it into your shell environment. For example:
#
# source /path/to/gstash.sh
#
# Once sourced in you can run the commands:
#
@rca
rca / repath_dylib.sh
Created October 7, 2012 20:37
Repath the references in an OS X .dylib file for packaging within an application.
#!/bin/bash
# Repathing .dylib's references for packaging within an application
# Author: Roberto Aguilar <roberto.c.aguilar@gmail.com>
#
# With help from Nick Jensen's blog at:
# http://goto11.net/how-to-bundle-a-c-library-with-a-cocoa-application/
#
# All references within the dylib except ones to files in /usr/lib are
# converted over to reference the given root.
@rca
rca / serve.py
Created November 13, 2012 01:37
SimpleHTTPServer subclass that sends custom headers
#!/usr/bin/env python
import SimpleHTTPServer
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
@rca
rca / README.md
Created November 14, 2012 23:59
Keep a Mountain Lion system from ever going to sleep

Mountain Lion Narcolepsy

I have experienced Mountain Lion on a Mac mini will go to sleep regardless of the Energy Saver settings in the System Preferences. After some reading, it seems OS X Mountain Lion has very aggressive power management, which will put the system to sleep against your (my) will.

This is my attempt to create a Launch Agent, which will use the system command caffeinate to prevent sleep indefinitely.

Copy the plist into ~/Library/LaunchAgents, then, in a Terminal session, run the command to load it up:

@rca
rca / list_counter.py
Created November 29, 2012 00:41
Count the number of times an item appears in a list
counts = {}
for item in items:
counts.setdefault(item, 0)
counts[item] += 1
print counts