Skip to content

Instantly share code, notes, and snippets.

View wryk's full-sized avatar

Milia wryk

View GitHub Profile
@wryk
wryk / pluralize.js
Created February 18, 2014 13:29
pluralize word (use regular plural rules => works only on regular words)
/*
plural rules
regular
if -s, -x, -ch or -sh then add -es
if -{consonant}y then remove -y and add -ies
else add -s
irregular
if -f then remove -f and add -ves
if -fe then remove -fe and add -ves
@wryk
wryk / hyphen-to-camel.js
Created February 18, 2014 13:42
transform hyphen case text to camel case
function hyphenToCamel (text) {
var hyphen = text.split('');
var camel = [];
var i = 0, j = 0, l = hyphen.length;
while (i < l) {
camel[j] = hyphen[i] === '-' ? hyphen[++i].toUpperCase() : hyphen[i];
i++; j++;
}
@wryk
wryk / camel-to-hyphen.js
Created February 18, 2014 13:43
transform camel case text to hyphen case
function camelToHyphen (text) {
var camel = text.split('');
var hyphen = [];
var i = 0, l = camel.length;
for (var i = -1, l = camel.length; ++i < l;) {
hyphen[i] = camel[i] === camel[i].toUpperCase() ? '-' + camel[i].toLowerCase() : camel[i];
}
return hyphen.join('');
@wryk
wryk / vector.js
Last active August 29, 2015 13:57
module.exports = Vector;
function Vector (x, y, z) {
this.x = x || 0;
this.y = y || 0;
this.z = z || 0;
}
Vector.prototype.clone = function clone () {
return new Vector(this.x, this.y, this.z);
module.exports = Pool;
function Pool (create, reset) {
this.pool = [];
this.create = create;
this.reset = reset;
}
Pool.prototype.acquire = function acquire () {
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];
var inherit = require('inherit');
module.exports = AbstractError;
inherit(AbstractError, Error)
function AbstractError (message) {
this.message = message;
this.stack = (new Error()).stack;
}
@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 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);
let (delete) = macro {
rule { $path:ident } => { }
}
macro (delete!) {
rule {
$path:ident
} => {
}