Skip to content

Instantly share code, notes, and snippets.

View ayust's full-sized avatar

Amber Yust ayust

  • Google
  • Vancouver, BC
  • 03:52 (UTC -07:00)
View GitHub Profile
@ayust
ayust / tomltojson.py
Created January 21, 2017 18:16
Quick script to convert TOML front matter to JSON front matter
#!/usr/bin/env python
import json
import os
JSON_CONFIG = {
"indent": 2,
"sort_keys": True,
"ensure_ascii": False,
"allow_nan": False,
>>> def echo(s):
... print s
...
>>> funcs = []
>>> for i in range(3):
... funcs.append(lambda: echo(i))
...
>>> for func in funcs:
... func()
...
"""Analyze a log of a text communication, looking for distinct discussions."""
from collections import Counter, deque
import re
import string
import sys
LINE_RE = re.compile(r"^(?P<timestamp>[\d:]+)\s"
r"<\W?(?P<nick>[\w|^`[\]]+)>\s"
r"(?P<message>.*)$")
@ayust
ayust / fluttermosh.sh
Created November 30, 2012 21:21
Wrapper for mosh that makes it work on systems where mosh doesn't seem to want to parse properly
#!/bin/bash
set -e
MOSH_IP="$(host -cIN "$1" | cut -d' ' -f4)"
MOSH_CONNECT_INFO="$(ssh -t "$1" -- "mosh-server" | grep "MOSH CONNECT" | tr -d '\r' | cut -d' ' -f3,4)"
read MOSH_PORT MOSH_KEY <<<"$MOSH_CONNECT_INFO"
MOSH_KEY="$MOSH_KEY" exec mosh-client "$MOSH_IP" "$MOSH_PORT"
@ayust
ayust / ordering.py
Created July 7, 2012 04:22
A simple proof-of-concept for comment partial ordering
# Let us control the passage of time (magic!)
wall_time = 0
class Comment(object):
# Used for quick and dirty unique IDs.
# In a real system, the IDs probably wouldn't be
# this simple, but it doesn't matter what they are
# as long as they're unique.
_instance_counter = 0
#!/bin/bash
trap "echo ' Batman!'; exit 0" SIGINT
while true; do echo -n Na; sleep 0.1; done
class Command(object):
command_name = None
# ...
class FooCommand(Command):
command_name = "foo"
@ayust
ayust / gist:2360906
Created April 11, 2012 17:53
Re-center Stream in New G+ Theme
/*
Add this theme in Stylish or the like.
Set it for 'Pages on the domain plus.google.com'
*/
#contentPane > div {
text-align: center !important;
}
#contentPane > div > div > div {
Python 2.6.7 (r267:88850, Dec 2 2011, 20:27:26)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = -1
>>> b = -2
>>> hash(a) == hash(b)
True
>>> hash(a)
-2
>>> hash(b)
@ayust
ayust / bisect-merges.py
Created March 14, 2012 23:12
Git bisection across only mainline commits (a la git log --first-parent)
#!/usr/bin/env python
import json
import optparse
import os
import subprocess
import sys
def gitdir():