Skip to content

Instantly share code, notes, and snippets.

View RReverser's full-sized avatar
🇺🇦

Ingvar Stepanyan RReverser

🇺🇦
View GitHub Profile
@RReverser
RReverser / better-console-log.js
Last active May 9, 2019 21:07
Better console.log in Node
// UPD:
// Now available as npm module!
// Check out https://github.com/RReverser/better-log for details.
console.log = (function (log, inspect) {
return function () {
return log.apply(this, Array.prototype.map.call(arguments, function (arg) {
return inspect(arg, { depth: 1, colors: true });
}));
};
@RReverser
RReverser / es6-intrinsic.js
Created June 14, 2015 14:04
ES6 spec: 6.1.7.4 Well-Known Intrinsic Objects
/*
The MIT License (MIT)
Copyright (c) 2015 Ingvar Stepanyan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
var createChain = function (ops) {
var chain = function () {};
chain.__asyncOps = ops;
return new Proxy(chain, AsyncContextHandler);
};
function AsyncAccessError() {
TypeError.call(this, 'Can\'t perform synchronous operation on remote object.');
}
@RReverser
RReverser / index.js
Last active September 6, 2015 11:53
jsunderhood tutorial
#!/usr/bin/env node
var fs = require('fs');
var acorn = require('./parser');
var transform = require('./transform');
var escodegen = require('escodegen');
var filename = process.argv[2];
if (!filename) {
console.log('Usage: transpile filename.js');
function awaitableVersionOf(nodeFunction) {
return (...args) => new Promise((resolve, reject) => {
nodeFunction(
...args,
(error, ...cbArgs) => error ? reject(error) : resolve(...cbArgs)
);
});
}
function slice(str, start, end) {
let i = 0, pos = 0, legacyStart, legacyEnd;
for (let ch of str) {
if (i === start) {
legacyStart = pos;
}
i++;
pos += ch.length;
if (i === end) {
legacyEnd = pos;
Example #1:
ArrayLiteral[Yield] :
[ Elision[opt] ]
[ ElementList[?Yield] ]
[ ElementList[?Yield] , Elision[opt] ]
Option #1:
ArrayLiteral :
function *getSymbols(s) {
for (var i = 0; i < s.length - 1; i++) {
if (s.charCodeAt(i) >> 10 === 0x36 && s.charCodeAt(i + 1) >> 10 === 0x37) {
yield s.substr(i, 2);
} else {
yield s.charAt(i);
}
}
yield s.charAt(i);
}
RegExp.prototype.matches = function* (str) {
let moreThanOnce = this.global || this.sticky;
let myLastIndex = 0;
do {
// preserve lastIndex of another .exec() calls on same regexp
let savedLastIndex = this.lastIndex;
// use own state for lastIndex to match our str
this.lastIndex = myLastIndex;
let match = this.exec(str);