Skip to content

Instantly share code, notes, and snippets.

View slacktracer's full-sized avatar

Thiago F slacktracer

  • An island.
View GitHub Profile
@slacktracer
slacktracer / gist:ec1d532cafb62f712025b4ee8a99b5c9
Created January 27, 2023 19:37
kinda typing fromEntries result as a enum-ish
type Keys<T extends readonly string[]> = Readonly<{ [key in T[number]]: key }>;
// const keys = ["feat1", "feat2"] as const;
export const makeEnumLikeFromArray = <T extends readonly string[]>(array: T) =>
Object.fromEntries(array.map((item) => [item, item])) as Keys<T>;
// const a = make<typeof keys>(keys);
@slacktracer
slacktracer / index.html
Created November 13, 2021 20:08
Infectio — a puzzle game #codevember
<main>
<controls>
<div class="new-game">New Game</div>
<div>Moves <span class="moves">0</span> / <span class="max-moves">30</span></div>
</controls>
<board></board>
<colors></colors>
<controls>
<div>Skill <span class="skill">0</span></div>
<div><input type="range" class="level" value="10" min="3" max="10" /></div>
@slacktracer
slacktracer / index.html
Created November 13, 2021 19:58
side scroller v0.6 (matter.js)
<div id="keysleft">
move: WASD
<br>hold/drop: E
<br>pause: F
<br>gravity: R
</div>
<div id="keysright">
zoom: + -
<br>fire: click
<br>testing: T
@slacktracer
slacktracer / index.html
Created November 13, 2021 19:54
platformer v0.1 (matter.js)
<svg height = '800' width = '1200'>
<g id="grid" stroke="#f2f2f2">
<line x1="0" y1="0" x2="3000" y2="0" style="stroke-dasharray:1,58,1,0;stroke-width:3000;"/>
<line x1="0" y1="0" x2="0" y2="3000" style="stroke-dasharray:1,58,1,0;stroke-width:3000;"/>
</g>
</svg>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Controls: arrow keys
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@slacktracer
slacktracer / mochainstance.mjs
Created February 18, 2018 19:35 — forked from anonymous/mochainstance.mjs
Mocha ES Modules Example
import Mocha from "mocha"
export default new Mocha()
@slacktracer
slacktracer / context.js
Created January 3, 2018 15:28 — forked from rodrigobranas/context.js
context.js
let context = {};
context.createContext = function (fn) {
let name = "context" + Math.floor(Math.random() * 10000000);
Object.defineProperty(fn, "name", {value: name});
let params = {};
global[name] = params;
fn(params);
delete global[name];
};
const makeG = n => x => (x ** 2 + 1) % n;
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
const pollard = n => {
const g = makeG(n);
let x = 1;
let y = 2;