Skip to content

Instantly share code, notes, and snippets.

View BrianOstrander's full-sized avatar

Brian Ostrander BrianOstrander

View GitHub Profile
@BrianOstrander
BrianOstrander / ZomboidBlenderRender.py
Created March 2, 2023 22:07
Uses a template blender file to render multi-tile models from blender into tile sheets for Project Zomboid.
import sys, subprocess, bpy
from functools import partial
from pathlib import Path
RENDER_SHEET_OPERATOR_KEY = 'sw.zomboid_render_sheet'
RENDER_TILES_OPERATOR_KEY = 'sw.zomboid_render_tiles'
COLLECTION_SHEET_PREFIX = 'sheet#'
DIRECTORY_TEMP_SUFFIX = '_tile_renders'
DIRECTORY_RENDER_SUFFIX = '_renders'
ACTION_DELAY = 0.00001
@BrianOstrander
BrianOstrander / GetRekt.md
Last active October 17, 2020 09:17
How to lose your mind with the clashing design choices of C# 6.0 and Newtonsoft's deserialization

{ get; } = rekt

How to lose your mind with the clashing design choices of C# 6.0 and Newtonsoft's deserialization

Recently, I upgraded a personal Unity3D project to enjoy all the wonderful new C# features that have come out, such as the get only auto property. It looks like this:

public string SomeProperty { get; }

On first glance, it works a lot like C#'s readonly field, with the ability to set a default value, or set its value in a constructor.

public string SomeProperty { get; } = "a default value";

@BrianOstrander
BrianOstrander / SerializedPropertiesUtility.cs
Created August 11, 2020 18:29
This is used to fix an issue with get only auto properties and Newtonsoft's deserializer.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lunra.Core;
using UnityEditor;
using UnityEngine;
namespace Lunra.Hothouse.Editor
{
@BrianOstrander
BrianOstrander / gist:a7908b979f12631d86c5
Created April 27, 2015 15:28
Shallow vs. Deep cloning
// The GameObject prefab assigned in the editor before playing the game.
GameObject somePrefab;
void Start() {
// --- Deep Clone ---
// Instantiate a new instance of somePrefab, and asign the reference of it to the instantiatedPrefab variable.
// The Instantiate() method returns an Object, instead of a GameObject, so we have to convert it to a GameObject by putting (GameObject) before it.
GameObject instantiatedPrefab = (GameObject)Instantiate(somePrefab);
04/24/2015 17:14:30: System.NullReferenceException: Object reference not set to an instance of an object
at UdpKit.UdpSocket+MasterClient.OnDirectConnectionWan (UdpKit.Protocol.DirectConnectionWan direct) [0x00000] in <filename unknown>:0
at UdpKit.Protocol.ProtocolClient+<>c__DisplayClass2`1[UdpKit.Protocol.DirectConnectionWan].<SetHandler>b__1 (UdpKit.Protocol.Message m) [0x00000] in <filename unknown>:0
at UdpKit.Protocol.ProtocolClient.Recv (UdpEndPoint endpoint, System.Byte[] buffer, Int32 offset) [0x00000] in <filename unknown>:0
at UdpKit.UdpSocket.RecvProtocol (UdpEndPoint endpoint, System.Byte[] buffer, Int32 bytes) [0x00000] in <filename unknown>:0
at UdpKit.UdpSocket.RecvNetworkPacket (UdpEndPoint ep, System.Byte[] buffer, Int32 bytes) [0x00000] in <filename unknown>:0
at UdpKit.UdpSocket.RecvNetworkData () [0x00000] in <filename unknown>:0
at UdpKit.UdpSocket.NetworkLoop () [0x00000] in <filename unknown>:0
public void ClearID(System.Type configType) {
ClearID(configType);
}
3/11/2015 3:32:58 PM: 72.52.215.35:26000: Send To:100.37.240.75:45626
3/11/2015 3:32:58 PM: 72.52.215.36:27000: Send To:100.37.240.75:45626
3/11/2015 3:32:58 PM: 72.52.215.37:25000: Send To:100.37.240.75:45626
3/11/2015 3:32:58 PM: 69.167.152.231:24000: Recv From:100.37.240.75:45626
3/11/2015 3:32:58 PM: 69.167.152.231:24000: Recv From:100.37.240.75:45626
3/11/2015 3:32:58 PM: Parsing: GetZeusInfo
3/11/2015 3:32:58 PM: Parsing: ProbeFeatures
3/11/2015 3:32:58 PM: Parsing: PeerKeepAlive
3/11/2015 3:32:58 PM: Writing: GetZeusInfoResult
3/11/2015 3:32:58 PM: NatProbeResult for peer 9e754445-a829-4149-9c7c-a6f16f904647 is [NatFeatures Lan=[EndPoint 192.168.1.32:52492 | 13882347088320187660] Wan=[EndPoint 100.37.240.75:45626 | 7216438182844346938] AllowsUnsolicitedTraffic=Yes, HairpinTranslation=Yes, EndPointPreservation=Yes
using UnityEngine;
using System.Collections;
namespace LunraGames.AdvancedObjects {
/// <summary>
/// A class to manage scripts and prefabs that should only be spawned once.
/// </summary>
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour {
@BrianOstrander
BrianOstrander / Rankings
Created March 9, 2015 23:03
An excerpt of a NodeJS API for getting users between two ranks.
exports.getRanks = function(rankMin, rankMax, sinceUTC, callback) {
var sql = 'SELECT nickname,shared_identifier,items,experience FROM accounts WHERE ? < date_updated ORDER BY experience DESC LIMIT ?,?';
var sqlParams = [sinceUTC, rankMin, (rankMax - rankMin) + 1];
mysql.query(sql, sqlParams, function (err, result) {
if (err) {
console.log(err);
callback(err, null);
}
for (var i = 0; i < missingTokens.length; i++) {
accountModel.createEndpoint(missingTokens[i], function(err, endpointArn) {
if (err) {
callback(err);
} else {
allEndpoints[allEndpoints.length] = endpointArn;
}
});
}
callback();