This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.from = function from(x) { | |
var result = new Array(); | |
for (var i = 0, n = x.length; i < n; i++) { | |
if (i in x) | |
result[i] = x[i]; | |
} | |
return result; | |
}; | |
// If Object.getPrototypeOf(Subarray) === Array, then: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Guidelines: | |
// - Class declarations and object literals should have the same features | |
// - Keep new features at a minimum (apart from what’s already in the object literal proposal) | |
// - Don’t obscure the fact that private names are actually name objects. | |
// => They can also be imported from somewhere else – a use case that needs to be supported. | |
// Rules: | |
// - Use # to denote const-ness | |
// Alternative: keyword `const` | |
// - Use @ to refer to name objects |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* class.js | |
* @author Dmitry A. Soshnikov | |
*/ | |
function Class(params) { | |
/** | |
* Constructor function | |
* If not specified, use default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Sensible defaults for jsFiddle. | |
// @author Mathias Bynens <http://mathiasbynens.be/> | |
// @link http://mths.be/bde | |
// @match http://jsfiddle.net/* | |
// ==/UserScript== | |
// Ignore existing fiddles | |
if (window.location.pathname == '/') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
path = require('path'), | |
colors = require('colors'), | |
argv = require('optimist').argv; | |
fs.readFile(path.join(__dirname, argv._[0]), function (err, data) { | |
var lines = data.toString().split('\n'); | |
for (var i = 0; i < lines.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pattern = {} | |
function Pattern:extend(obj) | |
local child = obj or {} | |
setmetatable(child, {__index = self}) | |
return child | |
end | |
function Pattern:new(...) | |
local obj = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run this with node and then run the output with sh | |
var Http = require('http') | |
var ChildProcess = require('child_process'); | |
Http.cat("http://github.com/api/v2/json/repos/show/creationix", function (err, json) { | |
if (err) throw err; | |
var data = JSON.parse(json); | |
data.repositories.forEach(function (repo) { | |
console.log("echo " + JSON.stringify(repo.name + " - " + repo.description)); | |
console.log("git clone --bare " + repo.url); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Another ES6 Proxy experiment. This one creates a stack whose underlying | |
* implementation is an array. The proxy is used to filter out everything | |
* but "push", "pop", and "length" from the interface, making it a pure | |
* stack where you can't manipulate the contents. | |
*/ | |
var Stack = (function(){ | |
var stack = [], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
This is a simple experiment relying on ECMAScript 6 Proxies. To try this out, | |
use Aurora (http://www.mozilla.org/en-US/firefox/channel/). | |
The goal was to create a HTML writer where the method names were really just | |
the HTML tags names, but without manually creating each method. This uses | |
a Proxy to create a shell to an underlying writer object that checks each | |
method name to see if it's in a list of known tags. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = { | |
'initialize': function(first, last) { | |
this.first = first; | |
this.last = last; | |
}, | |
'speak': function(message) { | |
return this.first + ' ' + this.last + ': ' + message; | |
} | |
}; |