Skip to content

Instantly share code, notes, and snippets.

View JosePedroDias's full-sized avatar

José Pedro Dias JosePedroDias

View GitHub Profile
@JosePedroDias
JosePedroDias / README.md
Created January 24, 2023 11:08
test stylesheet font face definitions

This is supposed to be served next to a fonts.css file defining one or more font-families, ex:

@font-face {
  font-family: "American Captain";
  src: url("./American-Captain.woff") format("woff");
}
@JosePedroDias
JosePedroDias / hack.ts
Last active January 5, 2023 14:30
filter JS complex tree with cycles
const ignoreKeys = new Set([
'parent',
'transform',
]);
const numberKeyRgx = /^[0-9]+$/;
const simpleKeyRgx = /^[a-zA-Z_\$][a-zA-Z0-9_\$]*$/;
const getExpr = function (key: string) {
if (numberKeyRgx.test(key)) return `[${key}]`;
return (simpleKeyRgx.test(key)) ? `.${key}` : `['${key}']`;
@JosePedroDias
JosePedroDias / configuration.nix
Created January 3, 2023 23:58
run nixos on M1 with UTM
{ config, pkgs, ... }:
{
imports =
[
./hardware-configuration.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
@JosePedroDias
JosePedroDias / ArrayUtils.test.ts
Last active December 29, 2022 12:14
DIY browser tests without mocking
import { expect } from 'chai';
import { ArrayUtils } from './ArrayUtils';
function sortByNumericAttribute() {
const arr = [
{ a: 'a', n: 3 },
{ a: 'b', n: 2 },
{ a: 'c', n: 6 },
];
expect(ArrayUtils.sortByNumericAttribute(arr, 'n', false)).to.deep.eq([
@JosePedroDias
JosePedroDias / fetchForJest.js
Created June 23, 2022 09:14
fetch for jest
// to capture actual responses
let i = 0;
global.fetch = jest.fn(async (url, options) => {
console.log(`#${i++}: ${options.method || 'GET'} ${url}`);
const resp = await originalFetch(url, options);
const body = await resp.json();
console.log(` status: ${resp.status}, body: ${JSON.stringify(body, null, 2)}`);
return body;
});
@JosePedroDias
JosePedroDias / connect.sh
Created May 10, 2022 14:56
mysql 5.7 docker-composed
mysql -h localhost -u USER -P 3306 -p --protocol=TCP
@JosePedroDias
JosePedroDias / misc.js
Created February 23, 2022 11:22
misc.js
function clamp(v, m, M) {
return v < m ? m : v > M ? M : v;
}
function average(arr) {
return arr.reduce((prev, curr) => prev + curr, 0) / arr.length;
}
// triangle m0 x l of area 1 (linear degradation)
function averageWithDegradation(arr) {
@JosePedroDias
JosePedroDias / README.md
Last active October 28, 2021 16:38
simple interceptor of webgl context calls (for when spector.js is an overkill)

the code should be called right after we obtain the GL context. Don't forget to reset/edit ignoreCommands if you intend to capture some of those.

example usages:

fakeGl.captureOperations(40)
...
fakeGl.ignoreCommands = []
@JosePedroDias
JosePedroDias / map.geojson
Last active October 16, 2021 09:23
Maratona de Lisboa 2021-10-17
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JosePedroDias
JosePedroDias / index.md
Last active February 7, 2021 16:30
build ODE

Build ODE in Linux

simple approach (can't choose revelant things):

sudo apt add libode-dev

otherwise use premake as explained below

Build ODE in Windows