Skip to content

Instantly share code, notes, and snippets.

View reececomo's full-sized avatar
🍊
Working on something cool

Reece Como reececomo

🍊
Working on something cool
View GitHub Profile
@reececomo
reececomo / PrintBluepillJUnitResults.py
Created July 5, 2019 06:55
Print Bluepill JUnit Results to console
##
# Print JUnit Test Results.
#
# - Description: Only prints iOS-formatted results (AllTests > Suites > Subsuites > Cases).
#
# - Usage:
# - `python3 PrintBluepillJUnitResults.py <XML file>`
#
# - Arguments:
# - JUnit results XML file
import Foundation
/**
Simple fixed-size ring buffer / circular queue data structure.
This basic implementation uses an array under the hood.
Maintains a Write Queue and a Read Queue. Does not prevent "lapping" of the read/write queues.
*/
class RingBuffer<Element> {
type Buffer = Uint8Array; // `Buffer` needs to be polyfilled in non-Node environments.
declare module "js-binary" {
export class Data {
constructor(capacity: number);
appendBuffer(data: Buffer): void;
writeUInt8(value: number): void;
writeUInt16(value: number): void;
writeUInt32(value: number): void;
@reececomo
reececomo / sortObject.ts
Last active June 14, 2024 11:37
Sort an object in place or by copy (TypeScript/JavaScript)
// JavaScript versions at the bottom
// ----- TypeScript: -----
type ObjectCompareFn = (a: string, b: string) => number;
/** Sorts an object in place */
export function sortObject<T extends object>(obj: T, compareFn?: ObjectCompareFn): T {
Object.keys(obj).sort(compareFn).forEach(key => {
@reececomo
reececomo / SpritesheetAnimation.ts
Created June 14, 2024 12:29
Quickly generate spritesheet animations in PixiJS
import { AnimatedSprite, Assets, IPointData } from 'pixi.js';
/**
* A simple way to load animations.
*/
export class SpritesheetAnimation extends AnimatedSprite {
public constructor(name: string, {
autoPlay = false,
autoUpdate = true,
updateAnchor = false,
@reececomo
reececomo / audiospriteAsset.ts
Created June 19, 2024 11:16
Import audio sprite assets with @pixi/sound. For use with audiosprite / assetpack-plugin-audiosprite.
import { Sound, utils, sound } from '@pixi/sound';
import { Loader, ExtensionType, LoaderParserPriority } from 'pixi.js';
/** JSON file 'jukebox' format (the default format emitted by audiosprite) */
export interface AudiospriteJson {
resources: string[];
spritemap: Record<string, { start: number, end: number, loop?: boolean }>;
}
@reececomo
reececomo / utility-types.ts
Last active September 25, 2024 02:37
AllowExcess<T>, InexactOptionals<T>, Untrusted<T>, etc.
/* eslint-disable @typescript-eslint/ban-types */
/**
* Allow object literals to include additional unchecked properties.
* @see https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks
*/
// prettier-ignore
export type AllowExcess<T> = T extends object
? T extends Array<infer U> ? AllowExcess<U>[]
: {[K in keyof T]: AllowExcess<T[K]>} & {[key: string]: unknown}
@reececomo
reececomo / example.ts
Created November 3, 2024 02:34
file uploads with r2
// ----- 2. -----
// (scroll down for 1.)
import { z } from "zod";
import { UploadConfig, uploadFile } from "@/utils/upload-client";
import { uploadsTable } from "@/server/db/schema";
import { userProcedure } from "@/server/api/procedures";
import { db } from "@/server/db";
@reececomo
reececomo / .zshrc
Last active November 5, 2024 03:01
zsh git aliases/functions: fin, rebase
alias reload="source ~/.zshrc"
alias editzsh="code ~/.zshrc"
alias editbash="code ~/.zshrc" # legacy
# git:
branch() {
git branch --show-current 2> /dev/null
}
defaultbranch() {
@reececomo
reececomo / git-force.sh
Last active November 8, 2024 01:32
protect git push -f
git() {
WARN='\033[0;33m'
RESET='\033[0m'
if [[ "$1" == "push" && "$2" == "-f" ]]; then # idiot safety net
echo -e "${WARN}note: running with --force-with-lease. run with \"--force\" to override.${RESET}"
command git push --force-with-lease "${@:3}"
else
command git "$@"
fi