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 / 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
#!/usr/bin/env python
"""
The attached utf-8 encoded text file contains the favorite musical artists of 1000 users from LastFM. Each line is a list of up to 50 artists, formatted as follows:
Radiohead,Pulp,Morrissey,Delays,Stereophonics,Blur,Suede,Sleeper,The La's,Super Furry Animals\n Band of Horses,Iggy Pop,The Velvet Underground,Radiohead,The Decemberists,Morrissey,Television\n
etc.
Write a program that, using this file as input, produces a list of pairs of artists which appear TOGETHER in at least fifty different lists. For example, in the above sample, Radiohead and Morrissey appear together twice, but every other pair appears only once. Your program should output the pair list to stdout in the same form as the input (eg Artist Name 1, Artist Name 2\n).
;; force myself to use arrow keys so that I don't
;; mash the control key with my pinky 90% of the time I am using
;; emacs.
(defun save-the-pinky ()
"Echo out message to echo area"
(interactive)
(message "Use the arrow keys!")
)
(global-set-key [(control n)] 'save-the-pinky)
@rca
rca / status_prompt.sh
Created December 3, 2012 23:58
show last command's status on prompt and make it red if non-zero
function highlight_status
{
if [ "$1" -ne "0" ]; then
echo -e "\033[31;1m${1}\033[0m"
else
echo 0
fi;
}
export PS1='[$(highlight_status $?)]\u@\h:\w\$ '
@rca
rca / net.conf
Last active December 12, 2015 09:39
A python-based pillar `sls` file that uses grains data to create a `Network` object. The network object is returned in a dictionary that is included in the render context.
addr={{ pillar['shoe']['network'].addr }}