Skip to content

Instantly share code, notes, and snippets.

View mlms13's full-sized avatar
⚗️

Michael Martin mlms13

⚗️
View GitHub Profile
@mlms13
mlms13 / keybase.md
Last active December 1, 2017 17:37

Keybase proof

I hereby claim:

  • I am mlms13 on github.
  • I am mulmus (https://keybase.io/mulmus) on keybase.
  • I have a public key ASC1pfTBJTZEjJ8xXbxWGMnKwv5AyUjTCKvxW90-0NN3sgo

To claim this, I am signing this object:

static var coins = [4, 3, 1];
var computed = new Map(); // cache already-solved target amounts
// return the minimum number of coins needed to make change for the
// given target amount, using the list of coins above. Returns `None`
// for requests that don't make sense (target < smallest coin)
// break it into all possible sub-problems, and cache the result from computing those
// did i do it? is this dynamic programming?
function makeChange(target: Int, count: Int): Option<Int> {
return switch computed.getOption(target) {
@mlms13
mlms13 / postgresql_color_adt.sql
Last active September 19, 2017 02:32
Create a sum type for colors in sql
-- data NamedColor = Red | Green | Blue
-- data CustomColor = CustomColor
-- { r :: Int
-- , g :: Int
-- , b :: Int
-- }
-- data Color = NamedColor | CustomColor
create type custom_color as (r int, g int, b int);
@mlms13
mlms13 / brackets.hx
Last active May 11, 2017 20:45
Balanced Brackets
function match(arr: Array<ParenToken>, leftCount = 0): Bool {
return switch arr.getOption(0) {
case None: leftCount == 0;
case Some(LeftParen): match(arr.tail(), leftCount + 1);
case Some(RightParen): leftCount <= 0 ? false : match(arr.tail(), leftCount - 1);
};
}
function tokenize(str: String): Array<ParenToken> {
#! /usr/bin/env bash
color_black='\033[0;30m'
color_red='\033[0;31m'
color_green='\033[0;32m'
color_yellow='\033[0;33m'
color_blue='\033[0;34m'
color_purple='\033[0;35m'
color_cyan='\033[0;36m'
color_gray='\033[0;37m'
@mlms13
mlms13 / flat-to-tree.js
Last active April 29, 2016 17:17
Collect a flat array of objects as nested map
var flat = [
{ id: "A", name: "A", parent: "" },
{ id: "B", name: "B", parent: "" },
{ id: "C", name: "C", parent: "D" },
{ id: "D", name: "D", parent: "B" },
{ id: "E", name: "E", parent: "A" }
];
function unflatten(list) {
return; //...
var sections = [{
id: "A",
flag: false,
subsections: [{
id: "A1",
subsections: [{
id: "A1a",
flag: true
}, {
id: "A1b"
@mlms13
mlms13 / lovefield.d.ts
Created November 22, 2015 05:41
Typescript definition file for Lovefield. I didn't make this.
// Type definitions for Lovefield v2.0.62
// Project: http://google.github.io/lovefield/
// Definitions by: freshp86 <https://github.com/freshp86>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts"/>
declare module lf {
export enum Order { ASC, DESC }
// get names and ratings for BFZ cards from ChannelFireball
function getRatings() {
var list = [].slice.apply($('.postContent h1').not(":first").not(":last"));
return list.map(function(el) {
var rating = $(el).next().next().clone().find("b").remove().end().text()
return {
name: el.textContent,
rating: parseFloat(rating)
};
});
@mlms13
mlms13 / uphxlib.fish
Last active August 29, 2015 14:26
Update haxelib dev repos in fish-shell
function uphxlib
# upgrade normal haxe repositories
echo 'a' | haxelib upgrade
# keep track of the current directory
set current_dir (pwd)
# update all 'dev' repo git repositories
for lib in (haxelib list | cut -d: -f2- | grep 'dev:')
set dev_dir (echo $lib | rev | cut -c 2- | rev | cut -d '[' -f2- | cut -c5-)