Skip to content

Instantly share code, notes, and snippets.

View mbforbes's full-sized avatar
🖋️
Sketches

Maxwell Forbes mbforbes

🖋️
Sketches
View GitHub Profile
async function getWikiImageURL(searchQuery) {
const PROXY = "https://cors-anywhere.herokuapp.com/";
const WIKI_API_ENDPOINT = `${PROXY}https://en.wikipedia.org/w/api.php`;
// First fetch to get the page ID
let pageId;
try {
console.log("Trying request 1");
const response1 = await fetch(
`${WIKI_API_ENDPOINT}?action=query&list=search&srsearch=${encodeURIComponent(
@mbforbes
mbforbes / ecs-dirty-aspects.ts
Created January 4, 2022 22:22
TypeScript ECS w/ dirty Component optimization and Aspects
/**
* An entity is just an ID. This is used to look up its associated
* Components.
*/
export type Entity = number
/**
* A Component is a bundle of state. Each instance of a Component is
* associated with a single Entity.
@mbforbes
mbforbes / ecs-dirty.ts
Last active July 27, 2024 04:23
ECS implementation w/ dirty Component optimization
namespace P02 {
/**
* An entity is just an ID. This is used to look up its associated
* Components.
*/
type Entity = number
/**
@mbforbes
mbforbes / minimal-ecs.ts
Created September 5, 2021 06:50
A minimal but complete Entity Component System (ECS) implementation in 99 lines.
type Entity = number
abstract class Component { }
abstract class System {
public abstract componentsRequired: Set<Function>
public abstract update(entities: Set<Entity>): void
public ecs: ECS
}
type ComponentClass<T extends Component> = new (...args: any[]) => T
class ComponentContainer {
private map = new Map<Function, Component>();
@mbforbes
mbforbes / from_scruples.py
Created June 18, 2021 18:30
scruples preprocess
"""Compare preprocessed scruples to original titles.
Usage:
python -m sc.scripts.from_scruples
"""
import code # code.interact(local=dict(globals(), **locals()))
import json
import os
from typing import List, Tuple, Set, Dict, Any, Optional, NamedTuple, Iterator, Callable
@mbforbes
mbforbes / paper.sh
Created October 11, 2018 02:49
Script that turns a pdf from pixels into paper near you (well, near me).
#!/bin/bash
# ______ ______ ______ ______ ______
# /\ == \/\ __ \ /\ == \/\ ___\ /\ == \
# \ \ _-/\ \ __ \\ \ _-/\ \ __\ \ \ __<
# \ \_\ \ \_\ \_\\ \_\ \ \_____\\ \_\ \_\
# \/_/ \/_/\/_/ \/_/ \/_____/ \/_/ /_/
#
#
# Script that turns a pdf from pixels into paper near you (well, near me).
@mbforbes
mbforbes / fallgate-freesound.org.txt
Created August 21, 2018 04:32
Fallgate sounds from freesound.org
https://freesound.org/people/vacuumfan7072/sounds/396031/
https://freesound.org/people/DSOADigital/sounds/362256/
https://freesound.org/people/MichelleGrobler/sounds/410560/
https://freesound.org/people/LukeSharples/sounds/209127/
https://freesound.org/people/JoelAudio/sounds/135464/
https://freesound.org/people/tim.kahn/sounds/140455/
https://freesound.org/people/et_graham/sounds/366345/
https://freesound.org/people/kristinhamby/sounds/382637/
https://freesound.org/people/LiamG_SFX/sounds/334238/
https://freesound.org/people/kolczok/sounds/198987/
@mbforbes
mbforbes / python-gzip.py
Created April 12, 2018 22:19
Python compress file
def compress(bytes_path: str, compressed_path: str) -> None:
logging.info('Compressing "{}" to "{}"'.format(
bytes_path, compressed_path,
))
with open(bytes_path, 'rb') as f_in:
with gzip.open(compressed_path, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
logging.info('Removing "{}"'.format(bytes_path))
os.remove(bytes_path)
@mbforbes
mbforbes / stubgen, recursive on torch, manual cleanup, stubgen on numpy, resulting errors
Created September 26, 2017 18:24
Running `stubgen --recursive torch`, some manual fixes, then trying `stubgen --recursive numpy`. More failures and it also can't figure out what `--recursive` is anymore.
out/numpy/__init__.pyi:6: error: No library stub file for module 'numpy.lib'
out/numpy/__init__.pyi:6: note: (Stub files are from https://github.com/python/typeshed)
out/numpy/__init__.pyi:7: error: No library stub file for module 'numpy.matrixlib'
out/numpy/_import_tools.pyi:23: error: Cannot assign to a type
out/numpy/__init__.pyi:12: error: No library stub file for module 'numpy.version'
out/numpy/__init__.pyi:13: error: Cannot find module named '__builtin__'
out/numpy/__init__.pyi:13: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
dataio.py:17: error: Cannot find module named 'tqdm'
out/numpy/ctypeslib.pyi:5: error: No library stub file for standard library module 'ctypes'
viewer.py:16: error: Cannot find module named 'visdom'
@mbforbes
mbforbes / stubgen, recursive on torch, manual cleanup, resulting errors
Created September 26, 2017 18:21
Running `stubgen --recursive torch` then manually fixing some reserved keyword, default args, and missing declaration errors. It wants other libs and still can't find cuda.
regression.py:21: error: No library stub file for module 'numpy'
regression.py:21: note: (Stub files are from https://github.com/python/typeshed)
dataio.py:17: error: Cannot find module named 'tqdm'
dataio.py:17: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
viewer.py:16: error: Cannot find module named 'visdom'
viewer.py:30: error: Name 'torch.Tensor' is not defined
viewer.py:45: error: Module has no attribute "Tensor"
viewer.py:107: error: Module has no attribute "Tensor"
dataio.py:34: error: Name 'torch.Tensor' is not defined
dataio.py:43: error: Name 'torch.Tensor' is not defined