Skip to content

Instantly share code, notes, and snippets.

@tilgovi
tilgovi / gist:969619
Created May 12, 2011 22:38
gunicorn logging reload on USR1
diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py
index 6062117..a681420 100644
--- a/gunicorn/app/base.py
+++ b/gunicorn/app/base.py
@@ -38,6 +38,7 @@ class Application(object):
self.callable = None
self.logger = None
self.do_load_config()
+ self.__handlers = None
@tilgovi
tilgovi / center-window.el
Last active June 9, 2019 07:56
Center Emacs Windows
(defun balance-margins ()
"This function balances the margins of all windows on the selected
frame such that the first column and the fill column are the same
distance from the left and right edge, respectively."
(walk-windows
(lambda (window)
(let* ((total-width (window-total-width window))
(fringe-width (apply '+ (butlast (window-fringes window))))
(scroll-bar-width (window-scroll-bar-width window))
(divider-width (window-right-divider-width window))
@tilgovi
tilgovi / gist:1227319
Created September 19, 2011 19:20
Node.js call/cc function with fibers
/* This is the call-with-current-continuation found in Scheme and other
* Lisps. It captures the current call context and passes a callback to
* resume it as an argument to the function. Here, I've modified it to fit
* JavaScript and node.js paradigms by making it a method on Function
* objects and using function (err, result) style callbacks.
*/
Function.prototype.callcc = function(context /* args... */) {
var that = this,
caller = Fiber.current,
fiber = Fiber(function () {

Keybase proof

I hereby claim:

  • I am tilgovi on github.
  • I am tilgovi (https://keybase.io/tilgovi) on keybase.
  • I have a public key whose fingerprint is 9255 5CDE B2C1 5E97 0AD8 FDE8 5994 A5A1 8F13 626A

To claim this, I am signing this object:

@tilgovi
tilgovi / README.md
Last active December 22, 2015 16:58
Getting back to a commit after stripping the git hash from `git describe --always` output.

Background

For Hypothes.is, I've been using git describes --always option for generating version numbers. However, Chrome apps can only have digits (and '.') in their version identifiers. For that reason, instead of ending up with 0.0.6-1371-g93b5d9d (which is what versioneer generates for me), I've been publishing extensions that strip off the git hash.

Problem

When something goes wrong in production, the clear question is "what git hash was this extension built from?"

Solution

Here's my bash script to recover a git hash from a version like "0.0.6-1371" (in our case this means 1371 commits since v0.0.6).

It's easy: use git rev-list to count the commits since the tag. Then, subtract from that the trailing count in our version number to get the difference. Finally, skip back that amount from HEAD (important: in topological order).

@tilgovi
tilgovi / post-receive
Created September 26, 2012 08:21
python git deploy
#!/bin/bash
while IFS=" " read -ra LINE; do
REF=${LINE[2]}
HEAD=`echo ${REF} | awk '{print $NF}' | awk -F/ '{print $NF}'`
GIT_WORK_TREE=~/${HEAD} git checkout -f ${REF}
source ~/${HEAD}/bin/activate
pip install -r ~/${HEAD}/requirements.txt
pip install ~/${HEAD}
deactivate
@tilgovi
tilgovi / export.py
Created August 25, 2012 07:57
Open Annotation export from okfn/annotator-store
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import json
import jsonld
import pprint
import rdflib
import rdflib_jsonld
@tilgovi
tilgovi / dom-traversals.coffee
Last active October 8, 2015 00:09
DOM tree traversal helpers
# Return true if the given predicate is true for every Node of the tree.
# The predicate function is invoked once for each Node in the tree.
# An optional third argument specifies a traversal order and should be a
# function that takes a Node and returns its successor. The default order is
# DOM position order (pre-order).
everyNode = (node, fn, next = preFirst) ->
return !someNode(node, ((n) -> !fn(n)), next)
# Return the first Node in the tree that matches the predicate.
@tilgovi
tilgovi / README.md
Created June 20, 2012 23:09 — forked from mbostock/.block
Fisheye Grid

The above grid shows the effect of fisheye distortion. Move the mouse to change the focal point.

@tilgovi
tilgovi / gist:2239638
Created March 29, 2012 16:40
virtualenv lifting
"""
If a virtual environment is active, make sure it's being used.
Globally-installed console scripts use an absolute shebang path which
prevents them from importing packages in the virtualenv.
"""
import os
import os.path
if 'VIRTUAL_ENV' in os.environ: