Skip to content

Instantly share code, notes, and snippets.

View wmayner's full-sized avatar

William Mayner wmayner

View GitHub Profile
@wmayner
wmayner / OrbitControls.js
Last active January 25, 2018 14:48
Fork of three.js Orbit Controls that allows binding its event handlers to arbitrary elements, rather than just the given `domElement`. Useful when adding sibling DOM elements to the canvas, e.g. labels for objects.
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
/*global THREE, console */
// This set of controls performs orbiting, dollying (zooming), and panning. It maintains
@wmayner
wmayner / index.html
Last active August 29, 2015 14:13 — forked from tmcw/index.html
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
body { margin:0; padding:0; }
#map { width:960px; height:500px; background:cyan; }
</style>
</head>
<body>

The Tao of Unix

  1. Rule of Modularity: Write simple parts connected by clean interfaces.
  2. Rule of Clarity: Clarity is better than cleverness.
  3. Rule of Composition: Design programs to be connected to other programs.
  4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  5. Rule of Simplicity: Design for simplicity; add complexity only where you must.
  6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
  7. Rule of Transparency: Design for visibility to make inspection and debugging easier.
@wmayner
wmayner / why_numbering_should_start_at_zero.md
Created July 31, 2014 17:19
Another reason why numbering should start at zero

Why numbering should start at zero

Elaborating on the reasons given in Dijkstra's memo on the topic, we observe the following:

1-based indexing

  • Ranges are of the form 1 ≤ i < N + 1.
  • The last element of a sequence has index N.
@wmayner
wmayner / normalize_cm.py
Last active August 29, 2015 14:01
A small function for rendering a connectivity matrix into a normal form.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from itertools import permutations
def normalize_cm(connectivity_matrix):
"""Render a square connectivity matrix into a normal form.
@wmayner
wmayner / lru_cache.py
Created May 5, 2014 20:58
[Python] Memory-aware LRU cache decorator
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Memory-aware LRU Cache function decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A modification of the builtin ``functools.lru_cache`` decorator that takes an
additional keyword argument, ``use_memory_up_to``. The cache is considered full
if there are fewer than ``use_memory_up_to`` bytes of memory available.
@wmayner
wmayner / fliptest.sh
Created April 25, 2014 21:07
Python: timing various ways of flipping bits in a binary string
#!/env/sh
# Test various ways of flipping '1's and '0's in a Python binary string.
TEST="'111101111010001000100100001'"
TESTINT="129831201"
echo "Bit manipulation given decimal int:"
PYSTRING="i = $TESTINT; bin((i ^ (2 ** (i.bit_length()+1) - 1)))[3:]"
echo "$PYSTRING\n"
@wmayner
wmayner / README.md
Last active December 29, 2015 09:38 — forked from agnoster/README.md

wmayner.zsh-theme

Forked from @agnoster's zsh theme. Incorporates changes from @smileart's fork.

Modifications in this fork:

  • The current path is right aligned, so it's out of the way when working in deeply nested directories. The main, left-aligned prompt only the current directory's name.
@wmayner
wmayner / stackoverflow.alfredworkflow
Created July 9, 2013 20:31
StackOverflow workflow for Alfred, derived from http://www.alfredforum.com/topic/1524-stackoverflow-workflow/. This version shows when the question was asked in human-readable format instead of just an actual date.
import json, StringIO, gzip, alfred, urllib, urllib2, datetime, time
def voiteImg(votes):
if votes < 0:
imgStr = 'so--1.png'
elif votes == 0:
imgStr = 'so-0.png'
elif votes >0 and votes <10:
imgStr = 'so-1-1.png'
elif votes >= 10 and votes <50:
@wmayner
wmayner / .vimrc.bundles.local
Created November 15, 2012 19:39
Additional bundles installed in addition to spf13 default bundles
" original github repos
Bundle 'wincent/Command-T'
Bundle 'sjl/gundo.vim'
Bundle 'tpope/vim-abolish'
Bundle 'tpope/vim-commentary'
Bundle 'digitaltoad/vim-jade'
Bundle 'tpope/vim-repeat'
Bundle 'tpope/vim-speeddating'
Bundle 'tpope/vim-unimpaired'
Bundle 'kchmck/vim-coffee-script'