Skip to content

Instantly share code, notes, and snippets.

View Cycymomo's full-sized avatar

Cyril Moreau Cycymomo

View GitHub Profile
@Cycymomo
Cycymomo / arrayDiff.js
Last active December 16, 2015 12:19
Comparaison de tableaux JS
/*
* L'array le plus long doit être dans tab1
*/
Array.prototype.diff = function diff( tab1, tab2 ){
var tab3 = [];
if (Array.isArray( tab1 ) && Array.isArray( tab2 )){
tab3 = tab1.filter( function( value, index ){
return this[ index ] && value[ Object.keys( value )[ 0 ] ] === this[ index ][ Object.keys( this[ index ] )[ 0 ] ];
}, tab2 );
@Cycymomo
Cycymomo / arrayFilter.js
Last active December 16, 2015 12:28
Array filter
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */) {
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
@Cycymomo
Cycymomo / replaceSpecialChars.js
Last active December 16, 2015 12:28
replaceSpecialChars
var rules = {
a:"àáâãäå",
A:"ÀÁÂ",
e:"èéêë",
E:"ÈÉÊË",
i:"ìíîï",
I:"ÌÍÎÏ",
o:"òóôõöø",
O:"ÒÓÔÕÖØ",
u:"ùúûü",
function isMap(m) { //similarly for Set, WeakMap, WeakSet
try {
Map.prototype.size.call(m);
return true;
} catch () {return false}
}
function isDataView(d) {
try {
DataView.prototype.buffer.call(d);
@Cycymomo
Cycymomo / assert.js
Created April 27, 2013 09:40 — forked from ianb/assert.js
function AssertionError(msg) {
this.message = msg || "";
this.name = "AssertionError";
}
AssertionError.prototype = Error.prototype;
/* Call assert(cond, description1, ...)
An AssertionError will be thrown if the cond is false. All parameters will be logged to the console,
and be part of the error.
*/
@Cycymomo
Cycymomo / cloneDeep.js
Last active December 19, 2015 06:18
deep copy object or array in Javascript
function deepCopy(obj) {
if (Object.prototype.toString.call(obj) === '[object Array]') {
var len = obj.length, out = new Array(len), i = 0;
for ( ; i < len; i++ ) {
out[i] = arguments.callee(obj[i]);
}
return out;
}
if (typeof obj === 'object') {
var out = {}, i;
@Cycymomo
Cycymomo / isNumber.js
Created July 4, 2013 16:38
isNumber javascript
function isNumber(n) {
n = n.toString().replace(/,/g, '.'); // en chaine, puis convertir , en .
return !isNaN(parseFloat(n)) && isFinite(n);
}
console.log(isNumber(5)); // true
console.log(isNumber(4597)); // true
console.log(isNumber("lol")); // false
console.log(isNumber("9.489.")); // false
console.log(isNumber("9.489")); // true
@Cycymomo
Cycymomo / chromeRichNotifications.html
Last active December 19, 2015 13:59
Chrome rich notifications
<!DOCTYPE html>
<html>
<head>
<title>Exemple des Notifications Riches de Chrome</title>
<script>
/*
* Liste des callbacks
*/
var notificationCreated = function(seqID) {
console.log("Notification '" + seqID + "' créée avec succès !");
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
// by @SylvainPV at syllab.fr
(function getNextVendredi13(){
for(d=new Date;d.getDay()+d.getDate()>1;d=new Date(+d+8e7));return d
})()
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
(function parseNumbers(s){
return s.replace(/ ?s?(.)\S*/g,function(a,b){return'zudtqciehn'.search(b)})
})("un deux trois quatre cinq six sept huit neuf zero six six sept");