Skip to content

Instantly share code, notes, and snippets.

View angstyloop's full-sized avatar

Sean Allen angstyloop

View GitHub Profile
@angstyloop
angstyloop / SmartEventTarget
Created November 2, 2022 06:31
Sub-class of EventTarget from the JavaScript WebAPI. Supports removing events without specifying a handler function reference. After reading this code to make sure it's safe (it is, but still), copy it into your web browser's JS console and press enter to test the class invariants of SmartEventTarget.
class SmartEventTarget extends EventTarget {
constructor() {
super();
this.handlers = {};
}
addEventListener(name, handler) {
super.addEventListener(name, handler);
if (!this.handlers[name]) {
this.handlers[name] = new Set();
}
@angstyloop
angstyloop / gist:68f89950977631150867d666675d44e2
Last active November 8, 2022 07:35
Helper for "Fetch this Node.js script with node:https"
require('https').get('https://google.com',a=>a.on('data',a=>process.stdout.write(a))).on('error',console.error);
@angstyloop
angstyloop / gist:0ea863102cd7b6a01492e30118e42927
Last active November 8, 2022 07:36
Fetch this Node.js script with node:https
require('https').get('https://gist.githubusercontent.com/angstyloop/68f89950977631150867d666675d44e2/raw/b613a86e7319226d5741c0b0b656c7e0ea36b572/gistfile1.txt',a=>a.on('data',a=>process.stdout.write(a))).on('error',console.error);
@angstyloop
angstyloop / node-https-get.js
Created November 8, 2022 07:52
node https get
require('https').get('https://www.google.com', it => {
console.log('statusCode:', it.statusCode);
console.log('headers:', it.headers);
it.on('data', it => process.stdout.write(it));
}).on('error', console.error);
@angstyloop
angstyloop / gcloud-0.txt
Last active November 8, 2022 09:25
getting started with gcloud / create gcloud vm with ssh access / ssh into gcloud vm / delete gcloud vm
################################################################################
# Getting started with GCloud.
# You'll need a google developer account, so that you have access to the GCloud
# console. You'll need to create a GCloud project and attach a Billing Method
# to it. After that you'll need to install the gcloud API.
# On Ubuntu, you can do that really quickly with Snap.
sudo snap install google-cloud-cli --classic
@angstyloop
angstyloop / Jenkinsfile
Last active November 13, 2022 19:58
Stand up an official Jenkins Docker container on Linux
pipeline {
agent {
docker {
image 'node:lts-bullseye-slim'
args '-p 3000:3000'
}
}
stages {
@angstyloop
angstyloop / DraggableSprite.gd
Last active December 24, 2023 23:11
A GDScript example - a single node game that lets you move a sprite around with the mouse, with or without having to hold the mouse button down. Tested with the standard edition (no C# support) of Godot v3.5.1
# DESCRIPTION
#
# This is a simple Godot game that lets you move a sprite around in two ways:
#
# * by clicking, and then without moving, releasing. Then you can drag
# the sprite around without holding down the mouse button. When you
# want to drop the sprite, release the mouse button.
#
# * by clicking, and then while holding the mouse button down, dragging
# the sprite to where you want it by moving the mouse. When you want
@angstyloop
angstyloop / saveFile.ts
Last active February 23, 2023 06:51 — forked from thomaskonrad/saveFile.ts
Downloading a binary file and saving the file by name in the browser with TypeScript
declare global {
interface Navigator {
msSaveBlob?: (blob: any, defaultName?: string) => boolean
}
}
export default async function saveFile(arrayBuffers: ArrayBuffer[], fileName: string, fileType: string): Promise<void> {
return new Promise((resolve, reject) => {
const blob = new Blob(arrayBuffers, { type: fileType });
@angstyloop
angstyloop / threshold.c
Created March 5, 2023 01:29
Threshold an image to black and white with the amazing open-source VIPS C library for image processing. Create a "binary image".
/** threshold.c
Create a "binary image" from an image - an image with only black (rgb(0, 0, 0))
and white (rgb(255, 255, 255)) pixels, based on a cutoff threshold for the pixel
values of the grayscale image. Pixel values above the threshold are set to 255,
255, and pixel values below the threshold are set to 0, in the new image.
COMPILE
gcc -o threshold threshold.c `pkg-config vips --cflags --libs`
@angstyloop
angstyloop / threshold1.c
Last active March 7, 2023 00:38
Threshold an image with VIPS in C, revised version of threshold.c. Uses a built-in VIPS relational operator instead of thresholding by hand.
/** threshold1.c
*
* COMPILE
*
* gcc -o threshold1 threshold1.c `pkg-config vips --cflags --libs`
*
* EXAMPLE
*
* ./threshold1 128 in.png out.png
*/