Skip to content

Instantly share code, notes, and snippets.

View d12's full-sized avatar
🐱

Nathaniel Woodthorpe d12

🐱
View GitHub Profile
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCr6VkBkvGW2RrDt0X+6HpEnhpWvKq1nqfczVxb0FXm00l5Fu68+kAmK+QOCHnRBMP9LZU/tsHWxjxiN6tKD1sORn4e72QMvXk53q4VJhOSJLA9yyPsrzCAF1wIHA7yQvm3lxQ23e+Vtzwnl/bjyrxUeRO8H1z2v62pJ6KpX3kdVV0KTZouT3DFiuQmfT+CasCLKCUX4FyUxoT08MwapX5MFVetiRJ8CLKlL6DUBx5HuYUwi9cb8oZIv11ffG3QJDCBhJWrkDDa4RihC01MWztWxiDffpCCOiwwlmOW08PaLxuP922ZSBJwMj34Iu3f8X0HP/qByUdq9DQtFGyp+wC1eG3OAqnZF+oN0BKurzwfYk8DHiUoPernxeoADfJwvsn1q7cQ9nQxVtg9NFP4bq4ZRkWu5aU9GRFVDvDw1NDLTRAbvrHv2L/Jfj0dLlBjhvJww68qKeClKiAKEGSoizsm59tbHBVP8h76k11JoP7o0VSML1FzxuJkoAh8MjrIcz92tHVgX+MI+BYmZLwBxwJOoB0aydpiL1GTU9HBNIY5rPKdoMOC6iWGS737CqPXHL+MACeDBMMbAz3gcGmFynUd8VHOfmX7puR0oOD3XwuymmbwIChYe/UL314Yp9JWtTzAaWQMeLldi3LXcirjp+x00vPGU+gdlYnhC08n5KKUpQ== d12@Nathaniels-MacBook-Pro.local
@d12
d12 / ExceptionManager.cs
Created March 29, 2021 01:26
A simple Unity exception handler that reports errors to a server. Handy for tracking down issues hit by end users.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExceptionManager : MonoBehaviour
{
private const int ExceptionsPerCooldown = 5;
private const float CooldownTime = 5f;
private int _exceptionsLeftBeforeTimeout = ExceptionsPerCooldown;
@d12
d12 / realtimedictionary.md
Last active December 7, 2022 21:49
How to use RealtimeDictionary

I had trouble finding information or examples showing how to use RealtimeDictionary, so I put together this doc that details the things I learned as I figured it out.

What is a RealtimeDictionary

RealtimeDictionary isn't a generic C# dictionary that syncs across the network. It specifically maps from uints (unsigned ints, or integers from 0 to ~4 billion) to RealtimeModels. There are other guides which cover RealtimeModels, but they're essentially network-synced structs that can hold whatever data you like.

It's a little complicated if you were just looking to map between two primitive data types, but creating a small RealtimeModel that wraps a single attribute is pretty quick and easy.

Also note that your keys must be unsigned ints. RealtimeDictionary does not support keys of other types.

f_lines = File.read("input.txt").lines.map(&:chomp)
result_lines = f_lines.map do |line|
# Extract all angle brackets, and sort them.
# We use this as a "stack" of angle brackets that we can pull from
# when we need an angle bracket in the final result
angle_brackets = line.scan(/[<>]/).sort
line_chars = line.chars.map do |c|
c == " " ? " " : angle_brackets.shift
end
@d12
d12 / 11.rb
Created January 2, 2022 16:23
# Brute force
# Times out
# O(n^2) time, O(1) space
def max_area(heights)
max = 0
current_left_index = nil
current_right_index = nil
heights.each_with_index do |num1, index1|
next if num1 == 0
# @param {Integer[][]} image
# @param {Integer} sr
# @param {Integer} sc
# @param {Integer} new_color
# @return {Integer[][]}
def flood_fill(image, sr, sc, new_color)
x_max = image.length - 1
y_max = image[0].length - 1
stack = [[sr, sc]]
@d12
d12 / 9.rb
Created October 21, 2021 02:05
Advent 2015 day 9
require "json"
require "byebug"
mapping = {}
list = File.read("9_input.txt").lines.map(&:chomp)
list.each do |l|
a, _, b, _, number = l.split(" ")
mapping[[a, b]] = number.to_i
@d12
d12 / quest-capture-fix.sh
Created March 9, 2021 19:17
Widen Oculus Quest recording capture size
set -e
adb shell setprop debug.oculus.capture.width 1280
adb shell setprop debug.oculus.textureWidth 1280
adb shell setprop debug.oculus.capture.height 720
adb shell setprop debug.oculus.capture.bitrate 10000000
adb shell setprop debug.oculus.foveation.level 0
adb shell setprop debug.oculus.capture.fps 60
input = File.read("7_input.txt").gsub("OR", "|").gsub("AND", "&").gsub("LSHIFT", "<<").gsub("RSHIFT", ">>").gsub("NOT", "~").lines.map(&:chomp)
@map = {}
input.each do |expression|
left_side, right_side = expression.split("->")
@map[right_side.strip] = left_side
end
@memo = {}
def evaluate(label)
# Strategy:
# 1. Find location of each number
# 2. For each combination of 2 numbers, find the distance between them in the graph. Use BFS because I'm lazy
# 3. Brute force the shortest path that goes through each of the 7 numbers.
# - For each permutation of 7 numbers that begins with 0, sum up the distances for each hop.
# - E.g. [0, 2, 5, ...] == distance(0, 2) + distance(2, 5) + ...
# - Find min distance among all permutations
require "byebug"
input = File.read("input.txt").lines.map(&:strip).map(&:chars)