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 / regex-find-replace-sublime
Last active August 29, 2015 14:13
Sublime global find + replace regex
(notice space at the end of each!)
Find: ([a-zA-Z]+)='(.+)'
Replace with: \1="\2"
Fixes any single quote ids/classes/html attributes (eg. name='foo-bar' -> name="foo-bar", name='{{ foo._bar(bim) }}' -> name="{{ foo._bar(bim) }}")
@christabor
christabor / sublime git editor mac
Created February 3, 2015 17:42
Fix Sublime git editor association (mac)
# Fallback for this issue, when using
# http://www.sublimetext.com/docs/3/osx_command_line.html and https://help.github.com/articles/associating-text-editors-with-git/
# `subl -n -w: subl: command not found`
# `error: There was a problem with the editor 'subl -n -w'.`
# `Please supply the message using either -m or -F option.`
git config --global core.editor "subl -n -w" || git config --global core.editor "~/bin/subl -n -w"
@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 / 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