Skip to content

Instantly share code, notes, and snippets.

View JosePedroDias's full-sized avatar

José Pedro Dias JosePedroDias

View GitHub Profile
@JosePedroDias
JosePedroDias / debug_cookie_set.js
Created July 13, 2020 18:02
tampermonkey userscripts for cookies and localStorage
@JosePedroDias
JosePedroDias / jsonl.js
Last active April 18, 2020 15:24
jsonl as generators
const fs = require('fs');
const readline = require('readline');
async function* readJsonlGen(filename) {
const lineReader = readline.createInterface({
input: fs.createReadStream(filename),
});
let i = 0;
for await (const line of lineReader) {
@JosePedroDias
JosePedroDias / spy.js
Created March 2, 2020 22:10
spy and spyOnObject
function spy(fn, prot = fn.prototype) {
function proxy() {
const args = Array.prototype.slice.call(arguments);
proxy.calls.push(args);
proxy.called = true;
return fn.apply(this, args);
}
proxy.prototype = prot;
@JosePedroDias
JosePedroDias / keybase.md
Created February 15, 2020 02:55
keybase.md

Keybase proof

I hereby claim:

  • I am josepedrodias on github.
  • I am josepedrodias (https://keybase.io/josepedrodias) on keybase.
  • I have a public key ASAK1PVQv74qCAcdG8fz1yGPHE1WIExSVThhfHRlFKzhfAo

To claim this, I am signing this object:

@JosePedroDias
JosePedroDias / photo_trace_with_gimp.md
Created February 9, 2020 14:25
photo trace with gimp
  • image > scale image > 200%
  • filters > edge detect > difference of gaussians > 9 / 1
  • colors > desaturate
  • colors > levels > push left bottom point rightwards, manipulate rightmost line to accentuate trace width wo/ much noise added
@JosePedroDias
JosePedroDias / modules.js
Last active January 5, 2020 13:37
traverse to manipulate JSON
// yarn list --json > modules.json
const fs = require('fs');
const O = require('./modules.json');
function visit(o) {
if (typeof o === 'object' && o !== null) {
if (o instanceof Array) {
// change array (noop)
@JosePedroDias
JosePedroDias / set-operations.js
Created January 4, 2020 13:22
set operations
// 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
JosePedroDias / ideas.md
Last active October 4, 2019 22:43
ldjam 45 ideas

THEME: Start with nothing

1

  • 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
JosePedroDias / README.md
Created September 29, 2019 14:37
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.

jsonlishStringify([4,true,'yay'])
`[
4
@JosePedroDias
JosePedroDias / JSON_number_limits.md
Created July 20, 2019 11:58
JSON number limits

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).