Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrey Roenko flapenguin

View GitHub Profile
View promisify.ts
type Promisified<T extends Function> =
T extends (cb: (err: any, data: infer TData) => any) => void ? () => Promise<TData> :
T extends (arg0: infer TArg0, cb: (err: any, data: infer TData) => any) => void ? (arg0: TArg0) => Promise<TData> :
T extends (arg0: infer TArg0, arg1: infer TArg1, cb: (err: any, data: infer TData) => any) => void ? (arg0: TArg0, arg1: TArg1) => Promise<TData> :
/* etc */
never;
function w0args(cb: (err: Error, data: string) => void) {}
function w1args(arg0: number, cb: (err: Error, data: string) => void) {}
function w2args(arg0: number, arg2: boolean, cb: (err: Error, data: string) => void) {}
View discount-promises.js
function nextTick(callback) {
setTimeout(callback, 0);
}
class Promise {
constructor(callback) {
this.state = 'pending';
this.onSuccess = [];
callback(value => {
View top-down-parser.js
function parseNumber(str) {
const m = str.match(/^-?\d+/);
if (!m) {
throw new SyntaxError('not a number at ' + str);
}
const number = m[0];
return {
ast: { type: 'number', value: parseInt(number, 10) },
rest: str.substr(number.length)
};
@flapenguin
flapenguin / output.js
Last active May 17, 2017
Generate sha256 during build via Prepack.io
View output.js
lol = "07123e1f482356c415f684407a3b8723e10b2cbbc0b8fcd6282c49d37c9c1abc";
kek = "b794385f2d1ef7ab4d9273d1906381b44f2f6f2588a3efb96a49188331984753";
@flapenguin
flapenguin / firefox.foreignObject.csp.html
Last active Apr 20, 2017
Firefox CSP foreignObject doesn't render
View firefox.foreignObject.csp.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'nonce-foobar==';">
<!-- Replace CSP with next line to make svg render correctly -->
<!--<meta http-equiv="Content-Security-Policy" content="style-src 'self' 'unsafe-inline';">-->
@flapenguin
flapenguin / bugs-firefox.foreignObject.canvas.html
Created Apr 19, 2017
Firefox foreignObject background-image canvas rendering bug
View bugs-firefox.foreignObject.canvas.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Cache-Control" content="no-cache">
<title>Firefox foreignObject background-image canvas rendering bug</title>
<style>
td { border: 1px darkblue solid; }
@flapenguin
flapenguin / snippet.js
Created Nov 18, 2016
pobeda.aero remove russian cities
View snippet.js
var cities = [
'Барселона', 'Братислава', 'Вена', 'Кёльн/Бонн',
'Ларнака', 'Милан', 'Мюнхен'
];
$('.airtickets-cities')
.filter((ix, el) => cities.every(x => el.textContent.indexOf(x) === -1))
.closest('.airtickets-item')
.remove()