Skip to content

Instantly share code, notes, and snippets.

View nfroidure's full-sized avatar
🌻
Getting greener

Nicolas Froidure nfroidure

🌻
Getting greener
View GitHub Profile
@nfroidure
nfroidure / gRetain.js
Last active August 29, 2015 13:56
gulp-retain
function gRetain(options) {
var stream = new Stream.Writable({objectMode:true})
, fileMap = {}
, timeout
, size = 0
;
options.limit = options.limit || 0;
options.delay = options.delay || 300;
'use strict';
var STYLE_ATTRIBUTE = 'TEXT-STYLE-NAME';
var styleMatches = function (item, styleName) {
if (!item || item.attributes === undefined || item.attributes[STYLE_ATTRIBUTE] === undefined) {
return false;
}
return item.attributes[STYLE_ATTRIBUTE].match(styleName);
@nfroidure
nfroidure / xbbcode2xhtml.js
Last active August 29, 2015 14:09
Convert XBBCodes to XHTML
module.exports = function xbbcode2html(str, options) {
var all = options.all || false;
var cleanup = options.cleanup || false;
var secure = options.secure || false;
var tags = [
'span', 'kbd', 'var', 'del', 'ins', 'div', 'strong', 'em', 'dfn', 'cite',
'q', 'blockquote', 'p', 'br', 'a', 'ol', 'ul', 'li', 'abbr', 'acronym',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'pre', 'address', 'img', 'tr',
'th', 'td', 'table', 'caption', 'thead', 'tfoot', 'tbody', 'dl', 'dd', 'dt',
'map', 'area', 'code', 'samp', 'sub', 'sup'
@nfroidure
nfroidure / gist:8e07426a2bc9ff65dee5
Created December 11, 2014 13:23
Mixins mess in
var Mixin = require('Mixin');
var Mixin1 = require('Mixin1');
var Mixin2 = require('Mixin2');
var Mixin3 = require('Mixin3');
function MyCtor() {
}
Mixin.set(myCtor, Mixin1, Mixin2, Mixin3);
@nfroidure
nfroidure / gulpfile.js
Last active August 29, 2015 14:16 — forked from Simounet/gulpfile.js
var clone = require('gulp-clone');
gulp.task("default", function() {
var normal = gulp.src( destination + '*.png' );
var retina = normal.pipe(clone());
normal.pipe(makeSprites())
.pipe(gulp.dest( imagesBase + '1x/' ));
var YError = require('yerror');
var _localDateCopy = global.Date;
var DateMock = {
_mocking: false,
_pendingQueue: [],
_assignedQueue: [],
_pendingIndex: 0,
start: function(theTimeQueue, options) {
@nfroidure
nfroidure / gist:3608274
Created September 3, 2012 10:06
Convert a number to an amount
Number.prototype.toAmount = function() {
var parts=(this+'').split('.');
parts[0]=(parts[0]?parts[0]:'0');
parts[1]=(parts[1]?parts[1].substring(0,2):'00');
parts[1]+=(parts[1].length==1?'0':'');
return parts[0]+'.'+parts[1];
}
var price=12.112;
console.log(price.toAmount()); // Outputs 12.11
@nfroidure
nfroidure / gist:3727624
Created September 15, 2012 12:43
Migration
#! /bin/sh
# Init
cd /
if [ "$1" != "Y" ]; then
echo "$0 1:sure(Y/N)"
else
while read orgid database
do
@nfroidure
nfroidure / gist:4663042
Last active December 11, 2015 21:29
How to handle errors on chaining APIs
// Chaining API for URIBuilder
var uri=new URLBuilder().parse('bad_url_format').addQueryParam('param','value').setPort('443').toString();
// How to handle the bad url parse error ?
// Don't want to throw exception
// Can't return null
// Chainable API for URIBuilder
var uri = new URLBuilder(logErrorHandler)
.parse('bad_url_format')
.addQueryParam('param','value')
.setPort('443')
.toString();
function logErrorHandler(err, url_object){
if('parse_error'===err.type)