Skip to content

Instantly share code, notes, and snippets.

View wmayner's full-sized avatar

William Mayner wmayner

View GitHub Profile
@wmayner
wmayner / random_cut_timer.py
Created March 15, 2017 01:33
Evaluating a random cut vs. other PyPhi functions
import json
import os
import pickle
import random
from time import time
import numpy as np
import pyphi
from pyphi import Network, Subsystem
@wmayner
wmayner / slate-bindings.md
Last active December 5, 2018 19:31
Short guide to using my Slate keybindings

Slate bindings

Window focus

  • Pressing Ctrl + Esc (or Ctrl + Caps Lock if you have Caps Lock mapped to Esc) will put a “window hint” at the center of every currently visible window.
  • These will each have a unique letter in them.
  • Pressing a letter will focus that window.
  • Pressing Esc will cancel the window hints.

Window movement/resizing

@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.