Skip to content

Instantly share code, notes, and snippets.

View mobyjames's full-sized avatar
🤔

James Jacoby mobyjames

🤔
View GitHub Profile
@mobyjames
mobyjames / code.py
Created December 29, 2018 18:52
Trellis Sweeper
# Mine Puzzle Game
# Created by James Jacoby, December 2018
#
# A mine clearing game loosely based on minesweeper
#
# HOW TO PLAY:
#
# Press a key to clear a space
# If it's a mine, you lose
# Otherwise, the adjacent spaces will change color to indicate the number
@mobyjames
mobyjames / mines.py
Created March 4, 2019 17:19
Adafruit Trellis Minesweeper
# Mine Puzzle Game
# Created by James Jacoby, December 2018
#
# A mine clearing game loosely based on minesweeper
#
# HOW TO PLAY:
#
# Press a key to clear a space
# If it's a mine, you lose
# Otherwise, the adjacent spaces will change color to indicate the number
@mobyjames
mobyjames / bot-client.ts
Last active October 23, 2021 22:44
Colyseus Bot Template
export class BotClient {
client: Client;
room: Room<GameState>;
player: Player;
sessionId: string;
constructor(server: string | Client) {
this.client = server instanceof Client ? server : new Client(server);
}
const gameServer = new Server({
gracefullyShutdown: false,
});
registerGracefulShutdown(async (err) => {
console.log('shutting down...');
await broadcastAll('Sorry to interrupt. Servers are restarting shortly.');
await delay(10000);
await gameServer.gracefullyShutdown(true, err);
});
const PlayStateMachine = Machine(
{
id: 'game',
initial: 'idle',
states: {
idle: {
on: {
INIT: 'waiting',
},
},
@mobyjames
mobyjames / character-renderer.ts
Last active January 26, 2021 18:00
Render pixel art in NodeJS
import { pallet } from './pallet';
import sharp from 'sharp';
export async function renderCharacter(pixels: Array<number>) {
const width = 20;
const height = 20;
// create raw pixel buffer
// pixels are stored as numbers in red, green, blue, alpha format
// starting in top left
@mobyjames
mobyjames / diagnostics.ts
Created April 24, 2024 22:07
Colyseus Diagnostic Info
import osUtils from "node-os-utils";
import { matchMaker } from 'colyseus';
async function getTotalConnections() {
const rooms = await matchMaker.query({});
let total = rooms.reduce((acc, room) => {
return acc + room.clients;
}, 0);
@mobyjames
mobyjames / auth.ts
Created May 7, 2024 17:04
passwordless auth sample
export async function beginAuthentication(email: string | null): Promise<boolean> {
if (!email || email.length === 0 || !email.includes('@')) {
throw ApiError.required('email');
}
email = email.trim();
const existingUser = await User.findOne({ email });
let authKey = getRandomDigitString(4);
const authKeyExpiration = dateWithMinutesFromNow(10);