Skip to content

Instantly share code, notes, and snippets.

View Flushot's full-sized avatar
👀

Chris Lyon Flushot

👀
View GitHub Profile
#!/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
@Flushot
Flushot / ps1.sh
Last active September 21, 2018 02:41
PS1
__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\]"
@Flushot
Flushot / .emacs
Last active May 10, 2021 00:06
Emacs config
;; -*- mode: elisp -*-
;; Chris' emacs file
;; Enable transient mark mode
(transient-mark-mode 1)
;; Enable org-mode
(require 'org)
;; default directory: ~/projects/
@Flushot
Flushot / github_link_graph.py
Last active September 17, 2015 22:47
Builds a graph visualization (viewable in yEd) of linked pages in a GitHub wiki repository
@Flushot
Flushot / json_decode_ex.php
Created June 2, 2015 01:53
Improved version of json_decode that throws on decode failures and uses more sane defaults
/**
* 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) {
@Flushot
Flushot / worker.py
Last active August 29, 2015 14:21
Multithreaded queue worker
from abc import ABCMeta, abstractmethod
import logging
import multiprocessing
import threading
import time
try:
import queue
except ImportError:
import Queue as queue
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
@Flushot
Flushot / html_builder.php
Last active August 29, 2015 14:17
HTML builder for PHP
<?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.
*
@Flushot
Flushot / Makefile
Created March 11, 2015 21:32
Python+flask+sqlalchemy microservice boilerplate
.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
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)