Skip to content

Instantly share code, notes, and snippets.

View FGRibreau's full-sized avatar
✍️
writing "#NoBullshit Tech-Lead" book https://getnobullshit.com

Francois-Guillaume Ribreau FGRibreau

✍️
writing "#NoBullshit Tech-Lead" book https://getnobullshit.com
View GitHub Profile
@FGRibreau
FGRibreau / getFriendsv1.js
Last active December 13, 2015 17:28
#IUT #Nantes Lectures on NodeJS
// Mix async (request) + sync (writeFile) style
var request = require('request')
, async = require('async')
, fs = require('fs')
, friends = require('./friends');
function getImgPath(friend){
return './public/'+friend.uid+".jpg";
}
@FGRibreau
FGRibreau / post-commit
Created February 5, 2013 21:11
Keep gh-pages in sync with master on git post-commit hook
#!/bin/sh
git checkout gh-pages
git rebase master
git checkout master
@FGRibreau
FGRibreau / hack.sh
Last active December 12, 2015 01:28 — forked from erikh/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@FGRibreau
FGRibreau / underscore_template_err.js
Last active May 24, 2018 10:37
Add the following code just after UnderscoreJS declaration to find where _.template calls are run against empty templates.
/**
* Add the following code just after UnderscoreJS declaration to find
* where _.template calls are run against empty templates.
*/
(function(old){
_.template = function(str, data) {
if(!str){
console.error("Could not load template", new Error().stack);
@FGRibreau
FGRibreau / uglifyjs-benchmark-results.md
Created December 15, 2012 15:31
Real-world benchmark results of UglifyJS v1 vs UglifyJS v2

Compressing 4 bundles with Pound (npm view pound) with JavaScript production code from https://redsmin.com


UglifyJS v1

  • times: 37720ms 36971ms
  • output size: 533Ko, 479Ko, 120Ko, 538Ko
@FGRibreau
FGRibreau / table.filter.lua
Created September 26, 2012 19:59
Lua table.filter (JavaScript Array::filter equivalent)
-- table.filter({"a", "b", "c", "d"}, function(o, k, i) return o >= "c" end) --> {"c","d"}
--
-- @FGRibreau - Francois-Guillaume Ribreau
-- @Redsmin - A full-feature client for Redis http://redsmin.com
table.filter = function(t, filterIter)
local out = {}
for k, v in pairs(t) do
if filterIter(v, k, t) then out[k] = v end
end
@FGRibreau
FGRibreau / strpad.lua
Created September 26, 2012 19:00
Strpad function in LUA
-- strpad(input, pad_length, [pad_string], [pad_type])
-- (php-style) implemented in LUA (inspired from https://gist.github.com/2625581)
-- @FGRibreau - Francois-Guillaume Ribreau
-- @Redsmin - A full-feature client for Redis http://redsmin.com
local function strpad(input, pad_length, pad_string, pad_type)
local output = input
if not pad_string then pad_string = ' ' end
if not pad_type then pad_type = 'STR_PAD_RIGHT' end
@FGRibreau
FGRibreau / hash_range.js
Created September 21, 2012 09:28
My yesterday night 1 hour code rush: JavaScript Hash with Range-based keys
/**
* September 20 night: 1 hour code rush
* @FGRibreau
*
* Requirements
* ------------
* The aim of this code rush is to enable developers to define a "range hash map"
* in a very expressive way (without if/then/else).
*
* Data-set
@FGRibreau
FGRibreau / console_patch.js
Created September 6, 2012 11:56
Add timestamp information to the JavaScript console
/**
* Patch the console methods in order to provide timestamp information
*
* Usage:
* > console.log('ok')
* 2012-09-06T11:52:56.769Z ok true
*
* Note:
* The patch will only be applied with the first call.
*
@FGRibreau
FGRibreau / array.until.js
Created August 20, 2012 21:53
Array::until - Return the array elements until a selector is matched #javascript
Object.defineProperty(Array.prototype, 'until',{
/**
* Return the array elements until a selector is matched
* @param {Number|String|Function} selector
* @return {Array} A new array that goes from the first element to `selector`
*
* Usage:
* deepEqual([1,2,3,4,5].until(4), [1, 2, 3, 4])
* deepEqual(['a','b','c','d','e'].until('c'), ['a', 'b', 'c'])
* deepEqual([{t:'a'},{t:'b'},{t:'c'},{t:'d'}].until(function(o){return o.t == 'c';}), [{t:'a'},{t:'b'},{t:'c'}])