Skip to content

Instantly share code, notes, and snippets.

View fed135's full-sized avatar
🗜️
Optimizing...

Frederic Charette fed135

🗜️
Optimizing...
View GitHub Profile
@fed135
fed135 / lib.js
Created July 18, 2019 19:13
Forked HTTP
/**
* Multi-process request
*/
/* Requires ------------------------------------------------------------------*/
const crypto = require('crypto');
const path = require('path');
const fork = require('child_process').fork;
<!-- 729 Bytes -->
<style>td{width:64px;height:56px;padding-top:10px;border:2px solid;float:left;text-align:center;font-weight:bolder;font-family:arial;font-size:42px}</style><body/><script>for(_='d.a~===[a]a,b=0;document.body){function} return(e[b])if(l(c");c[r]c[b]4>++for( .map((f .onclick= ,b)m;} %4]}}(d)) aa;var .innerHTML.appendChild(a++)=createElement("t; (nn[f.ac=[],e=["X","O"],g h( (};=e[g];g=0g?1:0;k()k(b<e.length;b  f}) d={};d={a:~},a~=0++~----}}l(3a.reduce(p,0)m(a+=a+" won!"p(a(b,db+(da?1:0)}}Cable"),rr;rtr=[];uu;uvd[u]=v;tv);v h.bind(null,r,u)}Ct)}C);';G=/[^ -}]/.exec(_);)with(_.split(G))_=join(shift());eval(_)</script>
@fed135
fed135 / sample.txt
Created May 28, 2019 16:16
HA-store benchmark samples file
This file has been truncated, but you can view the full file.
37019 1
48322 1
4941 1
74011 1
181550 1
7489 1
198154 1
110860 1
18306 1
120357 1
@fed135
fed135 / graphQLTransactionName.js
Created March 13, 2019 19:32
Get transaction name from graphql query
const assert = require('assert');
function getGraphQLTransactionName(query) {
let parsed;
let models = [];
// Looks for model tokens
while (null !== (parsed = (new RegExp(/(\w+)(?:\(.+\))? {/gmi)).exec(query))) {
query = query.replace(parsed[0], '');
// Appends the first capture group
if (parsed[1] !== 'query') models.push(`[${parsed[1]}]`);
@fed135
fed135 / game.js
Created October 4, 2018 01:03
Rock-Paper-Scissors example
function play(playerMove) {
// Constants, for clarity
const TIE = 0;
const DEFEAT = 1;
const VICTORY = 2;
// Moves matrix, array determines the player's victory condition over other moves
const moves = {
rock: [TIE, DEFEAT, VICTORY],
paper: [VICTORY, TIE, DEFEAT],
@fed135
fed135 / clone.js
Created September 4, 2018 11:59
Deep Clone (Time Limit 1h)
function clone(target, options = {}) {
options = Object.assign({ omitTypes: [], maxDepth: 10 }, options);
const parents = [];
const copiedParents = [];
const complexTypes = [Boolean, Number, String, Date, Error, Map, Set, RegExp];
const skippedTypes = [Symbol, Function];
function cloneLayer(obj, layer = 0) {
// Simple/complex types
if (obj === null) return null;
@fed135
fed135 / table.js
Last active September 4, 2018 11:57
Table builder (Time limit 2h30)
function printTable(table) {
const options = {
padding: 1,
columns: table.reduce(parseColumns, []),
lineSize: 1,
};
options.lineSize = options.columns.reduce((num, col) => {
return num + col.size + (options.padding * 2) + 1;
}, 1);
@fed135
fed135 / db.js
Last active July 24, 2018 16:36
ha-store sample 1
/**
* Data access layer
*/
/* Requires --------------------------------------------------------------*/
const MongoClient = require('mongo').MongoClient;
/* Init ------------------------------------------------------------------*/
@fed135
fed135 / iv.js
Created October 24, 2017 23:50
Reveal framework (IV)
/**
* IV Reveal framework
*
* I wanted to simplify and standardize the way I was building applications and leverage some great patterns like dependency injection, reveal and factories.
* Unfortunatly, conveinience and "protecting the user from himself" by de-listing some private methods caused a few headaches during testing.
* This aims at solving all those.
*
* Let's consider a module 'Server'
*
* --- Module
@fed135
fed135 / NODE_IS_FUNKY.md
Last active September 28, 2016 04:49
Node is funky