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
@stefanocudini
stefanocudini / gist:af8bfd0da0c4e1ef24917f5f4171d00b
Created November 7, 2023 15:11
fix ubuntu audio bluetooth
##https://askubuntu.com/questions/1248886/how-to-set-default-profile-for-bluetooth-headset
echo "load-module module-card-restore restore_bluetooth_profile=true" >> /etc/pulse/default.pa
sudo alsa force-reload
sudo systemctl restart bluetooth.service
@stefanocudini
stefanocudini / read_stdin.js
Created August 11, 2023 16:03
read stdin in nodejs
let rawInput = '';
process.stdin.on('readable', function() {
const chunk = process.stdin.read();
if (chunk !== null) {
rawInput += chunk;
}
});
process.stdin.on('end', function() {
const converted = convert(rawInput);
@stefanocudini
stefanocudini / ssh-pipe.sh
Created May 11, 2023 22:22
trasnfer pipe via ssh
#TODO test
outfile=$(basename $1)
dd if=$1 | ssh remoteuser@ip.addresss.of.remote.machine 'dd of=${outfile}'
@stefanocudini
stefanocudini / secure-random.sh
Created May 2, 2023 23:53
cryptographically secure random
#https://security.stackexchange.com/questions/183948/unix-command-to-generate-cryptographically-secure-random-string
LC_ALL=C tr -dc '[:alnum:]' < /dev/urandom | head -c32
@stefanocudini
stefanocudini / backup-mate-panel.sh
Created April 23, 2023 12:00
backup restore mate panel launchers
#!/bin/bash
dconf dump /org/mate/panel/ > panel.conf
#restore
#dconf load /org/mate/panel/ < panel.conf
@stefanocudini
stefanocudini / valid-locations.js
Last active January 17, 2023 22:16
regexpression test stringified array of locations
/**
test str is formatted "11.2,46.1|11,46|11.2,46.1|11.1,46.2"
*/
function validLocations(str) {
const regAll = /(?=^([^\|]*\|){3}[^\|]*$)(?=^([^,]*,){4}[^,]*$)/
// contains min 3 pipe and 4 commas
, regPipe = /^([^\|]*\|){3,}[^\|]*$/
@stefanocudini
stefanocudini / geopicker_api.md
Last active September 7, 2023 15:27
geopocker api rest endpoints

API Rest endpoints

The API is work in progress. This basic structure can be extended starting from the environment variable PREFIX which by default /

(✔️ Work ❌ TODO 🚧 Work in Progress)

Status Method Path Return Description
✔️ GET / html default demo map page if enabled by env var DEMO_PAGE=true
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] += '#'