Skip to content

Instantly share code, notes, and snippets.

🌻
Getting greener

Nicolas Froidure nfroidure

🌻
Getting greener
Block or report user

Report or block nfroidure

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test.jsonx
<json:object>
<json:string name="text">Hello world!</json:string>
</json:object>
@nfroidure
nfroidure / knifecycle-sample2.js
Created Jan 26, 2019
Another example with service renaming
View knifecycle-sample2.js
import { Knifecycle, constant, autoService, service } from 'knifecycle';
// Initialize the injector
const $ = new Knifecycle();
// Declare constants
$.register(constant('FTP_CONFIG', { user: 'test', password: 'test' }));
$.register(constant('FTP_CONFIG2', { user: 'test2', password: 'test2' }));
// Declare services
@nfroidure
nfroidure / knifecycle-sample.js
Last active Jan 26, 2019
Sample usage of Knifecycle
View knifecycle-sample.js
import { Knifecycle, constant, autoService, autoProvider } from 'knifecycle';
// Initialize the injector
const $ = new Knifecycle();
// Declare constants
$.register(constant('FTP_CONFIG', { user: 'test', password: 'test' }));
$.register(constant('DB_CONFIG', { user: 'test', password: 'test' }));
@nfroidure
nfroidure / npm-pkg-files.sh
Created Jan 12, 2019
Shows the result of packing a NPM module
View npm-pkg-files.sh
tar tvf $(npm pack)
View message.js
function buildMessage(values) {
const DIFF = Math.pow(2, 9); // 512
const MAX_PRECISION = 4; // 512 * 4 allows to encode 300 <= x <= 1100
const maxIndex = values.indexOf(Math.max(...values));
const minIndex = values.indexOf(Math.min(...values));
const maxDiff = values.reduce(
(diff, v) => Math.max(v - values[minIndex], diff),
0
);
const precision = Math.ceil(maxDiff / DIFF);
View script.go
package main
import (
"bufio"
"fmt"
"log"
"math"
"os"
"path/filepath"
"strconv"
@nfroidure
nfroidure / manual.js
Created Jun 5, 2017
`swagger-http-router` with manual DI
View manual.js
import { getInstance, initializer } from 'knifecycle';
import uuid from 'uuid';
import { initDelayService } from 'common-services';
import {
initRouter,
initHTTP,
initHTTPTransaction
} from 'swagger-http-router';
@nfroidure
nfroidure / api.swagger.json
Created May 11, 2017
API Client generation experiment
View api.swagger.json
{
"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 Nov 7, 2016
A worflow oriented controller
View workflow-oriented-controller.js
// 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) => {
View middlewares-anti-pattern.js
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?
You can’t perform that action at this time.