Skip to content

Instantly share code, notes, and snippets.

View christabor's full-sized avatar
😅
I may be slow to respond.

Chris Tabor christabor

😅
I may be slow to respond.
View GitHub Profile
@christabor
christabor / gist:8e042a20b91e4f0944e4
Created March 14, 2015 11:13
levenshtein visualization python
A visualization of perhaps the most inefficient algorithm - the recursive Levenshtein distance.
ks
ksi |
ksit ___/
ksitt ____/
ksitti _____/
ksittin ______/
ksitting _______/
@christabor
christabor / gist:90cbcbbfa6725256a314
Created March 14, 2015 11:34
Super inefficient Levenshtein distance (recursive) pt 2 (python)
Better recursion tree visualization
\____cd
cdo___/
cdog____/
cdoge_____/
\____cd
cdo___/
cdog____/
\____cd
@christabor
christabor / ag + xargs open function
Created April 9, 2015 01:30
Search and open files in sublime using ag
function agFileSearch() {
ag "$1" -l | xargs open
}
alias agfiles='agFileSearch'
# .. usage:
# agfiles 'mytext'
@christabor
christabor / declarative datatables
Created April 21, 2015 18:49
Declarative datatables
$('[data-datatable]').each(function(k, table){
// data_vars is a json encoded string embedded in html as a
// data-* attribute. This allows declarative programming with complex
// overrides, without coupling to the javascript.
var data_vars = $(this).data('datatable-opts');
var opts = $.extend(window.DATATABLES_OPTS, data_vars);
$(this).dataTable(opts);
});
@christabor
christabor / w3c color
Created June 5, 2015 16:27
w3c color recommendation algo
function checkVisibility(color1, color2) {
// http://www.w3.org/TR/AERT#color-contrast
// Color brightness is determined by the following formula:
// ((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
// Note: This algorithm is taken from a formula for converting RGB values to
// YIQ values. This brightness value gives a perceived brightness for a color.
@christabor
christabor / gist:e3f7ede5c0a86a97a5b1
Created July 1, 2015 04:20
namebot + random words
from namebot import techniques as nb
from random_words import RandomWords
# https://pypi.python.org/pypi/RandomWords/0.1.5
rw = RandomWords()
# https://github.com/Automotron/namebot
test = rw.random_words(count=10)
print(nb.make_portmanteau_default_vowel(test))
@christabor
christabor / catalan_numbers
Last active August 29, 2015 14:24
Catalan numbers
# https://en.wikipedia.org/wiki/Catalan_number
import math
prod = 1
for n in range(2, 100):
prod = math.factorial((2 * n)) // (
math.factorial((n + 1)) * math.factorial(n))
print(prod)
@christabor
christabor / railfence-python
Last active August 29, 2015 14:24
railfence cipher
https://github.com/christabor/MoAL/blob/master/MOAL/maths/applied/computational/cryptography/ciphers/historical/transposition/railfence.py
Encoded with 2 rows: IAEVRBGERTHVAEYISCE
I . V . V . Y . G . C . T
H . E . E . B . S . R
A . A . R . I . E . E
Encoded with 3 rows: IVVYGCTHEEBSRAARIEE
I . E . R . G . R
@christabor
christabor / random_timeseries.py
Created August 12, 2015 04:27
Random time series warping
from random import randrange as rr
# Use with: http://mlpy.sourceforge.net/docs/3.5/dtw.html#id3
def random_timesequence(start, end, steps=3):
seq = []
for n in range(start, end):
# Randomize the number of sub-steps,
# but maintain the bounds and monotonicity
@christabor
christabor / pynames.py
Created August 13, 2015 05:02
Python library names
vowels = ['a', 'e', 'i', 'o', 'u']
with open('/usr/share/dict/words') as words:
_words = []
with open('/Users/ctabor/Desktop/words.txt', 'wb+') as wordfile:
for word in words:
if len(word) > 3 and len(word) < 8:
word = word.strip().lower()
if word[1] in vowels:
if word[2] in vowels: