This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Stolen from "Structure and Interpretation of Computer Programs" | |
;https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html#%_sec_3.1.1 | |
;Implementation: | |
;--------------- | |
(define (make-account balance) | |
;withdraw method: | |
(define (withdraw amount) | |
(if (>= balance amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A function that rotates a 2-dimensional array by 90 degrees. | |
> _([ | |
[1, 2, 3], | |
[1, 2, 3], | |
[1, 2, 3] | |
]).rotate().value() | |
[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" A handy mapping for debugging node.js applications from vim using the node build-in debugger. | |
" Add the following mapping to your .vimrc file: | |
nnoremap <C-D> Odebugger<esc>:w<CR>:!node debug %:p <CR>dd:w<CR> | |
" Now in vim, go to the place where you want to break and press Ctrl + D. | |
" This inserts a 'debugger' statement, at your current line and launches the file in debug mode. | |
" You can also combine this with a testing framework like nodeunit: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode | |
" inoremap | |
" Description: A minimal, but feature rich, example .vimrc. If you are a | |
" newbie, basing your first .vimrc on this file is a good choice. | |
" If you're a more advanced user, building your own .vimrc based | |
" on this file is still a good idea. | |
"------------------------------------------------------------ | |
" Features {{{1 | |
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A function for integrating D3 and React. | |
* | |
* Receives a reusable D3 chart as per https://bost.ocks.org/mike/chart/. | |
* | |
* Returns a React component which Renders the chart and updates it | |
* using the 'data' property from its 'props' object. | |
*/ | |
// IMPLEMENTATION: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { dropWhile } = require('lodash') | |
const parser = { | |
of: (value) => Parser((_) => ({value, string:''})), | |
chain(f) { | |
return Parser((prevString) => { | |
const { value, string, error} = this.parse(prevString) | |
return error === undefined ? f(value).parse(string) : {error, value} | |
}) | |
}, | |
andThen(next) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { adt, object } = require('./core') | |
const Free = adt.data('Free', { | |
Pure: (value) => ( { value } ), | |
Impure: (value, func) => ( { value, func } ) | |
}).derive(adt.show) | |
const { Pure, Impure } = Free | |
Pure.prototype.chain = function (f) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Converts a value to string | |
const valueAsString = (value) => value.toString() | |
//Returns true if 'num' is divided without remainder by 'divider' | |
const dividesBy = (divider) => (num) => num % divider === 0 | |
//Prints 'i' only if it obeys the condition given by 'cond', using 'f' as a formatting function | |
const printIf = (cond, f) => (i) => cond(i) ? f(i) : "" | |
//Applies an array of functions to a value and concats the result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Implementation | |
*/ | |
// Takes an object containing several effectful functions, | |
// Returns a similar object where function does not do IO, but just returns an object with its name and args. | |
const constructDsl = (obj) => Object.keys(obj).reduce((valueObj, fn) => { | |
valueObj[fn] = (...args) =>({fn, args}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a list of objects which form one or many trees, this function builds and returns these trees. Works in linear time. | |
*/ | |
const idField = 'id'; | |
const parentIdField = 'parent' | |
const buildTree = (objectList) => { | |
let mainObjects = []; | |
let objects = {}; |
OlderNewer