Skip to content

Instantly share code, notes, and snippets.

Michael Haufe mlhaufe

Block or report user

Report or block mlhaufe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View queryStrings.js
function queryStrings(){
var out = {};
if(typeof location != 'undefined'){
var temp = location.search||location.href||'';
var nvp, ofSet;
if((ofSet = temp.indexOf('?')) > -1){
temp = temp.split("#")[0];
temp = temp.substring((ofSet+1), temp.length);
var workAr = temp.split('&');
for(var c = workAr.length;c--;){
@mlhaufe
mlhaufe / makeChange.js
Created Apr 9, 2014
Greedy Change Making Algorithm
View makeChange.js
var qapik = [50,20,10,5,3,1],
usCoins = [25,10,5,1];
//denominations (ds) must be in descending order
function makeChange(coins,ds){
var result = {}
for(var i = 0, d = ds[i]; i < ds.length; d = ds[++i]){
result['n'+d] = Math.floor(coins/d) // a div d
coins = coins % d
}
@mlhaufe
mlhaufe / maxSubsequence.js
Created Apr 16, 2014
Max Subsequence Sum
View maxSubsequence.js
var xs = [-4,-3,-7,+2,+1,-1,-4], //[2,1] = 3
ys = [-2,11,-4,13,-5,-2], //[11,-4,13] = 20
zs = [5,15,-30,10,-5,40,10,-8] // [...] = 55
function sum(j,as){
var max = Math.max;
function tabulate(i,runMax,curMax){
if(i > j) return curMax
var newMax = max(runMax+as[i],as[i])
return tabulate(i + 1, newMax, max(curMax,newMax))
@mlhaufe
mlhaufe / countInversions.js
Created Apr 16, 2014
Count inversions in an array
View countInversions.js
function countInversions(xs){
var count = 0;
function mergeSort(xs){
var size = xs.length
if (size < 2) return xs
var mid = Math.floor(size / 2),
left = xs.slice(0, mid),
right = xs.slice(mid)
@mlhaufe
mlhaufe / TFS1
Last active Aug 29, 2015
Tiny File System
View TFS1
04425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E2500000004425248450000000000001E25000000
@mlhaufe
mlhaufe / AD.cs
Created Jul 17, 2014
Active Directory from LINQPad
View AD.cs
var searchRoot = new System.DirectoryServices.DirectoryEntry(
@"LDAP://server:389/DC=foo,DC=com",
@"DOMAIN\USERNAME",
"PASSWORD"
){ AuthenticationType = AuthenticationTypes.ReadonlyServer };
using(var searcher = new System.DirectoryServices.DirectorySearcher(searchRoot)) {
searcher.Filter = "(&(objectCategory=group))";
var results = searcher.FindAll();
results.Dump();
View click-through.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Click-Through Circle</title>
<style type="text/css">
html, body{
margin:0;
padding:0;
}
@mlhaufe
mlhaufe / Bool.lps
Last active Aug 29, 2015
Lapis Design Notes
View Bool.lps
module
exports Bool
protocol Bool
False
True
and Bool => Bool
or Bool => Bool
not => Bool
View sudoku.pl
insert(X, Xs, [X|Xs]).
insert(E, [X|Xs], [X|Ys]) :- insert(E,Xs,Ys).
permute([],[]).
permute(L,[H|T]) :- insert(H,R,L), permute(R,T).
sudoku([[X11,X12,X13,X14,X15,X16,X17,X18,X19],
[X21,X22,X23,X24,X25,X26,X27,X28,X29],
[X31,X32,X33,X34,X35,X36,X37,X38,X39],
[X41,X42,X43,X44,X45,X46,X47,X48,X49],
View pathfinding.pl
adjacent(ems,phy).
adjacent(ems,soccer).
adjacent(soccer,cunn).
adjacent(ems,chem).
adjacent(chem,lap).
adjacent(lap,bridge).
adjacent(lap,arch).
adjacent(arch,engel).
adjacent(cunn,engel).
adjacent(bridge,union1).
You can’t perform that action at this time.