Skip to content

Instantly share code, notes, and snippets.

@cevek
cevek / example.js
Last active October 19, 2018 20:21
var foo, bar;
class Aaa {
constructor(a, b) {
this.a = a;
this.b = b;
}
}
class Bbb {
--use-strict (enforce strict mode)
type: bool default: false
--es-staging (enable test-worthy harmony features (for internal use only))
type: bool default: false
--harmony (enable all completed harmony features)
type: bool default: false
--harmony-shipping (enable all shipped harmony features)
type: bool default: true
--harmony-regexp-sequence (enable "RegExp Unicode sequence properties" (in progress))
type: bool default: false
function abc(obj, prop) {
for (let j = 0; j < 1e7; j++) {
var x = obj[prop];
}
return x;
}
function abc2(obj) {
for (let j = 0; j < 1e7; j++) {
var x = obj.b;
@cevek
cevek / promise-devtools.js
Created September 19, 2018 12:33
Devtools enhancement: Pause on exceptions inside promise.then or catch without checked caught in exceptions
function create(fn, name) {
if (fn === undefined) return;
const callback = data => {
let ret;
new Promise(() => (ret = fn(data)));
return ret;
};
callback.displayName = name;
return callback;
}
// Поместите настраиваемые сочетания клавиш в этот файл, чтобы перезаписать клавиши по умолчанию.
[
{
"key": "cmd+k",
"command": "workbench.action.terminal.clear",
},
{
"key": "cmd+alt+i",
"command": "workbench.action.terminal.toggleTerminal"
},
type AtLeastOne<T, U = { [K in keyof T]: { [P in K]: T[P] } }> = { [P in keyof T]?: T[P] } & U[keyof U];
type Exactify<Base, T extends Base> = Base & { [K in keyof T]: K extends keyof Base ? T[K] : never };
declare function requireExact<X extends Exactify<{a: number}, X>>(x: X): void;
type Omit<T, Keys extends string> = Pick<T, Exclude<keyof T, Keys>>;
type IfEquals<X, Y, A=X, B=never> =
(<T>() => T extends X ? 1 : 2) extends
(<T>() => T extends Y ? 1 : 2) ? A : B;
type WritableKeys<T> = {
@cevek
cevek / wait.js
Last active June 4, 2018 21:14
Wait until all async is done
var arr = [];
function allDone() { console.log('All done') }
function replaceCallback(callback) {
if (typeof callback !== 'function') return callback;
arr.push(callback);
return function () {
var pos = arr.indexOf(callback);
if (pos > -1) arr.splice(pos, 1);
var res = callback.apply(this, arguments);
if (arr.length === 0) allDone();
@cevek
cevek / result.js
Last active December 15, 2020 05:22
Typescript pre transformer
"use strict";
function Bar(props) { return null; }
React.createElement(Bar, { sdf: true, id: 'hello' });
React.createElement("div", { id: 'hi' }, "abc");
React.createElement("div", null, "abc");
@cevek
cevek / fibers.js
Created May 30, 2018 13:19
Fibers with async await
var prev = Date.now();
var callbacks;
function wait() {
return new Promise((resolve) => {
if (Date.now() > prev + 8) {
if (callbacks === undefined) {
callbacks = [];
callbacks.push(resolve);
requestAnimationFrame(() => {
prev = Date.now();
eval
new Function
new GeneratorFunction
new AsyncFunction
setTimeout("eval")
setInterval("eval")
div.innerHTML
div.setAttribute("onclick", "eval") // all events
div.attributes.setNamedItem
div.attributes.setNamedItemNS