Skip to content

Instantly share code, notes, and snippets.

View stefanocudini's full-sized avatar
🏔️
working from Alps

Stefano Cudini stefanocudini

🏔️
working from Alps
View GitHub Profile
function listenLog(app) {
console.log('listen paths', app._router.stack.filter(r => r.route).map(r => `${Object.keys(r.route.methods)[0]} ${r.route.path}`) );
console.log(`listening at http://localhost:${this.address().port}`);
/*
//TODO manage sigterm
process.on('SIGTERM', () => {
console.error('[geocoder-pelias-services] closing...')
serverParser.close();
});*/
}
@stefanocudini
stefanocudini / fastify-print-routes.js
Created November 11, 2022 14:40
fastify print routes
function getRouteConfig(r) {
return r.config ?? {}
}
module.exports = function printRoutes(routes) {
if (routes.length === 0) {
return
}
@stefanocudini
stefanocudini / rnd.js
Created September 15, 2022 09:21
mini random string in nodejs
let prevs = [];
while(true) {
const rnd = Buffer.from((10*Math.random()).toString()).toString('base64').substr(3,20)
//NS42MDExOTQwNTEzMjkwMDQ=
//console.log(rnd)
prevs.push(rnd)
let i = prevs.indexOf(rnd);
if(i>-1) {
prevs[i] += '#'
@stefanocudini
stefanocudini / wget.ext.sh
Created August 18, 2022 14:02
wget file ext
wget -A pdf,jpg -m -p -E -k -K -np http://site/path/
@stefanocudini
stefanocudini / .tmux.conf
Created February 11, 2022 16:47
tmux enable mouse for version 2.6
set-option -g mouse on
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stefanocudini
stefanocudini / stripYmlComments.js
Created October 18, 2021 15:30
Strip Yaml Comments in nodejs
function stripComments(ymltext) {
const lines = ymltext.split(/\r?\n/).map(line => {
const trim = line.trim();
return trim[0]!=='#' ? line : '';
}).filter(line => {
return line;
});
return lines.join('\n')+'\n';
@stefanocudini
stefanocudini / expressjs_get_entrypoint.js
Created October 14, 2021 09:13
expressjs list of defined entrypoint in app
function availableRoutes() {
return app._router.stack
.filter(r => r.route)
.map(r => {
return {
method: Object.keys(r.route.methods)[0],
path: r.route.path
};
});
}
@stefanocudini
stefanocudini / filesize.js
Created October 6, 2021 18:41
filesize human in nodejs/javascript
function filesize(bytes) {
if (bytes === 0) return bytes;
var sizes = ['Bytes','KB','MB','GB','TB'],
i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 1) + ' ' + sizes[i];
}
@stefanocudini
stefanocudini / bbox4routing.js
Created September 15, 2021 11:39
osm bbox for routers
function getBoundingBox(data) {
var bounds = {}, coordinates, point, latitude, longitude;
// Loop through each "feature"
for (var i = 0; i < data.features.length; i++) {
coordinates = data.features[i].geometry.coordinates;
if(coordinates.length === 1){
// It's only a single Polygon
// For each individual coordinate in this feature's coordinates...