Skip to content

Instantly share code, notes, and snippets.

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 / .gitignore
Created Jul 18, 2012
Find if a NodeJS module is available to require or not
View .gitignore
node_modules
@FGRibreau
FGRibreau / pid.js
Created Feb 16, 2012
Simple snippet for cross-platform .pid management in NodeJS. I use it for managing NodeJS apps with supervisord and monit
View pid.js
//
// 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";
@FGRibreau
FGRibreau / table.filter.lua
Created Sep 26, 2012
Lua table.filter (JavaScript Array::filter equivalent)
View table.filter.lua
-- 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 / 1_stripe-schema.md
Last active Jan 2, 2021
Stripe database schema (extracted from their sigma product) as of 2019-10-09
View 1_stripe-schema.md
jqn -r markdown-table 'map(x => "## " + x.name + "\n\n" + markdownTable(x.columns.map(y => [y.name, y.type]))  ) | join("\n\n")' < /tmp/stripe.json

accounts

id varchar
business_name varchar
business_url varchar
View Firebug chained methods - Usage.js
//Do this only one time !
makeChainable(console, 'assert clear count debug dir dirxml error exception group groupCollapsed groupEnd info log profile profileEnd time timeEnd warn'.split(' '));
//Usage:
console
.profile()
.time('testTime')
.group('GroupTest')
.debug('test', 1, 2, 3)
.warn('warniiing!')
@FGRibreau
FGRibreau / myapp.js
Created Mar 6, 2012
NodeJS Process Management at Brin.gr
View myapp.js
//
// 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 / HeaderValueExt.rs
Last active Nov 19, 2020
Convert a HeaderValue into a rust String
View HeaderValueExt.rs
/// Additional conversion methods for `HeaderValue`.
pub trait HeaderValueExt {
fn to_string(&self) -> String;
}
impl HeaderValueExt for HeaderValue {
fn to_string(&self) -> String {
self.to_str().unwrap_or_default().to_string()
}
}
@FGRibreau
FGRibreau / 0_readme.md
Created Nov 2, 2013
Mock NodeJS net.Socket with ReadWriteStream
View 0_readme.md
var dummySocket = new ReadWriteNetStream();

// Debug
dummySocket.on('data', function(data){
console.log('write received', data);
});

dummySocket.write('hey !');
@FGRibreau
FGRibreau / times.js
Created Feb 5, 2012
Ruby .times & .upto & .downto methods in JavaScript
View times.js
// Ruby = 5.times { |i| puts i }
// JS = (1).times(function(i){console.log(i);})
Number.prototype.times = function(cb) {
var i = -1;
while (++i < this) {
cb(i);
}
return +this;
@FGRibreau
FGRibreau / cors-nginx.conf
Last active May 26, 2020 — forked from alexjs/cors-nginx.conf
Slightly tighter CORS config for nginx
View cors-nginx.conf
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#