Skip to content

Instantly share code, notes, and snippets.

View wryk's full-sized avatar

Milia wryk

View GitHub Profile
function stringTypePlugin (validator) {
return function () {
validator.add(function (metadata) {
return metadata.type === 'string';
}, function (value) {
return typeof value === 'string';
})
};
}
import loadImage from 'load-image.js'
/**
* load images
* @param {Array<String>} urls Images' urls
* @promise {Array<Image>}
**/
export default function loadImages (urls) {
return Promise.all(urls.map(loadImage))
}
// string -> Promise Image
export function loadImage(url) {
var image = new Image();
var promise = waitImage(image);
image.src = url;
return promise;
}
import {normalize} from 'path';
export default ResourcePath;
function ResourcePath (value) {
this.value = normalize(value);
}
ResourcePath.prototype.add = function () {
var result = this.value;
macro (enum) {
rule {
$name:ident (,) ...
} => {
Object.freeze({
$($name: {}) (,) ...
})
}
}
let (delete) = macro {
rule { $path:ident } => { }
}
macro (delete!) {
rule {
$path:ident
} => {
}
var short = 'hello';
var long = 'hello world';
var result = '';
for (var i = -1, l = long.length; ++i < l;) {
console.log(i % short.length);
result += short[i % short.length];
}
console.log(result);
@wryk
wryk / test.js
Last active August 29, 2015 14:00
import workify from 'workify.js'
function log (error, it) {
if (error) throw error;
console.log(it);
}
toLowerCase = workify(function (it) { return it.toLowerCase(); });
toLowerCase('HELLO', log);
var inherit = require('inherit');
module.exports = AbstractError;
inherit(AbstractError, Error)
function AbstractError (message) {
this.message = message;
this.stack = (new Error()).stack;
}
module.exports = Something;
function Something () {}
Something.prototype.toJSON = function () {
var clone = {};
var firstChar;
var that = this;
Object.keys(this).forEach(function (key) {
var firstChar = key[0];