Skip to content

Instantly share code, notes, and snippets.

View futurist's full-sized avatar

James Yang futurist

  • China
View GitHub Profile
@futurist
futurist / mithril with generator
Created March 19, 2017 01:07
mithril with generator
function * component(vnode){
// oninit
yield
// view
while (true){
yield m('h1', 'hello world')
// onbeforeupdate
yield
@futurist
futurist / headless.md
Created June 29, 2017 05:33 — forked from addyosmani/headless.md
So, you want to run Chrome headless.

Update May 2017

Eric Bidelman has documented some of the common workflows possible with headless Chrome over in https://developers.google.com/web/updates/2017/04/headless-chrome.

Update

If you're looking at this in 2016 and beyond, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

Windows and Mac users might find using Justin Ribeiro's Docker setup useful here while full support for these platforms is being worked out.

@futurist
futurist / README.md
Created July 6, 2017 14:17 — forked from joyrexus/README.md
Form/file uploads with hapi.js

Demo of multipart form/file uploading with hapi.js.

Usage

npm install
npm run setup
npm run server

Then ...

@futurist
futurist / m-promisify.js
Last active July 20, 2017 00:57
Mithril promisify for 0.2.x using m.deferred
import m from 'mithril'
/**
* thatLooksLikeAPromiseToMe()
*
* Duck-types a promise.
*
* @param {object} o
* @return {bool} True if this resembles a promise
*/
@futurist
futurist / b.html
Last active May 8, 2018 00:15
Iframe With Service Worker
<script>
onload=e=>{
document.open()
document.write(`<script src=b.js><\/script>`)
document.close()
}
</script>
@futurist
futurist / breakOn.js
Created May 11, 2018 00:09
BreakOn for debugger
window.breakOn = function breakOn(obj, propertyName, mode, func) {
// this is directly from https://github.com/paulmillr/es6-shim
function getPropertyDescriptor(obj, name) {
var property = Object.getOwnPropertyDescriptor(obj, name);
var proto = Object.getPrototypeOf(obj);
while (property === undefined && proto !== null) {
property = Object.getOwnPropertyDescriptor(proto, name);
proto = Object.getPrototypeOf(proto);
}
return property;
@futurist
futurist / functional-es6.js
Last active May 14, 2018 07:32
Some collection of functional js
const curry = f => a => b => f(a, b)
const uncurry = f => (a, b) => f(a)(b)
const papply = (f, a) => b => f(a, b)
const compose2 = (f, g) => (...args) => f(g(...args))
const compose = (...fns) => fns.reduce(compose2)
const pipe = (...fns) => fns.reduceRight(compose2)
// express.js like middle ware
// arg => fns[0](arg,null)->ret0 => fns[1](arg,ret0)->ret1 ...
@futurist
futurist / es6-partial-application.md
Created May 14, 2018 07:41 — forked from JamieMason/es6-partial-application.md
ES6 Partial Application in 3 Lines

ES6 Partial Application in 3 Lines

const pApply = (fn, ...cache) => (...args) => {
  const all = cache.concat(args);
  return all.length >= fn.length ? fn(...all) : pApply(fn, ...all);
};

Example

@futurist
futurist / omega.js
Created May 14, 2018 08:01 — forked from CrossEye/omega.js
Functional compostion using fake operator overloading
// Based on a discussion with Michael Haufe:
// https://groups.google.com/group/jsmentors/browse_thread/thread/d028fb0041f93a27
// Not really recommended for anything but the fun of knowing it can be done!
var omega = function() {
var queue = [];
var valueOf = Function.prototype.valueOf;
Function.prototype.valueOf = function() {
queue.push(this);
return 1; // not needed now, but could be used later to distinguish operators.
@futurist
futurist / jsconfig.json
Created May 17, 2018 07:43
VSCode config file for ./src as modules
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src/",
"paths":{
"components11/*": ["./src/components/*"]
}
}