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
@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
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" };

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:

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):

Redis in Production at Smyte

To be clear we continue to run many Redis services in our production environment. It’s a great tool for prototyping and small workloads. For our use case however, we believe the cost and complexity of our setup justifies urgently finding alternate solutions.

  • Each of our Redis servers are clearly numbered with a current leader in one availability zone, and a follower in another zone.
  • The servers run ~16 different individual Redis processes. This helps us utilize CPUs (as Redis is single-threaded) but it also means we only need an extra 1/16th memory in order to safely perform a BGSAVE (due to copy-on-write), though in practice it’s closer to 1/8 because it’s not always evenly balanced.
  • Our leaders do not every run BGSAVE unless we’re bringing up a new slave which is carefully done manually. Since issues with the slave should not affect the leader and new slave connections might trigger an unsafe BGSAVE on the leader, slave Redis processes are set to not automatically rest
'use strict';
var React = require('react');
var emptyFunction = require('../../jslib/emptyFunction');
var throttle = require('lodash.throttle');
var listening = false;
var instances = [];
function makeStyle(defaults, tagName) {
tagName = tagName || 'div';
var Style = React.createClass({
getDefaultProps: function() {
return assign({}, defaults);
},
render: function() {
var style = assign({}, this.props);
delete style.children;
var Style = React.createClass({
render: function() {
var style = assign({}, this.props);
delete style.children;
return React.createElement(
'div',
{style: style, children: this.props.children}
);
}