Skip to content

Instantly share code, notes, and snippets.

View petehunt's full-sized avatar

Pete Hunt petehunt

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
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
self.reset()
def _refill_count(self):
/** @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() {
/** @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
petehunt / dshell.sh
Last active August 1, 2021 21:30
Create a fresh Ubuntu instance tied to your current working directory
#!/bin/bash
set -euo pipefail
CONTAINER="$(pwd | sha256sum | awk '{print $1}')"
if docker inspect "$CONTAINER" 2> /dev/null > /dev/null;
then
docker start "$CONTAINER" -ai
else
docker run --name="$CONTAINER" -v $(pwd):/root -w /root -ti ubuntu bash
fi
@petehunt
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.
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://fb.me/react-0.5.1.js"></script>
<script src="http://fb.me/JSXTransformer-0.5.1.js"></script>
</head>

graphql

hero {
  name
  friends {
    name
  }
}

Keybase proof

I hereby claim:

  • I am petehunt on github.
  • I am petehunt (https://keybase.io/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:

/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software