Skip to content

Instantly share code, notes, and snippets.

View mobyjames's full-sized avatar
🤔

James Jacoby mobyjames

🤔
View GitHub Profile
@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);
@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 / 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
const PlayStateMachine = Machine(
{
id: 'game',
initial: 'idle',
states: {
idle: {
on: {
INIT: 'waiting',
},
},
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);
});
@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);
}
@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 / 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 / clock.swift
Last active September 20, 2016 20:06
Broken Clock
import UIKit
import QuartzCore
import XCPlayground
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class ClockView: UIView {
let backgroundLayer = CAShapeLayer()
let faceLayer = CAShapeLayer()
@mobyjames
mobyjames / cross-domain-ga-eventbrite.md
Created June 7, 2016 17:11
A summary of the methods used to enable cross-domain support between a primary domain an an Eventbrite event

#Cross-domain Google Analytics + Eventbrite

Goal

Allow continuous tracking across two primary domains (primarydomain.com and eventbrite.com) in order to track the success of marketing initiatives.

Steps to Setup GA for Events

  1. Ensure that no live events are using "classic tracking"
  2. Go to manage page and select "manage" for the desired event