Skip to content

Instantly share code, notes, and snippets.

View atdt's full-sized avatar
💭
I may be slow to respond.

Ori Livneh atdt

💭
I may be slow to respond.
  • Google
  • New York City
View GitHub Profile
@atdt
atdt / sighup_daemon.py
Created December 30, 2011 08:14
DaemonContext (for python-daemon) that handles SIGHUPS
import daemon
import signal
class SighupDaemon(daemon.DaemonContext):
""" A DaemonContext that catches SIGHUPs """
# get default signal handler map for this system
defaults = daemon.daemon.make_default_signal_map()
def __init__(self, *args, **kwargs):
@atdt
atdt / Makefile
Created January 5, 2012 23:43
Build and upload Chrome extensions to GitHub using APIv3
EXTNAME := extension
KEYFILE := $(EXTNAME).pem
CRXFILE := $(EXTNAME).crx
EXTDIR := $(EXTNAME)
SHELL := /usr/bin/env bash
CHROME := open /Applications/Google\ Chrome.app -n --args
CWD := $(shell pwd)
SIZE := $(shell wc -c <$(CRXFILE) | tr -d ' ')
VERSION := $(shell python -c "import json,sys;print json.loads(sys.stdin.read()).get('version','')" < $(EXTDIR)/manifest.json)
ZIPFILE := $(EXTNAME)-$(VERSION).crx
@atdt
atdt / stacktrace.js
Created February 19, 2012 07:47
v8 stack trace
var stack_holder = new Error;
function stackPrepare(e,stacks) {
var stack = stacks
for (var p in stack[0]) {
stack[p] = stack[0][p]
}
stack.find = function(fn) {
for (var i=stack.length;i--;) {
if (stack[i].getFunction() === fn) break;
@atdt
atdt / unittest-random.py
Created March 12, 2012 07:27
Reproducible, random-data-driven tests for unittest
# -*- coding: utf-8 -*-
"""
RandTest
A unittest.TestCase subclass that facilitates working with
randomly-generated test data.
https://gist.github.com/2020459
:copyright: (c) 2012 by Ori Livneh
@atdt
atdt / dart-print.py
Created March 21, 2012 22:21
Dart-like print function for Python
-*- coding: utf-8 -*-
"""
Dart-like print function
(C) 2012 by Ori Livneh
MIT License
"""
from __future__ import print_function
import inspect
import string
@atdt
atdt / multitail
Created March 22, 2012 20:05
tail -f multiple files
# tail multiple files
# based on http://www.dabeaz.com/coroutines/follow.py
import sys
import time
import itertools
def tail(filenames):
# open files
@atdt
atdt / nose2-random.py
Created March 22, 2012 23:22
Randomized tests for Nose 2
# -*- coding: utf-8 -*-
"""
nose2-random
This plug-in facilitates capturing and setting the state of the internal
random number generator prior to test execution. Test output is annotated
with a seed value that you can re-use to reproduce randomly-generated test
data across runs.
.. note ::
@atdt
atdt / update-chromium.sh
Created March 28, 2012 17:25
Update Chromium to latest nightly on OS X
#!/usr/bin/env bash
# Update Chromium (on OS X) to the latest nightly build.
install_dir='/Applications/Chromium.app'
base_url='http://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac'
build=$(curl -s -f ${base_url}/LAST_CHANGE)
installed=$(/usr/libexec/PlistBuddy -c 'Print :SVNRevision' ${install_dir}/Contents/Info.plist)
script=$(basename $0)
@atdt
atdt / hack.sh
Created March 31, 2012 12:44 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@atdt
atdt / jenkins.js
Created April 7, 2012 17:28
An implementation of Jenkins's one-at-a-time hash
// An implementation of Jenkins's one-at-a-time hash
// <http://en.wikipedia.org/wiki/Jenkins_hash_function>
function hashString(key) {
var hash = 0, i = key.length;
while (i--) {
hash += key.charCodeAt(i);
hash += (hash << 10);
hash ^= (hash >> 6);
}