Skip to content

Instantly share code, notes, and snippets.

@bperel
bperel / levenshtein.js
Last active April 23, 2017 14:10 — forked from andrei-m/levenshtein.js
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
// https://gist.github.com/andrei-m/982927#gistcomment-1931258 looks like the fastest Levenshtein implementation
const levenshtein = (a, b) => {
if (a.length === 0) return b.length
if (b.length === 0) return a.length
let tmp, i, j, prev, val
// swap to save some memory O(min(a,b)) instead of O(a)
if (a.length > b.length) {
tmp = a
a = b
b = tmp
@bperel
bperel / mysqldump_pre_commit_hook.bash
Last active December 31, 2015 23:29 — forked from nuclearsandwich/mysqldump_pre_commit_hook.bash
Support table filtering and custom MySQL path, removes the "Dump completed on..." line
#!/bin/bash
# Pre-commit hook to make a mysql dump right before committing and add it to the commit.
#
## Change the following values to suit your local setup.
# The name of a database user with read access to the database.
#Uncomment if mysqldump is not in your path
#MYSQLPATH=c:/wamp/bin/mysql/mysql5.5.24/bin
#Comment if mysqldump is in your path
#!/bin/bash
# Pre-commit hook to make a mysql dump right before committing and add it to the commit.
#
## Change the following values to suit your local setup.
# The name of a database user with read access to the database.
DBUSER=root
# The password associated with the above user. Leave commented if none.
#DBPASS=seekrit
# The database associated with this repository.
DBNAME=dplay
@bperel
bperel / composite.js
Last active December 17, 2015 08:29 — forked from anonymous/composite.js
var force = d3.layout.force()
.gravity(0.2)
.charge(-150)
.linkDistance(300)
.size([800, 600]);
var svg = d3.select("body").append("svg:svg")
.attr("id","graph")
.attr("width", 800)
.attr("height", 600);