Skip to content

Instantly share code, notes, and snippets.

// Put strings from the input array
// which can be rotated to match each other
// into groups.
//
// input: ['Hello', 'World', 'lohEl', 'orld']
// output: [['Hello', 'lohEl'], ['World'], ['orld']]
function groupRotations(strings, transform) {
if (typeof transform !== 'function') {
transform = string => string.toLowerCase();
@very
very / events.js
Created September 23, 2013 00:13
Events.eventify = eventify;
Events.onify = onify;
Events.prototype.observe = observe;
Events.prototype.unobserve = unobserve;
Events.prototype.handle = handle;
Events.prototype.unhandle = unhandle;
Events.prototype.handleEvent = handleEvent;
Events.prototype.on = on;
Events.prototype.off = off;
Events.prototype.fire = fire;
@very
very / gist:6119816
Last active December 20, 2015 10:59
var behaviours = {
select: {
onstart: function(p) {
this.from = alignPos(this, p);
this.workspace.viewer.unselect();
},
onresume: function(p) {
if (this.from) {
this.mousemoved = true;
updateSelection(this, p);
var behaviours = {
select: {
onstart: function(p) {
var viewer = this.workspace.viewer;
this.from = {
x: p.x - (p.x % viewer.gridSize),
y: p.y - (p.y % viewer.gridSize)
};
viewer.unselect();
},
@very
very / gist:5632268
Last active December 17, 2015 15:29
function
sum
(
)
{
for
(
var
i
=
function createRandomGIF(width, height, colors) {
return {
width: width,
height: height,
resolution: 7,
colorTable: {
sorted: false,
colors: random(colors, 0x000000, 0xFFFFFF)
},
background: 0,
find . -iname "*.htm" -exec bash -c "iconv -f WINDOWS-1252 -t UTF-8 \"{}\" | html2text -utf8 -nometa -style pretty > \"`basename \"{}\" .htm`\".txt" \;
@very
very / gist:4005248
Created November 3, 2012 00:33
splitAt 2
function splitAt(string /* indexes... */) {
var i = 0, len = arguments.length, index = 0, parts = [];
while (i < len) {
parts[i] = string.substring(index, index = arguments[++i]);
}
return parts;
}
@very
very / gist:4005163
Created November 3, 2012 00:08
splitAt
function splitAt(string, index1, index2, etc) {
var parts = Array.prototype.slice.call(arguments);
parts[0] = 0;
for (var i = 0, l = parts.length; i < l; i++) {
parts[i] = string.substring(parts[i], parts[i + 1]);
}
return parts;
}
@very
very / gist:3992939
Created November 1, 2012 10:24
Map definition with chaining
var Map = (function Map(method) {
if (typeof method === "function") {
Map.prototype[method.name] = method;
return Map;
}
if (!(this instanceof Map)) {
return new Map();
}
this.data = {};
})(function has(key) {