Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
mlhaufe / combobox.html
Created January 26, 2012 03:07
HTML Combo box
<!doctype html>
<html>
<!-- Reference: <https://groups.google.com/group/comp.lang.javascript/browse_thread/thread/1f5810b6d34c8d50#> -->
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<select onchange="this.nextSibling.value = this.value;this.nextSibling.focus()" style="width:2em;margin-left:2em;vertical-align:top;height:1.5em" id="opt">
<option value=""></option>
@mlhaufe
mlhaufe / merge.sml
Last active July 12, 2017 21:57
SML merge sort
datatype 'a tree = Empty | Node of {l:'a tree, x: 'a, r: 'a tree}
type 'a set = ('a * 'a -> bool) * 'a tree
(* Note to self: next time I think an AVL tree is a good idea,
place head in microwave until the thought goes away... *)
fun makeBST cmp vs = let
fun half ls = length ls div 2;
fun mergesort [] = []
| mergesort [x] = [x]
@mlhaufe
mlhaufe / vector.sml
Created February 9, 2012 19:41
SML Vectors
type vector = real list;
fun map2 (f1 : 'a * 'b -> 'c) (f2 : 'a -> 'c) (f3 : 'b -> 'c) (xs : 'a list) (ys : 'b list) =
let
fun m2 [] [] = []
| m2 xs [] = f2 (hd xs) :: m2 (tl xs) []
| m2 [] ys = f3 (hd ys) :: m2 [] (tl ys)
| m2 xs ys = f1 (hd xs, hd ys) :: m2 (tl xs) (tl ys)
in
m2 xs ys
@mlhaufe
mlhaufe / language.sml
Created October 24, 2012 16:53
Trivial Language w/ Memory
datatype expr = LIT of int
| PLUS of expr * expr
| TIMES of expr * expr
| VAR of string;
datatype stmt = SKIP
| ASSIGN of string * expr
| SEQ of stmt * stmt
| PRINT of expr
| IFPOS of expr * stmt * stmt
@mlhaufe
mlhaufe / uppercase.s
Created October 28, 2012 19:08
Uppercase
# $t0 = index
# $t1 = character
# $t2 = ASCII 97 'a'
# $t3 = ASCII 122 'z'
# $t4 = string length
# $t5 = ASCII difference
# $t6 = ASCII 10 '\n'
# $t7 = maxlen
.data
promptString: .asciiz "\nEnter a string <= 20 characters in length (Empty string to exit): "
@mlhaufe
mlhaufe / palindrome.s
Created October 28, 2012 19:09
Case insensitive Palindrome Checker
######################################
# Case insensitive Palindrome Checker
######################################
# Register Usage
# $t0 = index
# $t1 = character
# $t2 = ASCII 97 'a'
# $t3 = ASCII 122 'z'
# $t4 = string length
# $t5 = ASCII difference
@mlhaufe
mlhaufe / dynFib.js
Last active February 7, 2017 19:38
Dynamic Programming with Fibonacci
//More info: <https://thenewobjective.com/blog/2013/01/dynamic-programming-for-great-justice/>
// Imperative: O(n) time, O(1) space
function fib(n){
if(n < 2)
return n;
var f0 = 0, f1 = 1, f;
for(var i = 1; i < n; i++){
@mlhaufe
mlhaufe / CS535_HW6_1.html
Created December 6, 2012 08:38
CS535 HW6
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript;version=1.8">
"use strict"
function Range(low, high){
if(!(this instanceof Range))
return new Range(low,high)
this.low = low;
function trampoline(f) {
while (typeof f === "function") f = f();
return f;
}
function fib(n){
function f(n0,n1,step){
return step == n ? n1 : function() { return f(n1, n0 + n1, step +1) }
}
return trampoline(f(0,1,1))
@mlhaufe
mlhaufe / compOp.js
Last active December 15, 2015 12:49
Using fake operator overloading to simulate function composition
Function.prototype.valueOf = function(){
id.fs.push(this)
}
function id(){
var fs = []
function f(x){
for(var i=0,len=fs.length,v=x;i<len;v=fs[i++](v));
return v
}