Skip to content

Instantly share code, notes, and snippets.

View sylvainpolletvillard's full-sized avatar

Sylvain Pollet-Villard sylvainpolletvillard

View GitHub Profile
@sylvainpolletvillard
sylvainpolletvillard / debounce.js
Last active December 20, 2016 22:03
debounce.js
function debounce(func, wait = 20, options) {
options = Object.assign({
leading: false,
trailing: true,
throttle: false
}, options);
let timeout, isWaiting = false;
return function debounced(...args) {
@sylvainpolletvillard
sylvainpolletvillard / EventEmitter.js
Last active January 16, 2017 21:29
EventListener and the quest of the minimal pubsub
class EventEmitter extends Map {
on (e,f){ this.set(e, [...this.get(e)||[], f]) }
off(e,f){ this.set(e, (this.get(e)||[]).filter(x => f && x !== f)) }
emit(e,...a){ (this.get(e)||[]).map(f => f(...a)) }
}
// minified classless fit-in-a-tweet version
E=(M=new Map,_=e=>M.get(e)||[])=>({on(e,f){M.set(e,[..._(e),f])},off(e,f){M.set(e,_(e).filter(x=>f&&f!==x))},emit(e,a){_(e).map(f=>f(a))}})
// Usage example:
@sylvainpolletvillard
sylvainpolletvillard / worsthelloworldever.html
Last active February 27, 2017 21:42
Worst "Hello World" ever (only works in Chrome because it is the worst)
<script>
ಠ='',ಉ=!ಠ+ಠ,ನ=!ಉ+ಠ,ಊ=ಠ+{},ಝ=ಉ[ಠ++],ಏ=ಉ[ೡ=ಠ],ಖ=++ೡ+ಠ,ತ=ಊ[ೡ+ಖ],
ಉ[ತ+=ಊ[ಠ]+(ಉ.ನ+ಊ)[ಠ]+ನ[ಖ]+ಝ+ಏ+ಉ[ೡ]+ತ+ಝ+ಊ[ಠ]+ಏ][ತ](ನ[ಠ]+ನ[ೡ]+ಉ[ಖ]+ಏ+ಝ+`
([[]+[]][+[]][[[][[[]+[][+[]]][+[]][++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[++
[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[]+[][+[]]][+[]][++[++[
[]][+[]]][+[]]]]+[]][+[]][++[++[++[[]][+[]]][+[]]][+[]]]+[[][[[]+[][+[]]][+[]][++[++[++[++[[]][+[]]
][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]]
[+[]][++[[]][+[]]]+[[]+[][+[]]][+[]][++[++[[]][+[]]][+[]]]]+[]][+[]][++[++[++[++[++[++[[]][+[]]][+[
]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[![]][+[]]+[]][+[]][++[++[++[[]][+[]]][
+[]]][+[]]]+[+[++[+[]][+[]]+[]+[[]+[][+[]]][+[]][++[++[++[+[]][+[]]][+[]]][+[]]]+[++[+[]][+[]]+[]][
@sylvainpolletvillard
sylvainpolletvillard / index.js
Last active May 8, 2017 17:05
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var reduceCSSCalc = require('reduce-css-calc')
console.log("test", reduceCSSCalc("calc(100% - 120px - 60px)") )
const [
,
mess = "mess",
message,
[, [{ [mess + "age"]: whoops = (() => mess)(mess) }]]
] = [1, undefined, undefined, [2, [(() => ({ message }))() ]]]
const [
mess = "mess",
message,
@sylvainpolletvillard
sylvainpolletvillard / base5compressor-poc.js
Created September 16, 2018 11:34
basic base 5 to utf-16 converter for 5chars.js. Probably useless
{
let chars = '+=[]_';
let range = 6; // 5^6 < 65535 < 5^7
function base5compress(input){
let out="";
for(let i=0; i<input.length; i+=range){
let part = input.slice(i, i+range).split('').reverse();
let charcode = part.reduce((acc, c) => chars.length*acc + chars.indexOf(c), 0)
out += String.fromCharCode(charcode)
@sylvainpolletvillard
sylvainpolletvillard / cloudSettings
Created October 19, 2018 09:30
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-10-19T09:30:08.862Z","extensionVersion":"v3.2.0"}
@sylvainpolletvillard
sylvainpolletvillard / evil.js
Created July 5, 2019 12:28
Evil javascript
// ; === Say hello to someone ===
// ; argument = String
// ; return = String
// ; NOTE: If you have a bug with character encoding, you should use this
/󠅡/ ; instead: rеturn = ([f])=>{Function(unescape(escape(f).replace(/u.{8}/g,'')))()}
function hello(who){
rеturn `󠅡󠅬󠅥󠅲󠅴󠄨󠄢󠄰󠅷󠅎󠅥󠅄󠄠󠅢󠅙󠄠󠅈󠄴󠅣󠅫󠄳󠅲󠅚󠄠󠄢󠄩󠄻󠄊Hello ${who}`
}
@sylvainpolletvillard
sylvainpolletvillard / eviljavascript.txt
Last active December 13, 2023 01:04
eviljavascript.txt
/// Hello World in JavaScript
/// NOTE: If you have a bug with character encoding, you should use
/󠅡// this; rеturn = ([𐕰])=>{Function(unescape(escape(𐕰).replace(/u.{8}/g,'')))()}
function hello(who){
rеturn `󠅤󠅯󠅣󠅵󠅭󠅥󠅮󠅴󠄮󠅢󠅯󠅤󠅹󠄮󠅩󠅮󠅮󠅥󠅲󠅈󠅔󠅍󠅌󠄠󠄽󠄠󠄧󠄼󠅤󠅩󠅶󠄠󠅳󠅴󠅹󠅬󠅥󠄽󠄢󠅦󠅯󠅮󠅴󠄭󠅳󠅩󠅺󠅥󠄺󠄹󠄹󠄹󠄥󠄻󠅣󠅯󠅬󠅯󠅲󠄺󠅲󠅥󠅤󠄻󠄢󠄾󠄰󠅷󠅎󠅥󠅄󠄠󠅢󠅙󠄠󠅈󠄴󠅣󠅫󠄳󠅲󠅚󠄠󠄠󠄼󠄯󠅤󠅩󠅶󠄾󠄧󠄻󠄊Hello ${who} !`
}
hello("world")
@sylvainpolletvillard
sylvainpolletvillard / game.js
Created February 26, 2020 13:18
quick game of life
const parseGrid = ([str]) => str
.split('\n')
.map(row => row.trim())
.filter(row => row.length > 0)
.map(row => row.split('').map(char => char !== '.'))
const formatGrid = rows => rows
.map(row => row.map(cell => cell ? '#' : '.').join(''))
.join('\n')