Skip to content

Instantly share code, notes, and snippets.

[].filter || (Array.prototype.filter = // Use the native array filter method, if available.
function(a, //a function to test each value of the array against. Truthy values will be put into the new array and falsy values will be excluded from the new array
b, // placeholder
c, // placeholder
d, // placeholder
e // placeholder
) {
c = this; // cache the array
d = []; // array to hold the new values which match the expression
for (e in c) // for each value in the array,
@zkochan
zkochan / index.js
Last active November 8, 2015 13:39
requirebin sketch
'use strict';
var magicHook = require('magic-hook');
function Logger() {
magicHook(this, ['log']);
}
Logger.prototype.log = function(msg) {
console.log(msg);
@zkochan
zkochan / index.js
Last active November 13, 2015 23:19
requirebin sketch
var registerPlugin = require('register-plugin');
var domify = require('domify')
function helloWorld(app, options, next) {
app.sayIt = function() {
document.body.appendChild(domify('Hello world!'));
};
next();
}
@zkochan
zkochan / example.yaml
Created January 4, 2016 14:39
zx file example
start: "node app"
test: "gulp test"
docker:
build: "docker-compose build"
run: "docker-compose up"
docs:
clean: "rimraf _book"
prepare: "gitbook install"
build:
- "zx docs:prepare"
@zkochan
zkochan / example.js
Created February 7, 2016 18:31
hexi-passport API
server.route.pre(function(next, opts) {
if (!opts.config.passport) return next(opts);
if (opts.config.passport.authenticate) {
opts.handler = [
function(req, res, next) {
var passportOpts = opts.config.passport.authenticate[req.params.provider] ||
opts.config.passport.authenticate.default;
passport.authenticate(req.params.provider, passportOpts)(req, res, next);
},
@zkochan
zkochan / create-app.js
Created March 11, 2016 16:14
create-app
'use strict';
module.exports = createApp;
var createElement = require('virtual-dom/create-element');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
function createApp(mount) {
var tree;
var node;
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
10% building modules 4/6 modules 2 active ...re/style-loader@0.13.1/_/addStyles.jsTypeError: Cannot read property 'directoryExists' of undefined
at Object.getAutomaticTypeDirectiveNames (/home/zkochan/src/test/issue394/node_modules/.store/typescript@2.0.0/_/lib/typescript.js:43865:17)
at State.loadTypesFromConfig (/home/zkochan/src/test/issue394/node_modules/.store/awesome-typescript-loader@2.2.4/_/src/host.ts:150:36)
at new State (/home/zkochan/src/test/issue394/node_modules/.store/awesome-typescript-loader@2.2.4/_/src/host.ts:144:14)
at Object.ensureInstance (/home/zkochan/src/test/issue394/node_modules/.store/awesome-typescript-loader@2.2.4/_/src/instance.ts:150:19)
at compiler (/home/zkochan/src/test/issue394/node_modules/.store/awesome-typescript-loader@2.2.4/_/src/index.ts:37:20)
at Object.loader (/home/zkochan/src/test/issue394/node_module
ERROR in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib/index.js
Module not found: Error: Cannot resolve module 'babel-loader' in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib
@ /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib/index.js 3:0-23
ERROR in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib/index.js
Module not found: Error: Cannot resolve module 'babel-loader' in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib
@ /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib/index.js 7:0-35
ERROR in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib/index.js
Module not found: Error: Cannot resolve module 'babel-loader' in /home/zkochan/.pnpm/.store/flat/babel-polyfill@6.16.0/_/lib
@zkochan
zkochan / README.md
Created November 17, 2016 18:42
How to migrate an npm package to TypeScript

Rename all .js files to .ts files

@zkochan
zkochan / README.md
Last active December 1, 2016 21:51
How to migrate a project to TypeScript
  1. Use lebab to convert your modules to ES2015 modules.
lebab es5.js -o es6.js --transform commonjs
  1. Change the .js extensions to .ts.
  2. Install typescript as a devDependency to your package