Skip to content

Instantly share code, notes, and snippets.

@jhofman
jhofman / track_changes.sh
Last active January 28, 2016 20:23
word-style "track changes" with latexdiff and git
#!/bin/bash
#
# script to show word-style "track changes" from a previous git revision
#
if [ $# -lt 2 ]
then
echo "usage: $0 <rev> <maintex>"
echo " rev is the prefix of a git revision hash"
echo " see 'git log' for revision hashes"
@zeroasterisk
zeroasterisk / client-time.js
Created October 17, 2013 02:11
meteor implementation of client/server time sync
/**
* When the client initializes this JS
*
* it gets the server time and sets a Session variable `serverTimeOffset`
* so the client always knows how far it's off from server time
* (and can be in sync)
*
*/
// getServerMS() and calculate offset/diff, set into session var
Meteor.setServerTime = function() {
@mizzao
mizzao / zooniverse_realtime_api.md
Last active December 22, 2015 22:39
zooniverse real-time command api examples

See https://gist.github.com/arfon/a79777b68dc512c06043 for general API discussion. Also, Arfon has a PDF file outlining our whiteboard design for this API.

Overall vision for the realtime research API:

  • Refactor Ouroboros to allow support for subject retiring, assignment (including client side), and custom interface commands.
  • Find an appropriate project for CrowdSynth or engagement-style experiments. Design interface tweaks, messaging, and other interventions into the project.
  • Subscriber gets access key to experiment on users for a given project. Access has certain limits such as max percentage of users, and time limit (2 months) etc.
  • Subscriber listens to Kafka stream (using DB replication library) for users coming online.
  • Subscriber sends a user request command (with possible time demand) to API when an interesting user comes online. API responds with either 200 (OK) or 403 (denied). If OK, these users are available for sending commands.
  • Control of users via commands is available for the spe
@minrk
minrk / nbstripout
Last active June 6, 2023 06:23
git pre-commit hook for stripping output from IPython notebooks
#!/usr/bin/env python
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
LICENSE: Public Domain
@enaeseth
enaeseth / objectid_to_uuid.py
Created June 12, 2013 19:29
Convert a MongoDB ObjectID to a valid, semantically similar UUID.
"""
Convert a MongoDB ObjectID to a version-1 UUID.
Python 2.7+ required for datetime.timedelta.total_seconds().
ObjectID:
- UNIX timestamp (32 bits)
- Machine identifier (24 bits)
- Process ID (16 bits)
- Counter (24 bits)
@larsmans
larsmans / hellinger.py
Created July 15, 2012 13:25
Hellinger distance for discrete probability distributions in Python
"""
Three ways of computing the Hellinger distance between two discrete
probability distributions using NumPy and SciPy.
"""
import numpy as np
from scipy.linalg import norm
from scipy.spatial.distance import euclidean