Skip to content

Instantly share code, notes, and snippets.

View Cycymomo's full-sized avatar

Cyril Moreau Cycymomo

View GitHub Profile
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
(function(d,t,y){
y=d.getFullYear();return t[(y%100*1.25+'0642'[(y/100-15)%4^0]*1+'033614625035'[d.getMonth()]*1+d.getDate()-!!((!(y%4)&&y%100)||!(y%400)))%7^0]
})(new Date(1789,6,14),['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']);
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
(function(y,t,r,i,d,j,s){
for(r=i=[];i<12;r[i++]=s)for(j=s=[];+d!=+new Date(y,i+1,0);s[j++]=t[(y%100*1.25+'0642'[(y/100-15)%4^0]*1+'033614625035'[d.getMonth()]*1+d.getDate()-!!((!(y%4)&&y%100)||!(y%400)))%7^0])d=new Date(y,i,j+1);return r
})(2000,['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi']);
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
// by @Lcfvs
// NodeFilter.SHOW_TEXT === 4
(function(n,e){
var t=document.createTreeWalker(n,4),p='nodeValue',i;while(t.nextNode()){i=t.currentNode;i[p]=i[p].replace(e,'')}
})(document.body,/e/ig);
@Cycymomo
Cycymomo / transformImg.js
Last active December 20, 2015 18:09
140bytes - transformImg.js by @nosmoking at developpez.com
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
(function(d,p){
for(i=0,m='onmouseo',s='style';I=d.images[i++];)I[m+'ver']=function(){this[s].transform=p},I[m+'ut']=function(){this[s]=''}
})(document,'rotate(-45deg)'); /*rotate(-45deg) : 45° rotation, scale(2) : zoom */
@Cycymomo
Cycymomo / doABarrelRoll.js
Last active December 20, 2015 18:09
140bytes - doABarrelRoll.js do a barrel roll by @SylvainPV at developpez.com
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
(function(){
for(e=document.body.style,i=4;i--;)p=["webkitT","mozT","msT","t"][i]+"rans",t=p+"form",e[p+"ition"]="all 5s",e[t]=e[t]?"":"rotate(360deg)"
})();
@Cycymomo
Cycymomo / dateQuirk.md
Created August 2, 2013 12:56
date object quirk

C'est bien pour étendre les "classes customs" qui se basent sur le constructeur de function mais pas pour les éléments natifs (Array, Date, etc). On ne peut pas, ou presque, les étendre.

Date.UTC(2012,02,30); // ok
MyDate.UTC(2012,02,30); // has no method 'UTC'

var d = new MyDate();
console.log(d.getHours()); // this is not a Date object.

Car, en dur dans le moteur Javascript, chaque méthode de Date va vérifier que l'objet en question est bien une instance de Date. Voici un extrait du code V8 (pour prendre un moteur en exemple) :

@Cycymomo
Cycymomo / bindEvent.js
Last active December 20, 2015 12:19
bindEvent.js
var bindEvent = function( element, type, eventHandler ) {
if ( element.addEventListener ) {
element.addEventListener( type, eventHandler, false );
} else if ( element.attachEvent ) {
element.attachEvent( "on" + type, eventHandler );
}
};
bindEvent(document.getElementById('mon_element'), 'change', function () {
alert('je change !');
@Cycymomo
Cycymomo / LICENSE.txt
Created August 1, 2013 09:21 — forked from aemkei/LICENSE.txt
140bytes - Converts a latin character string into [leetspeak]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@Cycymomo
Cycymomo / avgColor.js
Created July 29, 2013 13:47
Color utils
// get the average color of two hex colors.
function avgcolor(color1,color2){
var avg = function(a,b){ return (a+b)/2; },
t16 = function(c){ return parseInt((''+c).replace('#',''),16) },
hex = function(c){ return (c>>0).toString(16) },
hex1 = t16(color1),
hex2 = t16(color2),
r = function(hex){ return hex >> 16 & 0xFF},
g = function(hex){ return hex >> 8 & 0xFF},
b = function(hex){ return hex & 0xFF},
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
/* Chrome : */
(function(){
document.styleSheets[0].addRule('html','-webkit-filter:invert()')
})()
/* IE9+ & Opera : */
(function(){
document.styleSheets[0].addRule("body:before","content:'';position:fixed;outline:2999px solid invert")
})()