This file contains hidden or 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
// batch([1,2,3,4,5,6,7,8,9,10], 5) -> [[1,2,3,4,5], [6,7,8,9,10]] | |
const batch = (collection, batchSize) => { | |
return collection.reduce((accumulator, value, index) => { | |
const newAccumulator = index % batchSize === 0 ? | |
[...accumulator, []] : | |
accumulator; | |
const init = newAccumulator.slice(0, -1); | |
const last = newAccumulator.slice(-1)[0]; | |
return [...init, [...last, value]]; |
This file contains hidden or 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
// This is my solution to the "Little JavaScript Problem" from http://lisperator.net/blog/a-little-javascript-problem/ | |
// Apparently this means Mihai Bazon will hire me... Woo! | |
var pair = (head, tail) => (f => f(head, tail)) | |
var car = (pair) => pair((head, tail) => head) | |
var cdr = (pair) => pair((head, tail) => tail) | |
var range = (min, max) => pair(min, min == max ? null : range(min + 1, max)) | |
var map = (list, func) => pair(func(car(list)), cdr(list) === null ? null : map(cdr(list), func)) | |
var reverse = (list, newList=null) => list === null ? newList : reverse(cdr(list),pair(car(list), newList)) | |
var foreach = (list, func) => list === null ? null : (func(car(list)), foreach(cdr(list), func)) |
This file contains hidden or 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
// Here's a relatively verbose version that is somewhat easier to read | |
//////////////////////////////////////// | |
let program = '+++>++<[->+<]>.'; | |
let arr = []; | |
let dataPointer = 0; | |
let instructionPointer = 0; | |
let output = ''; | |
while (program[instructionPointer]) { |
This file contains hidden or 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
rpnCalc = (val) => { | |
const ops = { | |
"+": (a, b) => a + b, | |
"-": (a, b) => a - b, | |
"*": (a, b) => a * b, | |
"/": (a, b) => a / b, | |
}; | |
return val.split(" ") | |
.reduce((stack, val) => ( |
This file contains hidden or 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
; Adapted from http://stackoverflow.com/a/13041851/3122246 the way it goes about converting (converts to list of | |
; strings, then to a string then reads the string) is kind of ugly but the code is nice at least. | |
(defn bytes->int [bytes] | |
"Converts a byte array into an integer." | |
(->> | |
bytes | |
(map (partial format "%02x")) | |
(apply (partial str "0x")) | |
read-string)) |
This file contains hidden or 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
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<!-- https://raw.githubusercontent.com/babel/babel/master/packages/babel-regenerator-runtime/runtime.js --> | |
<script src="http://codepen.io/anon/pen/BKXJKy.js"></script> | |
<ul id="console-outputs"></ul> | |
<form id="console-form"> | |
<input type="text" /> | |
</form> | |
<script> | |
function submitted() { |
This file contains hidden or 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
// Not really sure how I feel about this but it's kinda cool... | |
const prettyList = function(list, conjunction) { | |
return list.reduce((acc, str, i, arr) => ( | |
arr.length - i == 1 ? | |
`${acc}${conjunction} "${str}"` : | |
`${acc}"${str}", ` | |
), | |
""); | |
} |
This file contains hidden or 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 href="javascript: (function() {/* ... */})();">Bookmarklet</a> |
This file contains hidden or 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
data:text/html,<h1>Hello, world! etc. |
This file contains hidden or 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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