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
// Y is the fixed point combinator. w1, w2, w3 are its building block. | |
// one level deep | |
var w1 = f => n => f( w1(f) )(n) | |
var Y = w1 | |
// two level deep | |
var w2 = g => f => n => f( g(g)(f) )(n) | |
var Y = w2(w2) |
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 step-by-step explanation (with generating Fibonacci Number): | |
From naïve self-referencing function to fixed-point combinator | |
*/ | |
// test runner | |
const t = (i => f => console.log(`v${i++}`, [1,2,3,4,5].map(f)))(1) | |
// 1 naïve approach | |
var fib = n => n < 2 ? 1 : fib(n - 2) + fib(n - 1) | |
t(fib) |
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
appName = "Finder" | |
app = Application(appName) | |
if (!app.running()) { | |
app.activate() | |
} | |
else { | |
if (! app.visible()) { | |
app.activate() |
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
console.log( | |
(x => $$('div.a-section a.TitleLink') | |
.map(y => y.innerText) | |
.filter((name, bool) => (bool = (x !== name), x = name, bool)) | |
.reduce((result, name, i) => `${result}${i + 1}. ${name} | |
`, "\n") | |
)() | |
) |
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
pref = Application("System Events").appearancePreferences | |
// weird syntax with no documentation... | |
pref.darkMode = !pref.darkMode() |
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
const fs = require('fs') | |
const child = require('child_process') | |
if (process.env.SUDO_UID === undefined) { | |
console.log(`Permission denied | |
sudo required`) | |
process.exit(1) | |
} |
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
let yCombinator = f => (g => (...p) => f(g(g))(...p))(g => (...p) => f(g(g))(...p)) | |
var factory = f => (...a) => a.length - a[0].length > 1 ? f.call.call(...a) : f.bind(null, ...a) | |
// | |
// we could add some fancy code to eliminate fn.call & fn.bind | |
// | |
// var topsy = (f => f.bind(f))(Function.call) | |
// var turvy = (f => f.bind(f))(Function.bind) | |
// var factory = f => (...a) => (a.length - a[0].length > 1 ? topsy : turvy(f, null))(...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
function *step(fn) { | |
var arr = Array(fn.length); | |
for (var i = 0; i < arr.length; i++) { | |
arr[i] = (yield); | |
} | |
var gen = fn.apply(null, arr); | |
return gen; | |
} |
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
# logging offline visits across sessions | |
# for in-house tracking and Google Analytics | |
# See my blog for more information (Chinese) | |
# http://ljw.me/2013/07/24/logging-offline-visits.html | |
# | |
# Usage: | |
# | |
# var tracker = new FTCTracker(beaconURLPrefix) | |
# tracker.push(url) | |
# |
NewerOlder