Skip to content

Instantly share code, notes, and snippets.

@svanellewee
svanellewee / Vagrantfile
Last active December 25, 2015 03:48
Vagrant Docker Provision
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@svanellewee
svanellewee / List monad.py
Last active November 14, 2015 22:15
List monad continued.. again
'''
Remember the bind operator's signiture:
Ma -> (a -> Mb) -> Mb
This means that
given a List(type a) and a function that takes each item a in the list and turns EACH ITEM into a List(type b)
and returns a List(type b)... not a List of List(type b)'s.. hence why you need a concat.
'''
'''
data List a = Nil | Cons a (List a)
@svanellewee
svanellewee / regex-elisp.el
Last active November 10, 2015 21:44
regex elisp example
(progn
(switch-to-buffer-other-window "*output*")
(erase-buffer)
(switch-to-buffer-other-window "*input*")
(erase-buffer )
;;(insert-file-contents "~/workspace/exampledata/ingramfull.sh")
(insert "get \"/ebook/front/archive/0071386556.jpg\" \"./images/downloads/9780071386555-003-unprocessed.jpg\"\n")
(insert "get \"/ebook/front/archive/0071483438.jpg\" \"./images/downloads/9780071483438-029-unprocessed.jpg\"\n")
(goto-char (point-min))
@svanellewee
svanellewee / lisp.py.again.py
Last active October 30, 2015 19:54
lisp again.. revisited. NIL is an ATOM! Also only got to just before lambda and label.
# (cons nil nil)
# (car '(nil))
# nil
# (cdr '(nil))
# nil
# (car '())
# nil
# (cdr '())
# nil
@svanellewee
svanellewee / lispy.py
Created October 24, 2015 20:34
python demo of lisp from first principles... (http://www-formal.stanford.edu/jmc/recursive.pdf)
# (m) --> (m . NIL)
# (m1, m2.. mn) --> (m1 . ( m2 . ( ... ( .. ( mn . NIL) ))))
# (m1 , m2..mn . x) ---> (m1 . ( m2 . ( ... ( .. ( mn . x) ))))
Nil = None
def atom(value):
'''
1. atom. atom[x] has the value of T or F according to whether x is an
atomic symbol. Thus
atom [X] = T
# From https://www.fpcomplete.com/school/starting-with-haskell/basics-of-haskell/13-the-list-monad
from functools import partial
'''
okay let's try working from first principles first!
'''
def ACons(head, tail):
return lambda fn: fn(head, tail)
@svanellewee
svanellewee / Reader Writer Monads.py
Created September 21, 2015 21:40
Reader Writer Monads.. with a little monoid theory thrown in...
# class Monoid m where
# mempty :: m
# mappend :: m -> m -> m
# mconcat :: [m] -> m
# mconcat = foldr mappend mempty
class MonList(object):
@classmethod
def mappend(cls, a, b):
return a + b
@svanellewee
svanellewee / pymonad.py
Last active November 5, 2017 06:20
Python Monad zoo!
# def bind(value, fn):
# return fn(value)
# print bind ( 12, lambda x :
# bind ( 13, lambda y :
# lambda x,y :x+y))()
# def maybe_bind(value, fn) :
# return fn(value) if value else None
@svanellewee
svanellewee / functorhackery.js
Last active August 29, 2015 14:25
Functors just take stuff out of "type-boxes" apply a function and put them back into the same "type-boxes".
/*
*
* Functor :
* fmap : (a -> b) -> fa -> fb
*
*/
function array_fmap1(fn, typeA) {
var typeB = []
typeA.forEach(function(aVal) {
@svanellewee
svanellewee / mongodb node.js stream.js
Created July 4, 2015 22:05
Node js streams with mongo and filter transforms! note the ???ObjectMode settings!
var mongodb = require("mongodb");
var MongoClient = mongodb.MongoClient;
var fs = require("fs");
var Transform = require("stream").Transform;
var name_surname_email_filter = new Transform({readableObjectMode:true, writableObjectMode:true} );
name_surname_email_filter._transform = function(data, enc, cb) {
//console.log(data);
var newdata = { first_name: data.first_name,