Skip to content

Instantly share code, notes, and snippets.

@phenax
phenax / chuck_norris_jokes.js
Last active December 22, 2017 07:05
Turn any page into a random chuck norris joke
(() => {
const chuckFace = 'http://wallsdesk.com/wp-content/uploads/2016/11/Chuck-Norris-HD.jpg';
const $body = document.body;
const $div = document.createElement('div');
$body.innerHTML = '';
$body.appendChild($div);
Object.assign($div.style, { width: '100%',fontSize: '1.5em', padding:'.5em', color: '#fff', textShadow: '1px 1px 1px #000', textAlign: 'center', backgroundColor: 'rgba(0,0,0,.4)' });
@phenax
phenax / ascii-stuff
Created January 3, 2018 16:31
My elephant
_______
/ \
/ * \
| ) \__________________
|V| / /_ \
| | / / |/| |
\ \__/ / \ / \_
\____/ | |_____________| __/
| | | |
@phenax
phenax / absolute-import-codemod-transform.js
Created April 16, 2018 12:38
Codemod transform to convert all relative paths to absolute import paths inside src
const path = require('path');
const SOURCE = 'src';
const SOURCE_PATH = path.resolve(SOURCE) + '/';
const removeSourceDirName = path =>
path.replace(new RegExp(`^${SOURCE}\/?`, 'gi'), '');
@phenax
phenax / get-promise-status.js
Created November 17, 2018 10:01
Get the promise status
const promiseState = status => ({ status });
const PROMISE_STATE = {
PENDING: promiseState('PENDING'),
RESOLVED: promiseState('RESOLVED'),
REJECTED: promiseState('REJECTED'),
};
const getPromiseStatus = promise =>
@phenax
phenax / foldPromiseImmedietely.js
Last active September 28, 2021 06:44
Fold promise immedietely
const PENDING_STATE = Symbol.for('MyPromise.PENDING');
const foldPromiseImmedietely = (promise, { RESOLVED, PENDING, REJECTED }) =>
Promise.race([ promise, Promise.resolve(PENDING_STATE) ])
.then(x => x === PENDING_STATE ? PENDING() : RESOLVED(x))
.catch(REJECTED);
const message = await foldPromiseImmedietely(teraPromise, {
RESOLVED: value => `Got ma ${value}`,
PENDING: () => 'Waitin for ma value',