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 / api.swagger.json
Created May 11, 2017 07:25
API Client generation experiment
{
"swagger": "2.0",
"info": {
"description": "WMG web services running altogether",
"version": "5.6.0",
"title": "infrastructure-wmg"
},
"host": "localhost:1664",
"schemes": [
"https"
@nfroidure
nfroidure / workflow-oriented-controller.js
Last active November 7, 2016 07:51
A worflow oriented controller
// No middleware, just pur functions
import getBodyFromReq from 'pureBodyParser';
import getQueryFromReq from 'pureQueryParser';
import sendToRes from 'pureResponseMaker';
// Use dependency injection for required services
// app/config/timer just come from this function caller
module.exports = ({ app, config, timer}) => {
app.post((req, res) => {
@nfroidure
nfroidure / middlewares-anti-pattern.js
Last active November 6, 2016 09:41
Express midlewares hell
module.exports = (app) => {
// where ther hell is this config set?
const config = app.get('config');
// How can i see what this timer do?
const timer = app.get('timer');
app.post((req, res, next) => {
const data = {};
// Which middleware set up this query params?

Notre PR, qui est soumise

que ton code soit accepté

que ton merge vienne

que ta review soit faîte

sur le code comme les tests.

@nfroidure
nfroidure / calculator.js
Last active July 11, 2016 13:07
Simple calculator
var operators = {
'+': (a, b) => a + b,
'-': (a, b) => a - b,
'*': (a, b) => a * b,
'/': (a, b) => a / b,
};
function calculator (str) {
return str.split(/\s*(\+|-)\s*/g)
.map(substr => {
@nfroidure
nfroidure / nock-recorder.js
Last active August 5, 2019 08:11
Snippet to record HTTP traffic
import fs from 'fs';
import nock from 'nock';
nock.recorder.rec({
logging: content => fs.appendFileSync('./nock-records.log', content),
});
@nfroidure
nfroidure / MongoObjectId.cls
Created March 4, 2016 09:38
Generating a MongoDB ObjectId in SalesForce Apex
public with sharing class MongoObjectId {
private static final Integer COUNTER_MASK = 16777215; // 0xFFFFFF
private static final Integer PID_MASK = 65535; // 0xFFFF
private static final String MACHINE_PART = '050135';
private static final String[] hexMap = '0123456789abcdef'.split('');
private static Integer counter = -1;
public static void seed() {
// Seed once or force reseed when testing
if(-1 == counter || Test.isRunningTest()) {
var YError = require('yerror');
var _localDateCopy = global.Date;
var DateMock = {
_mocking: false,
_pendingQueue: [],
_assignedQueue: [],
_pendingIndex: 0,
start: function(theTimeQueue, options) {
@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 CSV = require('oh-csv');
process.stdout.write(
'<?xml version="1.0" encoding="UTF-8"?>' + '\r\n' +
'<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"' + '\r\n' +
' xmlns:dsq="http://www.disqus.com/" xmlns:dc="http://purl.org/dc/elements/1.1/"' + '\r\n' +
' xmlns:wp="http://wordpress.org/export/1.0/">' + '\r\n' +
' <channel>' + '\r\n'
);