Skip to content

Instantly share code, notes, and snippets.

View sylvainpolletvillard's full-sized avatar

Sylvain Pollet-Villard sylvainpolletvillard

View GitHub Profile
@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)") )
@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 / 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 / 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 / hurray.js
Created December 19, 2016 23:48
Hurray; Array subclass with hash destructuring for method callbacks, and a few helpers
class Hurray extends Array {
forEach(callback){
super.forEach.call(this, (...args) => callback(Hurray.iterator(...args)));
return this; // make forEach chainable
}
every(callback){ return super.every.call(this, (...args) => callback(Hurray.iterator(...args))) }
filter(callback){ return super.filter.call(this, (...args) => callback(Hurray.iterator(...args))) }
find(callback){ return super.find.call(this, (...args) => callback(Hurray.iterator(...args))) }
findIndex(callback){ return super.findIndex.call(this, (...args) => callback(Hurray.iterator(...args))) }
@sylvainpolletvillard
sylvainpolletvillard / 666.js
Created September 8, 2016 22:02
currently thinking of the most obscure way to declare factorial function in JS
f=_=>!_||_*f(~-_)
@sylvainpolletvillard
sylvainpolletvillard / chess.js
Last active December 25, 2021 15:17
Óscar Toledo G.Nanochess writen in 6chars.js
[][[[]+[][+[]]][+[]][++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[]+[][+[]]][+[]][++[++[[]][+[]]][+[]]]][[[][[[]+[][+[]]][+[]][++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[]+[][+[]]][+[]][++[++[[]][+[]]][+[]]]]+[]][+[]][++[++[++[[]][+[]]][+[]]][+[]]]+[[][[[]+[][+[]]][+[]][++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[]+[][+[]]][+[]][++[++[[]][+[]]][+[]]]]+[]][+[]][++[++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[]+[][+[]]][+[]][++[[]][+[]]]+[[![]][+[]]+[]][+[]][++[++[++[[]][+[]]][+[]]][+[]]]+[+[++[+[]][+[]]+[]+[[]+[][+[]]][+[]][++[++[++[+[]][+[]]][+[]]][+[]]]+[++[+[]][+[]]+[]][+[]]+[+[]]+[+[]]+[+[]]][+[]]+[]][+[]][++[++[++[++[++[++[[]][+[]]][+[]]][+[]]][+[]]][+[]]][+[]]]+[[!![]][+[]]+[]][+[]][++[+[]][+[]]]+[[]+[][+[]]][
function getAllPropertyNames(o){ return o ? Object.getOwnPropertyNames(o).concat(getAllPropertyNames(Object.getPrototypeOf(o))) : [] }
Object.prototype.getAllPropertyNames = function(){ return getAllPropertyNames(this) }
function formatDate(value, format) {
var date = value && value instanceof Date ? value : new Date(value);
return format
.replace("YYYY", date.getFullYear().toString())
.replace("YY", date.getFullYear().toString().substr(2, 2))
.replace("MM", (date.getMonth() + 1).toString().replace(/^(\d)$/, '0$1'))
.replace("M", (date.getMonth() + 1).toString())
.replace("DD", date.getDate().toString().replace(/^(\d)$/, '0$1'))
.replace("D", date.getDate().toString())
@sylvainpolletvillard
sylvainpolletvillard / details-polyfill.js
Last active March 8, 2016 16:04
<details> polyfill
/**
* FORKED FROM: https://gist.githubusercontent.com/remy/370590/raw/0ade67d1b83b31c8eab1acc1f354ce425d290377/details.js
*/
(function (window, document) {
if ('open' in document.createElement('details')) return; // no polyfill necessary
var addEvent = function (el, type, fn) {
if (el && el.nodeName || el === window) {
if (document.addEventListener) {
el.addEventListener(type, fn, false);