This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
lines="-\|/" | |
i=0 | |
while : ; do | |
printf "\r\033[5mReticulating splines\033[25m %s" ${lines:$i:1} | |
i=$(((i + 1) % 4)) | |
sleep 0.5 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__git_ps1 () | |
{ | |
local b="$(git symbolic-ref HEAD 2>/dev/null)"; | |
if [ -n "$b" ]; then | |
printf " (%s)" "${b##refs/heads/}"; | |
fi | |
} | |
export PS1="\[\033[0;32m\][\D{%H:%M}] \[\033[0;32m\]\h:\[\033[0;33m\]\w\[\033[35m\]\$(__git_ps1) \[\033[0;36m\]\u\\$ \[\033[0m\]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- mode: elisp -*- | |
;; Chris' emacs file | |
;; Enable transient mark mode | |
(transient-mark-mode 1) | |
;; Enable org-mode | |
(require 'org) | |
;; default directory: ~/projects/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
import sys | |
import networkx as nx | |
import lxml.etree as et | |
def walk_path(start_path, match_regex=r'.*', recursive=True): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A more sane version of json_decode() | |
* | |
* @param $json | |
* @param $assoc when TRUE, json will be decoded as an associative array instead of an object. | |
* @param $depth max stack depth for recursion. | |
* @throws DomainException when parsing failed. | |
* @return the decoded value as an associative array or object (depending on what $assoc was set to). | |
*/ | |
function json_decode_ex($json, $assoc=true, $depth=512) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABCMeta, abstractmethod | |
import logging | |
import multiprocessing | |
import threading | |
import time | |
try: | |
import queue | |
except ImportError: | |
import Queue as queue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dfs_visit_key(tree, key_re, visitor_fn): | |
return dfs_walk(tree, \ | |
lambda k, fk, val: \ | |
visitor_fn(fk, val) \ | |
if re.match(key_re, '.'.join(fk)) \ | |
else val) | |
def dfs_walk(tree, visitor_fn, fullkey=None): | |
fullkey = list(fullkey or []) | |
if isinstance(tree, dict): # subtree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* HTML builder | |
* @author Chris Lyon <[email protected]> | |
* | |
* This functional HTML builder was inspired by JSX and eliminates the need to use the unsightly | |
* and error-prone string concatenation method of building HTML markup. You can now cleanly use | |
* nested functions as children and associative arrays as tag attributes. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: deps | |
all: deps | |
PYTHONPATH=.venv ; . .venv/bin/activate | |
.venv: | |
if [ ! -e ".venv/bin/activate_this.py" ] ; then virtualenv --clear .venv ; fi | |
deps: .venv | |
PYTHONPATH=.venv ; . .venv/bin/activate && .venv/bin/pip install -U -r requirements.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import random | |
from bisect import bisect | |
def weighted_choice(choices): | |
values, weights = zip(*choices) | |
total = 0 | |
cum_weights = [] | |
for w in weights: | |
total += w | |
cum_weights.append(total) |