Skip to content

Instantly share code, notes, and snippets.


Pete Hunt petehunt

  • Smyte
  • San Francisco, CA
View GitHub Profile
import binascii
import sqlite3
import collections
import math
import re
RE_SPLIT = re.compile(r'[^A-Za-z0-9_]+')
def tokenize(s):
# this is super basic and should be replaced with a real tokenizer
View ts-morph-watcher.ts
import { FSWatcher } from "chokidar";
import { Project, ProjectOptions } from "ts-morph";
import invariant from "invariant";
interface TsMorphWatcherFsEvent {
type: "add" | "unlink" | "change";
path: string;
type TsMorphWatcherEvent = TsMorphWatcherFsEvent | { type: "ready" };
import time
class Bucket(object):
def __init__(self, max_amount, refill_time, refill_amount):
self.max_amount = max_amount
self.refill_time = refill_time
self.refill_amount = refill_amount
def _refill_count(self):
View gist:5687276
/** @jsx React.DOM */
var MyRootComponent = React.createClass({
getInitialState: function() {
return {perMinute: '-', perDay: '-'};
componentDidMount: function() {
var socket = io.connect(this.props.url);
socket.on('business.clickout', this.setState.bind(this));
render: function() {
View gist:5687230
/** @jsx React.DOM */
var MyComponent = React.createClass({
getInitialState: function() {
// set up the initial state. used for "logical" initialization code
return {perMinute: '-', perDay: '-'};
componentDidMount: function() {
// fired only once, when the component is added to the DOM
// used for initialization code that has "side effects" i.e. i/o, jquery plugins, etc
var socket = io.connect(this.props.url);
petehunt /
Last active August 1, 2021 21:30
Create a fresh Ubuntu instance tied to your current working directory
set -euo pipefail
CONTAINER="$(pwd | sha256sum | awk '{print $1}')"
if docker inspect "$CONTAINER" 2> /dev/null > /dev/null;
docker start "$CONTAINER" -ai
docker run --name="$CONTAINER" -v $(pwd):/root -w /root -ti ubuntu bash
petehunt / React sortable
Created December 9, 2013 22:30
Here's an example of React + jQuery UI sortable. The key thing to note is that we have the render() method do absolutely nothing and use componentDidUpdate() + React.renderComponent() to proxy updates through to the children. This lets us manage the DOM manually but still be able to use all the React goodies you know and love.
View React sortable
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>

Keybase proof

I hereby claim:

  • I am petehunt on github.
  • I am petehunt ( on keybase.
  • I have a public key whose fingerprint is 576E 36CB DFD3 E7B8 727F DFD0 EF59 1C35 8D68 A67F

To claim this, I am signing this object:

View ReactDefaultBatchingStrategy.js
* Copyright 2013 Facebook, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software