Skip to content

Instantly share code, notes, and snippets.

View derhuerst's full-sized avatar

Jannis R derhuerst

View GitHub Profile
@derhuerst
derhuerst / mux.js
Last active January 18, 2016 17:17
A minimal Redux clone.
module.exports = Object.freeze({
createSelector: function (selector, processor) {
var cache = {}, processed;
return function (state) {
var selected = selector(state);
if (selected !== cache) {
processed = processor(selected);
@derhuerst
derhuerst / magic.coffee
Created January 13, 2016 23:39
functional secret storage
module.exports = (key, secret) -> (key2) -> if key is key2 then secret
@derhuerst
derhuerst / babel-unicode-math.md
Created January 17, 2016 18:13
An Idea for a Babel Plugin

babel-unicode-math

Create a Babel plugin that replaces the following symbols.

Functions

@derhuerst
derhuerst / a.coffee
Last active January 21, 2016 12:32
minimal test using intravenous
factory = (a) -> foo: 'bar'
module.exports = factory
@derhuerst
derhuerst / current-track.scpt
Created January 31, 2016 16:37
get the current track from Spotify
tell application "Spotify"
set tNumber to track number of current track as integer
set tDisc to disc number of current track as integer
set tDuration to duration of current track as integer
set tName to name of current track as string
set tArtist to artist of current track as string
set tAlbum to album of current track as string
set tAlbumArtist to album artist of current track as string
set meta to tNumber & ";" & tDisc & ";" & tDuration & ";" & tName & ";" & tArtist & ";" & tAlbum & ";" & tAlbumArtist & "
"
@derhuerst
derhuerst / test.coffee
Last active February 4, 2016 10:28
another intravenous bug
container = require('intravenous').create
onDispose: (m) -> delete m.data
originalId = Math.random()
container.register 'bucket', {original: originalId}, 'singleton'
@derhuerst
derhuerst / maybe.coffee
Created February 7, 2016 14:37
something like a maybe monad? not sure…
maybe = ->
fns = []
monad = (input) -> fns.reduce ((v, fn) -> fn v), input
Object.assign monad, with: (fn) ->
fns.push (v) -> if v? then fn v else null
monad
@derhuerst
derhuerst / benchmark.coffee
Last active February 8, 2016 18:27
`n + … + 0` in JS
sum = require './sum'
for name, fn of sum
start = Date.now()
i = 500000
while i > 0
n = fn 1000, 0
i--
end = Date.now()
console.log name, end - start
@derhuerst
derhuerst / bind.js
Created February 14, 2016 18:13
fp helpers in JS ✨
var bind = function () {
var args = Array.from(arguments)
var fn = args.shift()
return function () {
return fn(...args.concat(Array.from(arguments)))
}
}
@derhuerst
derhuerst / readme.md
Last active February 17, 2016 23:14
detect iterables in JavaScript