Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
Bug hunting 🎯

Simon Richardson SimonRichardson

👻
Bug hunting 🎯
View GitHub Profile
@graphnode
graphnode / levenshtein.js
Created May 18, 2011 23:09
levenshtein function in javascript
function levenshtein(s1, s2) {
// http://kevin.vanzonneveld.net
// + original by: Carlos R. L. Rodrigues (http://www.jsfromhell.com)
// + bugfixed by: Onno Marsman
// + revised by: Andrea Giammarchi (http://webreflection.blogspot.com)
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + reimplemented by: Alexander M Beedie
// * example 1: levenshtein('Kevin van Zonneveld', 'Kevin van Sommeveld');
// * returns 1: 3
@andrei-m
andrei-m / levenshtein.js
Last active October 9, 2024 10:36
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@rantav
rantav / README.md
Created August 23, 2012 06:13
Find slow queries in mongo DB

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

@luciferous
luciferous / README.md
Created September 29, 2012 13:11
Do-notation in Javascript

do.js

An experimental Javascript library that can be used for asynchronous control flow, non-determinism, parsing, and other kinds of computations which implement the interface:

bind :: m a -> (a -> m b) -> m b
return :: a -> m a

This gist is a temporary living situation for do.js, and will most likely be expanded into a full blown Github repository in the future.

@puffnfresh
puffnfresh / do.sjs
Created October 4, 2012 04:40
do-notation using sweet.js
macro $do {
case { $y:expr } => {
$y
}
case { $x:ident <- $y:expr $rest ... } => {
λ['>=']($y, function($x) {
return $do { $rest ... }
});
}
}
@puffnfresh
puffnfresh / binary.js
Created October 10, 2012 02:23
Safe ad-hoc polymorphism in JavaScript via bilby.js
var lib = require('./lib'),
λ = lib.method('show', lib.isNumber, function(n) {
return n.toString(2);
});
exports.showBinaryTimesTwo = λ.bind(λ.showTimesTwo)(λ);
@jlongster
jlongster / gist:3881008
Created October 12, 2012 19:28
js destructuring macro
// Note: there are bugs in hygienic renaming, so this doesn't work all the time yet.
macro varr {
case [$var (,) ...] = $expr => {
var i = 0;
var arr = $expr;
$(var $var = arr[i++];) ...
}
@dpeek
dpeek / gist:3984469
Last active October 12, 2015 06:27
Building Neko and Haxe from Source on OS X 10.8

Requirements

  • OS X Mountain Lion (10.8.1)
  • XCode 4.5.1 with "Command Line Tools" installed in Preferences > Downloads > Components
  • MacPorts Mountain Lion installer.

Install dependencies: (you might want a grab a coffee)

sudo port install boehmgc pcre mysql5 ocaml
@puffnfresh
puffnfresh / objectunion.js
Last active December 12, 2015 02:28
Creation of unions, with automatic value constructors and an automatic fold encoding.
// Boilerplate
function objectUnion(definer) {
var defined = 0, length = 0, isDefined = false, definitions, key;
definitions = definer(function() {
var names = arguments, fold;
if(isDefined) {
throw new TypeError('This objectUnion has already been defined');
}
function Ctor() {}
@drewolson
drewolson / reflection.go
Last active August 25, 2024 18:35
Golang Reflection Example
package main
import (
"fmt"
"reflect"
)
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`