Skip to content

Instantly share code, notes, and snippets.

all good

José Pedro Dias JosePedroDias

all good
View GitHub Profile
View set-operations.js
// s1 contains all elements of s2
function setContains(s1, s2) {
return new Set([...s2].every(x => s1.has(x)));
// elements in both s1 and s2
function setIntersection(s1, s2) {
return new Set([...s1].filter(x => s2.has(x)));
JosePedroDias /
Last active Oct 4, 2019
ldjam 45 ideas

THEME: Start with nothing


  • there's a character with a preset script of directions he will take. We get those as an overlay
  • our job is to make the hero reach somewhere in the initially empty map by adding tiles

social twist:

  • if each set of movements is driven by a seed of a random number generator, we can map different solutions of the same movements to different ending maps.
JosePedroDias /
Created Sep 29, 2019
jsonlish stringify

jsonlines and similar formats where each payload is stored as unindented JSON chunks divided by newlines are great for complex systems.

My application is more to aid in exploring large JSON files and copying/pasting, chunks in the editor, therefore made this small JSON stringifier that breaks the 1st level of arrays and objects with newlines,while returning valid JSON.

The placement of commas is intentional. This way one can find the item, right, shift+end, copy.


JSON number limits

So we we're using an API which returns a JSON response. One of its attributes is a numeric key. Due to historical reasons we're now being served longer number (longs) so the server, which is not based on JavaScript, started returning long integers.

I had heard about issues like this but hadn't cross against a real use case before.

So what started happening on our JavaScript clients (browser and React Native alike) is that the primitive value we get back once we get the fetch json promise resolved is an overflown number.

JavaScript engines commonly have the symbol Number.MAX_SAFE_INTEGER so one can retrieve the number above which problems start to appear (it is 9007199254740991).

View wc.html
<!DOCTYPE html>
<meta charset="utf-8" />
<title>webcomponents test</title>
JosePedroDias / log.js
Created Jan 18, 2019
basic logging to document
View log.js
function log(...args) {
// console.log.apply(console, args);
args = =>
typeof arg === 'object' ? JSON.stringify(arg) : arg
const preEl = document.createElement('pre');
const codeEl = document.createElement('code');
codeEl.appendChild(document.createTextNode(args.join(' ')));
JosePedroDias / deepTransformValues.js
Created Jun 18, 2018
transforms values from json file (simple version)
View deepTransformValues.js
const O = {
a: 2,
b: '3',
c: [5, [6, 'a'], {e:'c', f:2}],
d: {z:[3, 'd']}
function deepTransformValues(mapFn, o) {
if (o instanceof Array) {
JosePedroDias / reactHooks.js
Created Mar 13, 2018
expose react hook internals
View reactHooks.js
(function() {
var noop = function() {};
var helpers = h.helpers[ Object.keys(h.helpers)[0] ];
window.helpers = helpers;
function(r) {
window.root = r;
# based on
# mitmproxy -s
# mitmdump -s
from mitmproxy import http
def response(flow):
h = flow.request.headers
View ajax.js
function ajax(url, {
method = 'GET',
headers = {},
body = null,
}) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();, url, true);