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
| 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
| 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
| 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
| /* 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
| // 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) |
OlderNewer