Skip to content

Instantly share code, notes, and snippets.

@wolfflow
wolfflow / cloudSettings
Created August 21, 2017 19:14
Visual Studio Code Settings Sync Gist
{"lastUpload":"2017-08-21T19:14:37.242Z","extensionVersion":"v2.8.3"}
const makeFieldFn = (key) => (x) => (e) => e[key] === x;
module.exports = {
typeIs: makeFieldFn('type'),
keyCodeIs: makeFieldFn('keyCode'),
keyCodeIsIn: (range) => (e) => range.indexOf(e.keyCode) !== -1,
};
@wolfflow
wolfflow / bus-mixin.ls
Created December 11, 2015 08:45
Shortest Bacon Bus Mixin Ever
module.exports =
component-will-mount: !-> (@bus = new Bacon.Bus).onValue!
component-will-unmount: !-> @bus.end!
plug: (es) -> @bus.plug es
@wolfflow
wolfflow / index.js
Last active December 7, 2015 10:14
superagent + bacon.js
var B = require('baconjs');
var request = require('superagent');
var config = [{
pattern: "http://my.com(.*)",
fixtures: function (match, params, headers) {
if (match[1] === '/404') {
throw new Error(404);
}
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@wolfflow
wolfflow / script.ls
Last active August 29, 2015 14:23
React without JSX | LS
window <<< React.DOM
console.log h1, 'h1'
# works properly
React.render(h1(null,'foo'), document.body)
Bar = React.createClass do
render: -> h1 null, 'bar'
# !!!throws an error: Uncaught TypeError: Cannot read property '__reactAutoBindMap' of undefined
@wolfflow
wolfflow / decodeUtf16.coffee
Last active August 29, 2015 13:56
decode utf16
decode = (s) ->
s.replace /\\u([0-9a-f]{4})/gi, (_,r) -> String.fromCharCode parseInt(r,16)
@wolfflow
wolfflow / Bacon.repeatedlyOnFrame.ls
Created February 14, 2014 11:07
Bacon.repeatedlyOnFrame -- rAF based implementation of Bacon.repeatedly
# divisor adjusts sequence rate, e.g. value of 2 means that new values are produced on even frames only
# Thus Bacon.repeatedlyOnFrame(values, 6) is barely equivalent to 100ms timeout at 60fps
Bacon.repeatedlyOnFrame = (values, divisor = 1) ->
index = 0
Bacon.scheduleAnimFrame()
.scan 0, -> it + 1
.filter (tick) -> !(tick % divisor)
.map (tick) ->
values[index++ % values.length]
tasks = [
{done:false, results:[]}
{done:true, results:[]}
]
isDone = ->
tasks.filter((x)->x.done).length is tasks.length
Bacon.later(20000).assign(-> tasks[0].done = true)
@wolfflow
wolfflow / maybe.ls
Last active January 3, 2016 13:29
maybe
maybe = (fn) -> ->
return if arguments.length is 0
for arg in arguments
return if !arg?
fn.apply(@, arguments)
# Usage
Z = maybe((n)->n*n)