Skip to content

Instantly share code, notes, and snippets.

Avatar
🕉️
all good

José Pedro Dias JosePedroDias

🕉️
all good
View GitHub Profile
@JosePedroDias
JosePedroDias / README.md
Last active Dec 1, 2017
svg path to polygon (doesn't support curve segments, only LlMmHhVvZz, assumes commands are space separated!)
View README.md
const d =
  "M 12.773125,113.36602 221.3132,95.992053 l 12.11088,1.651482 10.58724,6.605925 7.48176,8.10713 2.84979,11.98594 -1.51508,13.41407 -4.62098,9.90131 -9.00254,8.33802 -9.58241,3.43426 -12.70975,0.58031 -203.961053,-17.77707 -5.9080342,-2.37991 -3.4503706,-4.50127 -1.9267305,-6.60592 1.1009889,-7.00904 3.5114276,-5.52164 z";
const p = svgDToPoly(d);

p would then be

[
@JosePedroDias
JosePedroDias / bootstrap.js
Created Oct 25, 2017
You want to serve a browser bundle with Reach, superagent and parse jsx scripts with type="text/jsx"? Install and run `npm run bundle`. You can expose additional content in the window too.
View bootstrap.js
window.React = require('react');
window.ReactDOM = require('react-dom');
window.superagent = require('superagent');
(function() {
'use strict';
const jsx = require('jsx-transform');
const jsxScriptEls = Array.prototype.slice.apply( document.body.querySelectorAll('script[type="text/jsx"]') );
@JosePedroDias
JosePedroDias / EL.js
Created Oct 5, 2017
create elements in a snabbdom-like way, without any virtual thingie. small and opinionated.
View EL.js
function EL(_nodeName, _attrs, _children) {
let attrs = {}, children = [];
const argLen = arguments.length;
if (argLen === 1) { return document.createTextNode(_nodeName); }
else if (argLen === 2) {
if (_attrs instanceof Array) { children = _attrs; }
else if (_attrs instanceof Object) { attrs = _attrs; }
else { throw new Error('2nd arg must be either an object (attrs) or an array (children)!'); }
}
else if (argLen === 3) { attrs = _attrs; children = _children; }
@JosePedroDias
JosePedroDias / mapLimit.js
Last active Oct 4, 2017
map limit with promises. play with it here: https://jsbin.com/fazihoc
View mapLimit.js
function eachN(arr, n) {
const arr0 = arr.slice();
const arrs = [];
while (arr0.length > 0) {
arrs.push( arr0.splice(0, n) );
}
return arrs;
}
function mapLimit(arr, promFn, limit) {
@JosePedroDias
JosePedroDias / async-map.js
Created Oct 2, 2017
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
View async-map.js
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 Sep 21, 2017
Some thoughts on Beaker browser and using the DAT format for multi-user experiences
View beaker.md

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
View README.md
@JosePedroDias
JosePedroDias / README.md
Last active Sep 13, 2017
render binary content as hex editor do
View README.md

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 
View handmade-jscrunch.js
const CHARS = `αβγδϵζηθικλμνξοπρστυϕχψωΓΔΘΛΞΠΣΦΨΩ`;
function replaceAll(txt, a, b) {
return txt.split(a).join(b);
}
function generateCrunchedCode(code, replacements) {
let a = code;
let b = '';
View jscrunch_by_hand.js
// 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')