Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
mjgpy3 / lodash.md
Created April 23, 2016 02:30
Fun with Lodash
_.flow(
  _.castArray,
  _.partial(_.at, _, ['[0].id', '[0]']),
  _.spread(put)
)
@mjgpy3
mjgpy3 / comp_is_assoc.md
Created May 3, 2016 16:57
Brute-force composition is associative proof, lambda calc

Prelude

T1: B = (\f g x. f (g x))

Goal

(B a (B b c)) = (B (B a b) c)
@mjgpy3
mjgpy3 / map_filter_using_fold.js
Created June 1, 2016 21:30
Map/Filter implemented using Fold
var filter = function (xs, p) {
return xs.reduce(function (results, v) {
return results.concat(p(v) ? [v] : []);
}, []);
};
var map = function (xs, f) {
return xs.reduce(function (results, v) {
return results.concat([f(v)]);
}, []);
@mjgpy3
mjgpy3 / select-columns.py
Created August 6, 2016 18:00
Selecting columns
foo.py select-column.py X
values = [
[1, 10, 20, 30, 40],
[2, 10, 21, 31, 41],
[3, 11, 22, 32, 42],
[4, 10, 23, 33, 43],
]
def matches_10(row):
return row[1] == 10
@mjgpy3
mjgpy3 / group-by.py
Created August 6, 2016 18:01
Group By Python
from itertools import groupby
values = [
['1', 'r1', '100'],
['1', 'r2', '100'],
['1', 'r3', '105'],
['1', 'c1', '100']
]
def grouping_factor(row):
@mjgpy3
mjgpy3 / group-by-general.py
Created August 6, 2016 18:09
A better Python group by
def group_by(values, grouping_factor):
results = {}
for value in values:
key = grouping_factor(value)
if key in results:
results[key].append(value)
else:
results[key] = [value]
@mjgpy3
mjgpy3 / some-python-basics.py
Created August 10, 2016 01:45
Some Python Basics
print "hello world"
""" This is a multi-line comment... no it's not
int main() {
return 0;
}
"""
def main():
return 0
@mjgpy3
mjgpy3 / InheritAllThings.fs
Created March 11, 2017 23:00
F# Inheritance Example
type Person(name: string) =
member this.GetName () = name
type Employee(name: string, id: int) =
inherit Person(name)
member this.GetId () = id
member val Id = id with get, set
@mjgpy3
mjgpy3 / css.js
Created March 21, 2017 17:02
Perhaps a CSS Monoid
function Unstyled() {
this.append = function (other) {
return other;
};
this.empty = function () {
return new Unstyled();
};
this.$addLesserStyle = function (style, value) {
@mjgpy3
mjgpy3 / myPlusCommutes.idr
Created April 20, 2017 02:25
Plus Commutes
myPlusCommutes : (n : Nat) -> (m : Nat) -> n + m = m + n
myPlusCommutes Z Z = Refl
myPlusCommutes Z (S k) = rewrite plusZeroRightNeutral (S k) in Refl
myPlusCommutes (S k) Z = rewrite plusZeroRightNeutral (S k) in Refl
myPlusCommutes (S k) (S j) =
cong {f=S} (rewrite sym (plusSuccRightSucc k j) in (rewrite myPlusCommutes k j in (rewrite plusSuccRightSucc j k in Refl)))