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 / 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 / times.js
Created February 5, 2012 22:45
Ruby .times & .upto & .downto methods in JavaScript
// 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 11:06 — forked from alexjs/cors-nginx.conf
Slightly tighter CORS config for nginx
#
# 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.
#
@FGRibreau
FGRibreau / keycloak-route-patterns-to-keep-open.txt
Created February 8, 2020 11:55
Minimal Keycloak route patterns to keep open (whitelist)
/auth/realms/<realm>/protocol/openid-connect/token
/auth/realms/<realm>/protocol/openid-connect/logout
/auth/realms/<realm>/protocol/openid-connect/auth
/auth/realms/<realm>/login-actions/first-broker-login
/auth/realms/<realm>/broker/after-first-broker-login
@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
$('#el').AttributeObserver(attr, callback, [delay]);
@FGRibreau
FGRibreau / convert.zsh
Created June 2, 2014 14:43
Convert MTS to MOV
for file in ./*.MTS
do
ffmpeg -i $file -vcodec mjpeg -b 100M -acodec pcm_s16be $file.mov
done
@FGRibreau
FGRibreau / PostgresToSNSWorker.js
Created March 4, 2017 20:39
PostgresToSNSWorker
// Basic PostgresToSNSWorker worker
const pg = require ('pg');
const pgConString = process.env.POSTGRESQL_CONNECTIONSTRING;
pg.connect(pgConString, function(err, client) {
if(err) {
console.log(err);
}
client.on('notification', function(msg) {
@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 / 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'}])