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
@mlhaufe
mlhaufe / arith-bool.js
Created Jan 8, 2019
Booleans with arithmetic
View arith-bool.js
// x, y :: {0,1}
var and = (x,y) => x * y,
not = (x) => 1 - x,
or = (x,y) => 1 - (1 - x) * (1 - y)
and(0,0) // 0
and(0,1) // 0
and(1,0) // 0
and(1,1) // 1
@mlhaufe
mlhaufe / README.txt
Created Dec 10, 2018
A half assed, buggy implementation of a Tiny File System. Not useful for anything as is.
View README.txt
- The application is currently single threaded
- The following commands have been implemented:
- exit
- create <PATH>
- open <PATH>
- display
- ls
- cd <TFS> (partial)
- mkdir <TFS> (partial). currently buggy due to nibble manipulation
- import <PATH> <TFS> (partial) stub + error checking only
View hackathon-2016.ts
function main() {
console.log("question1(0) == 0");
console.assert(question1(0) == 0, `${question1(0)}`);
console.log("question1(1) == 1");
console.assert(question1(1) == 1, `${question1(1)}`);
console.log("question1(7) == 13");
console.assert(question1(7) == 13, `${question1(7)}`);
console.log("question1(12) == 144");
console.assert(question1(12) == 144, `${question1(12)}`);
View uMVC.ts
abstract class Observer {
abstract update(data?: any): void
}
abstract class Observable {
protected _observers: Observer[] = []
observe(observer: Observer) {
if (this._observers.indexOf(observer) > -1)
throw new Error('Observer already added')
View Maze.ts
abstract class Command {
abstract execute(): void
}
abstract class UndoableCommand extends Command {
abstract undo(): void
}
class Direction {
static readonly UP = 0
@mlhaufe
mlhaufe / Functional.ts
Last active Jun 12, 2018
The expression problem with Hutton’s Razor
View Functional.ts
// data
type Exp =
{ tag: 'Lit', value: number } |
{ tag: 'Add', left: Exp, right: Exp }
// operations
let evaluate = (exp: Exp) =>
exp.tag === 'Lit' ? exp.value :
evaluate(exp.left) + evaluate(exp.right)
@mlhaufe
mlhaufe / factory-test.ts
Last active Jan 30, 2018
TypeScript Factory type
View factory-test.ts
type Factory<T extends { kind: string }> = {
// Can we do better than (...args: any[]) ?
readonly [P in T['kind']]: (...args: any[]) => T
}
type Bool = { kind: 'False' } | { kind: 'True' }
let BoolFactory: Factory<Bool> = {
False() { return { kind: 'False' } },
True() { return { kind: 'True' } }
@mlhaufe
mlhaufe / OAlgPeano.ts
Created Jan 27, 2018
ObjectAlgebra Peano Numbers
View OAlgPeano.ts
interface PeanoAlg<T> {
Zero(): T
Succ(pred: T): T
}
type PeanoData = { kind: "Zero" } | { kind: "Succ", pred: PeanoData }
let peanoFactory: PeanoAlg<PeanoData> = {
Zero(): PeanoData { return { kind: "Zero" } },
Succ(pred: PeanoData): PeanoData { return { kind: "Succ", pred} }
}
@mlhaufe
mlhaufe / file-path-clean.ps1
Created Jul 20, 2017
DropBox -> OneDrive file name validation test
View file-path-clean.ps1
$srcPath = 'C:\..\dropbox-location'
$targetPath = 'D:\..\OneDrive-Location
$items = Get-ChildItem -Path $srcPath -Recurse
$regex = [regex] '[^\p{IsBasicLatin}]|[#%()]|^\s|\s$'
$items | %{
if($regex.IsMatch($_.Name)) {
Write-Host -fore red $_.FullName
}
}
You can’t perform that action at this time.