Skip to content

Instantly share code, notes, and snippets.

@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 <[email protected]>
#
# 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 / 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 / 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 / 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 / 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
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() {
#!/usr/bin/env python
def foo(l=[]):
print l
l.append('hi')
foo()
foo()
@rca
rca / known_hosts_delete.sh
Created July 6, 2012 22:24
Remove a line from the SSH known_hosts file.
function khd
{
[ -z $1 ] && echo "No line number given" && return -1
sed -i -e "${1}d" ${HOME}/.ssh/known_hosts
}
@rca
rca / models.py
Created April 17, 2012 17:44
Adding URI to TastyPie resource
class NotebookResource(BackboneJSResource):
user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Notebook.objects.all()
authentication = MULTI_AUTH
authorization = OwnerAuthorization()
# allow to list posts for this notebook
@rca
rca / tasks.py
Created March 27, 2012 08:14
break a big celery job into smaller, batched, chunks
"""
Celery tasks that batch a job with many tasks into smaller work sets.
The problem I'm attempting to solve is one where a job comprised of many
tasks (say 100) will snub out a job comprised of only a few tasks (say 5). It
appears as though by default celery will queue up the second job's 5 tasks
behind the first job's 100 and it will have to wait until the first job's
completion before it even begins.