Skip to content

Instantly share code, notes, and snippets.

@kamiller
kamiller / clockwork.rb
Last active August 29, 2015 13:57
capistrano recipe to start/stop/restart daemonized clockwork
# Tasks to start/stop/restart a daemonized clockwork instance
namespace :clockwork do
desc "Start clockwork"
task :start, :roles => [:app] do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec clockworkd -c #{current_path}/config/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log start"
end
task :stop, :roles => [:app] do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec clockworkd -c #{current_path}/config/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log stop"
end
@kamiller
kamiller / ubuntu-partner-repo
Created July 3, 2012 20:22
add ubuntu partner repo
sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"
@kamiller
kamiller / lru.py
Created July 5, 2012 14:26
python LRU functools wrapper impl
import collections
import functools
def lru_cache(maxsize=100):
'''Least-recently-used cache decorator.
Arguments to the cached function must be hashable.
Cache performance statistics stored in f.hits and f.misses.
http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
@kamiller
kamiller / ubuntu_release.sh
Created August 28, 2012 12:35
determine ubuntu release
#!/bin/bash
lsb_release -sc
@kamiller
kamiller / debian_package_version.sh
Created August 28, 2012 18:18
compare debian package versions for equality
dpkg --compare-versions "1.0.11~rc1" gt "1.0-10" && echo "1.0-11 greater than RC"
@kamiller
kamiller / signal_ex.py
Created January 8, 2013 20:02
send / receive USR1 signal
#!/usr/bin/env python
import os
import sys
import signal
if __name__ == "__main__":
print "sending signal, pid="+repr(sys.argv[1])
os.kill(int(sys.argv[1]), signal.SIGUSR1)
@kamiller
kamiller / download_all_files.sh
Created March 11, 2013 22:55
recursively download all files in a directory
#!/bin/bash
wget -r -q -nH --cut-dirs=2 --no-parent --reject="index.html*" http://mysite.com/dir1/dir2/data
require 'octokit'
require 'csv'
require 'date'
# Github credentials to access your private project
USERNAME="USER_NAME"
PASSWORD="SEKRIT"
# Project you want to export issues from
USER="REPO_OWNER"
PROJECT="REPO_NAME"
@kamiller
kamiller / comparable_mixin.py
Last active December 15, 2015 20:59
python comparable mixin to ease comparision and hashing of objects
class ComparableMixin(object):
def _compare(self, other, method):
try:
return method(self._cmpkey(), other._cmpkey())
except (AttributeError, TypeError):
raise NotImplementedError("_cmpkey not implemented")
def __lt__(self, other):
return self._compare(other, lambda s,o: s < o)
@kamiller
kamiller / firefox_homepage.md
Last active December 19, 2015 10:29
set ubuntu firefox default homepage

Firefox

Set default home page edit /etc/firefox/syspref.js

At the bottom of the file add:

user_pref("browser.startup.homepage", "http://google.com");

Obviously change "http://google.com" to the page of your choice (or not).