Skip to content

Instantly share code, notes, and snippets.

View JosePedroDias's full-sized avatar

José Pedro Dias JosePedroDias

View GitHub Profile
@JosePedroDias
JosePedroDias / async-map.js
Created October 2, 2017 22:32
async map with promises :D each doesn't seem to work sync by the time we call the promise-returning function we're already starting it. I believed so but by runnign the example it gets obvious
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function sleep2(n) {
return new Promise(resolve => {
console.log('FIRED ' + n);
sleep(500).then(() => {console.log(n); resolve(n); });
});
}
@JosePedroDias
JosePedroDias / beaker.md
Last active September 21, 2017 01:55
Some thoughts on Beaker browser and using the DAT format for multi-user experiences

Beaker browser and the DAT format - thoughts on usage for multi-user experiences

some considerations on DAT and its features

Each DAT has a large hex id (chosen at random), which has several purposes:

  • it inequivocally identifies the DAT archive itself
  • it is used to encrypt the archive along the wire between peers
  • it remains the same during DAT changes
@JosePedroDias
JosePedroDias / README.md
Last active September 13, 2017 11:01
render binary content as hex editor do

Renders binary content such as Uint8Arrays to an hex layout similar to hex editor such as Hex Fiend and Frhed

Example output:

0000 0000001c 66747970 69736f36 00000001 69736f6d 69736f36 6d736468 000002a7 
0020 6d6f6f76 00000078 6d766864 01000000 00000000 00000000 00000000 00000000 
0040 00989680 00000000 53291000 00010000 01000000 00000000 00000000 00010000 
0060 00000000 00000000 00000000 00010000 00000000 00000000 00000000 40000000 

0080 00000000 00000000 00000000 00000000 00000000 00000000 00000002 000001ff

@JosePedroDias
JosePedroDias / handmade-jscrunch.js
Created September 3, 2017 03:39
handmade js crunch
const CHARS = `αβγδϵζηθικλμνξοπρστυϕχψωΓΔΘΛΞΠΣΦΨΩ`;
function replaceAll(txt, a, b) {
return txt.split(a).join(b);
}
function generateCrunchedCode(code, replacements) {
let a = code;
let b = '';
@JosePedroDias
JosePedroDias / jscrunch_by_hand.js
Created September 3, 2017 02:18
jscrunch by hand
// HAND MADE JSCRUNCH
ORIGINAL_CODE = '-que tal está isso asd? quero que fiques comigo querida asd.'
// naive approach
// 1) replace 'que' with ''
_ = '- tal está isso asd? ro  fis comigo rida asd.'
_.split('').join('que')
@JosePedroDias
JosePedroDias / beforeAndAfter.js
Last active July 11, 2017 12:51
before and after hooks for api methods
'use strict';
// call something before the method(s)
function toArr(arrLike) {
return Array.prototype.slice.apply(arrLike);
}
function beforeMethod(parent, methodName, beforeFn) {
@JosePedroDias
JosePedroDias / srtize.js
Last active February 21, 2020 20:13
load SRT file into WebVTT track for a video element in the page
'use strict';
function parseTime(s) {
let t = 0;
const p = s.split(':');
let ss = p.pop().replace(',', '.');
t += parseFloat(ss);
ss = parseInt( p.pop() || '0', 10);
t += ss * 60;
ss = parseInt( p.pop() || '0', 10);
Verifying that "josepedrodias.id" is my Blockstack ID. https://onename.com/josepedrodias
@JosePedroDias
JosePedroDias / wifi_location_server.js
Created October 5, 2016 11:42
wifi location server (draft). using the find android client here: https://github.com/schollz/find
'use strict';
const fs = require('fs');
const http = require('http');
const os = require('os');
const HEADERS = {
'Content-Type': 'application/json',