Skip to content

Instantly share code, notes, and snippets.

angular.module('todoApp').factory 'Task', ($resource) ->
class Task
constructor: (taskListId) ->
@service = $resource('/api/task_lists/:task_list_id/tasks/:id',
{task_list_id: taskListId, id: '@id'})
create: (attrs) ->
new @service(task: attrs).$save (task) ->
attrs.id = task.id
attrs
@nkrumm
nkrumm / Knockdown.tmTheme
Created October 8, 2013 21:07
Improved version of knockdown theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>author</key>
<string>Allen Bargi</string>
@nkrumm
nkrumm / post-update
Created October 9, 2013 07:39
post-update hook with specific directory export to /var/www/ or similar
#!/bin/sh
#
# this post-update hook shows how individual directories
# from a larger project can be exported to the /var/www directory
echo
echo "*** deploying to /var/www"
git archive master sims | (cd /var/www; tar -x)
echo "*** restarting apache2"
service apache2 restart
@nkrumm
nkrumm / make_swap_file.sh
Last active December 25, 2015 17:29
Create a swap *file* (not a partition)
# set count=2048 to whatever size you want, in Megabytes (2048 = 2GB swap)
# location of file is /var/swapfile
sudo dd if=/dev/zero of=/var/swapfile bs=1M count=2048 &&
sudo chmod 600 /var/swapfile &&
sudo mkswap /var/swapfile &&
echo /var/swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab &&
sudo swapon -a
# to turn off swap (remove for /etc/fstab as well)
sudo swapoff -a
@nkrumm
nkrumm / gist:7031035
Last active December 25, 2015 19:58
A self-executing SGE submit script. This script will auto-submit itself in the SGE queue, but run the commands in the <else> block when submitted. Obviates the need for two scripts (one to submit and one to run). Submit only from the head node (and set $HEAD_NODE_NAME).
# set this to your head node hostname (run hostname)
HEAD_NODE_NAME=master
if [ `hostname` = $HEAD_NODE_NAME ]; then
NODES=`qconf -sel | grep -v $HEAD_NODE_NAME`
for NODE in $NODES; do
SCRIPT_PATH=`readlink -f $0`
qsub -l h=$NODE $SCRIPT_PATH
done
import time
from functools import wraps
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
"""Retry calling the decorated function using an exponential backoff.
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
@nkrumm
nkrumm / gist:7092165
Created October 21, 2013 22:42
Removing SGE hosts from a queue (why is this so hard?) credit: http://resbook.wordpress.com/2011/03/21/remove-execution-host-from-gridengine/
# first, you need to disable the host from queue to avoid any jobs to be allocated to this host
qmod -d [email protected]
# wait for jobs to be finished execution on this host, then kill the execution script
qconf -ke thishost.com
# remove it from the cluster, this opens an editor, just remove the lines referring to this host
qconf -mq all.q
# remove it from allhosts group, this also opens an editor, remove lines referring to this host
qconf -mhgrp @allhosts
# remove it from execution host list
qconf -de thishost
@nkrumm
nkrumm / gist:7107196
Created October 22, 2013 20:05
Topy- htop and iotop in one window w/ tmux
alias topy='tmux attach -t topy || tmux new-session -s topy -d "htop" \; rename-window htop \; split-window -v -p 15 "iotop -o" \; attach -t topy'
@nkrumm
nkrumm / gist:7388421
Created November 9, 2013 18:41
embed ipython for debugging
# some code...
import IPython; IPython.embed()
# more code...
@nkrumm
nkrumm / merge_intervals.py
Created November 26, 2013 18:28
pandas compatible merge interval function
def merge_intervals(df, start_col="start", stop_col="stop"):
out = []
df = df.sort(start_col)
first_row = True
for ix, row in df.iterrows():
if first_row:
current_start = row[start_col]
current_stop = row[stop_col]
first_row = False
start = row[start_col]