Skip to content

Instantly share code, notes, and snippets.

🕉
all good

José Pedro Dias JosePedroDias

🕉
all good
Block or report user

Report or block JosePedroDias

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JosePedroDias
JosePedroDias / ideas.md
Last active Oct 4, 2019
ldjam 45 ideas
View ideas.md

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 Sep 29, 2019
jsonlish stringify
View README.md

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
View JSON_number_limits.md

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>
<html>
<head>
<meta charset="utf-8" />
<title>webcomponents test</title>
<link
href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII="
rel="icon"
type="image/x-icon"
/>
@JosePedroDias
JosePedroDias / log.js
Created Jan 18, 2019
basic logging to document
View log.js
function log(...args) {
// console.log.apply(console, args);
args = args.map((arg) =>
typeof arg === 'object' ? JSON.stringify(arg) : arg
);
const preEl = document.createElement('pre');
const codeEl = document.createElement('code');
codeEl.appendChild(document.createTextNode(args.join(' ')));
preEl.appendChild(codeEl);
document.body.appendChild(preEl);
@JosePedroDias
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
JosePedroDias / reactHooks.js
Created Mar 13, 2018
expose react hook internals
View reactHooks.js
(function() {
var noop = function() {};
var h = __REACT_DEVTOOLS_GLOBAL_HOOK__;
var helpers = h.helpers[ Object.keys(h.helpers)[0] ];
window.helpers = helpers;
/*helpers.walkTree(
noop,
function(r) {
window.root = r;
}
View cors.py
# based on https://gist.github.com/jhass/652dd780d23c1e236ff913e8a2b77eb2
# http://jsbin.com/wonitaqode/edit?js,output
# mitmproxy -s cors.py
# mitmdump -s cors.py
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();
xhr.open(method, url, true);
@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

[
You can’t perform that action at this time.