Skip to content

Instantly share code, notes, and snippets.

View jsmrcaga's full-sized avatar

Jo Colina jsmrcaga

View GitHub Profile
// Tested on node 18
// The result is sequential
function rand_promise(i) {
return new Promise((r) => {
const timeout = Math.random() * 1000;
setTimeout(() => r(i), timeout);
});
}
@jsmrcaga
jsmrcaga / cf_regions_colo.json
Created July 1, 2023 11:35
Cloudflare COLO region codes
{
"CGB": {
"city": "Cuiabá",
"country": "Brazil"
},
"COR": {
"city": "Córdoba",
"country": "Argentina"
},
"BTS": {
server {
listen 80;
server_name pgw.bottomatik.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
gzip on;
gzip_http_version 1.0;
gzip_min_length 256;
Verifying my Blockstack ID is secured with the address 12ZijDjYwb1us93s3JT8JMXKs2f8FBE1aa https://explorer.blockstack.org/address/12ZijDjYwb1us93s3JT8JMXKs2f8FBE1aa
@jsmrcaga
jsmrcaga / version-args.js
Created May 1, 2019 05:09
A simple version reporter
if (process.argv && process.argv.indexOf('-v') > -1) {
const { name, version } = require('./package.json');
return console.log(`${name} version ${version}`);
}
/*
Example:
node mystuff.js -v
> mystuff version 3.0.4
@jsmrcaga
jsmrcaga / webauthn.md
Last active March 7, 2019 08:42
WebAuthn API compilation

WebAuthn Protocol

Utility

ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer;

let challenge = ArrayBuffer.from('super hard challenge created in server');
let id = ArrayBuffer.from('id created in server')

@jsmrcaga
jsmrcaga / webauthn.md
Created March 7, 2019 08:21
WebAuthn API compilation

WebAuthn Protocol

Utility

ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer;

let challenge = ArrayBuffer.from('super hard challenge created in server');
let id = ArrayBuffer.from('id created in server')

// INSTRUCTIONS
/*
* 1) Run node sigint.js and call ctrl-c, then wait 1 second (for process to exit)
* Expected output: SIGINT 1
*
* 2) Run npm start (see end of file for example, which runs node sigint.js) and call ctrl-c, then wait 1 second (for process to exit)
* Expected output SIGINT 1
* Unexpected output SIGINT 2
*/
const fs = require('fs');
console.time('Reading CSV...');
let csv = fs.readFileSync('./rocket.csv', {encoding: 'utf8'});
console.timeEnd('Reading CSV...');
let lines = csv.split('\n');
let names = lines.splice(0,1)[0].split(';');
console.log('Got names', names.join(', '));
console.log('And', lines.length, 'lines');
@jsmrcaga
jsmrcaga / Git Magic
Created December 13, 2016 13:34
Command to auto rebase a branch from another.
[alias]
magic = "!sh -c 'git checkout \"$1\" && git pull && git checkout \"$0\" && git rebase \"$1\"'"