Skip to content

Instantly share code, notes, and snippets.

@tilgovi
tilgovi / gist:f94565b2beb6623a79e9
Created August 26, 2014 09:58
Sketches for forced login, bridge changes
commit 318158cf7ee82797969e5ab2fa559ca6ab4dfa6a
Merge: 0610025 a17f146
Author: Randall Leeds <tilgovi@hypothes.is>
Date: Mon Jul 28 22:29:32 2014 -0700
WIP on master: 0610025 Bump annotator-store version for security fix
diff --cc h/static/scripts/app_directives.coffee
index 7bac3cc,7bac3cc..4e03cca
diff --cc h/static/scripts/controllers.coffee
@tilgovi
tilgovi / basic.coffee
Last active August 29, 2015 14:01
Idea for bootstrap of a basic (default) Annotator application
Util = require('../src/util')
$ = Util.$
Adder = require('../src/plugin/adder')
Viewer = require('../src/plugin/viewer')
Editor = require('../src/plugin/editor')
TextSelector = require('../src/plugin/textselector')
Highlighter = require('../src/plugin/highlighter')
// This is our interaction point
position = null;
$(document.body).on('mouseup', function (event) {
});
var annotator = Annotator.create({
onSelection: function (event) {
// We have to trigger this event ourselves.
// Could be as simple as:
@tilgovi
tilgovi / application.coffee
Last active August 29, 2015 14:00
Annotator selector extension pseudocode
selectorExtension = require('./selectorExtension')
CustomAnnotator = Annotator.extend(selectorExtension)
annotator = new CustomAnnotator(...)
@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 / 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 / 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: