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 / merge.js
Created August 15, 2012 23:11 — forked from joseanpg/extend_and_merge.js
Merge as it should be ( == $.extend(true, {}, ...))
function myextend(/* args */){
var o = {}
, args = Array.prototype.slice.call(arguments)
, obj = args.shift()
, src = args.shift();
for (var p in src){
if (src.hasOwnProperty(p)){
if (hasOwn.call(obj,p) && typeof obj[p] === 'object' && obj[p] !== null) {
o[p] = myextend(obj[p],src[p]);
@FGRibreau
FGRibreau / existsSync.js
Last active July 17, 2023 10:19
existsSync - Check if a file exist in NodeJS
/*
fileExistSync - Check if a file exist in NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var fileExistSync = require('./fileExistSync');
var exist = fileExistSync('/var/folders/zm/jmjb49l172g6g/T/65b199');
Support for Nodev0.6
@FGRibreau
FGRibreau / extractArgs.js
Created July 25, 2012 12:47
Extract arguments from a string (quoted or not)
function extractArgs(str){
var args = [], buff = '', idx = -1, insideQuote = false, lgth = str.length;
function next(){return str.charAt(++idx);}
function peak(){return str.charAt(idx+1);}
function resetState(){insideQuote = false;buff = '';}
while(idx < lgth){
var c = next();
@FGRibreau
FGRibreau / .gitignore
Created July 18, 2012 12:29
Find if a NodeJS module is available to require or not
node_modules
@FGRibreau
FGRibreau / grunt_growl.js
Created June 6, 2012 09:10
How to get Growl notifications from Grunt.js
/* Inside grunt.js file (don't forget to add "growl" as a project dependency) */
grunt.utils.hooker.hook(grunt.fail, "warn", function(opt) {
require('growl')(opt.name, {
title: opt.message,
image: 'Console'
});
});
/*
* Fix the "Could not decode a text frame as UTF-8." bug #socket.io #nodejs #websocket
*
* Usage:
* cleanedString = filterUnicode(maybeHarmfulString);
*
* Original work-around from SockJS: https://github.com/sockjs/sockjs-node/commit/e0e7113f0f8bd8e5fea25e1eb2a8b1fe1413da2c
* Other work-around: https://gist.github.com/2024272
*
*/
@FGRibreau
FGRibreau / hack.sh
Created March 31, 2012 11:48 — forked from erikh/hack.sh
OSX For Hackers
#!/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/2262723/hack.sh | sh
#
@FGRibreau
FGRibreau / myapp.js
Created March 6, 2012 12:37
NodeJS Process Management at Brin.gr
//
// The following snippet must be inserted at the top of your main js file
//
process.title = "myapp";
var PID_FILE = "/usr/local/var/run/"+process.title+".pid"
, fs = require('fs');
fs.writeFileSync(PID_FILE, process.pid+"\n");
@FGRibreau
FGRibreau / output.php
Created February 22, 2012 19:21
Testing PHP-Parser
array(21) {
[0]=>
object(PHPParser_Node_Expr_Assign)#6 (3) {
["subNodes":protected]=>
array(2) {
["var"]=>
object(PHPParser_Node_Expr_ArrayDimFetch)#4 (3) {
["subNodes":protected]=>
array(2) {
["var"]=>
@FGRibreau
FGRibreau / pid.js
Created February 16, 2012 18:41
Simple snippet for cross-platform .pid management in NodeJS. I use it for managing NodeJS apps with supervisord and monit
//
// Usage: require('./pid')("myapp");
//
var fs = require('fs');
module.exports = function(appname){
process.title = appname;
var PID_FILE = "/usr/local/var/run/"+process.title+".pid";