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 / README.md
Last active February 8, 2022 14:23
API docs with CORS

Usage

To use this with any API, just clone the Gist and run the following:

NGINX_API_URL=https://api.example.com API_PATH=/v0/openAPI docker-compose up

Finally browse to : http://docs.localhost:16640.

// Programme qui compte jusque l'infini
// Par Thomas et Nicolas Froidure Stiernon
const depart = Date.now();
let compteur = 0;
while(true) {
if(Math.floor(Math.log10(compteur + 1)) > Math.floor(Math.log10(compteur))) {
console.log(compteur + 1, Math.round((Date.now() - depart) / 60000));
}
@nfroidure
nfroidure / gen_pg_graph.sh
Created November 30, 2020 16:02
Generate a PGSQL Graph
docker run \
-v $(pwd)/pgsql/docs:/home/schcrwlr/share \
--name schemacrawler \
--rm -i -t \
--entrypoint=/bin/bash schemacrawler/schemacrawler \
-c "/opt/schemacrawler/schemacrawler.sh --command=schema --output-format=png --output-file=/home/schcrwlr/share/graph.png --server=postgresql --host=\$(/sbin/ip route|awk '/default/ { print \$3 }') --port=15432 --database=diagrams --schemas=public --user=postgres --password=mysecretpassword --info-level=maximum --log-level=ALL"
<json:object>
<json:string name="text">Hello world!</json:string>
</json:object>
@nfroidure
nfroidure / knifecycle-sample2.js
Created January 26, 2019 11:15
Another example with service renaming
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 January 26, 2019 11:13
Sample usage of Knifecycle
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 January 12, 2019 07:23
Shows the result of packing a NPM module
tar tvf $(npm pack)
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);
package main
import (
"bufio"
"fmt"
"log"
"math"
"os"
"path/filepath"
"strconv"
@nfroidure
nfroidure / manual.js
Created June 5, 2017 09:44
`swagger-http-router` with manual DI
import { getInstance, initializer } from 'knifecycle';
import uuid from 'uuid';
import { initDelayService } from 'common-services';
import {
initRouter,
initHTTP,
initHTTPTransaction
} from 'swagger-http-router';