Skip to content

Instantly share code, notes, and snippets.

@polerin
polerin / MessageBridge.ts
Last active May 23, 2022 23:37
Typescript Type mapping / const / etc issues
// Basically just a typed facade around PubSub, but the basic goal
// is the same regardless of the backing implmentation
export default class MessageBridge<MessageMap>
{
// ... snip
public subscribe<MessageName extends keyof MessageMap>(
messageName : MessageName,
listener : (message : MessageMap[MessageName]) => void
@polerin
polerin / ApiClientFactory.js
Last active May 20, 2022 18:35
Example of api client implementations, focusing on contained state through class properties or enclosed scope
// factory included just to be silly
class ApiClientFactory
{
options;
defaultOptions = {
"apiClientClass" : "ApiClientPrecheck",
"clientOptions" : {
"tokenLife" : 400,
"someDeepConfig" : {
"foo" : 10,
@polerin
polerin / overlay.effect
Created May 13, 2022 22:55
Simple overlay/camera blend shader for OBS
// yeaaaah
#include "includes/streamfx.effect"
uniform float minPass<
string name = "Minimum alpha to let through";
string field_type = "slider";
float minimum = 0.0;
float maximum = 1.0;
float step = 0.001;
@polerin
polerin / DynamicMethodExample.php
Created April 6, 2022 16:17
Dynamic method example
<?php
interface IThingy
{
function getClassifier() : string;
}
class DynamicMethodHost
{
private string $methodPrefix = "__handle";
@polerin
polerin / AbstractContest.cs
Created January 30, 2020 18:59
lolAbstract
using System.Collections.Generic;
using Zenject;
using SMG.EventBus.Interfaces;
using SMG.Proximity.Players;
namespace SMG.Proximity.GameFlow
{
@polerin
polerin / Form.cs
Created January 21, 2020 16:52
Example UI Elements form structure -- simple "start game" menu
using System;
using System.Collections.Generic;
using UnityEngine;
using Unity.UIElements.Runtime;
using UnityEngine.UIElements;
using Zenject;
using SMG.Common.Exceptions;
/// <summary>
@polerin
polerin / rant.txt
Created August 9, 2018 17:50
Soapbox -- Immutability and predictable systems
polerin [12:08 PM]
Well, lets discuss something. I'm not saying I'm right y'all. Just that I have... opinions.
heh
OK, so the general subject is this: Immutability/static behavior in OOP
As I mentioned in #ideabin, I find it frustrating when objects change state through method calls that don't seem like they should do that.
it introduces a lot of variability and potential for unexpected behavior.
polerin [12:10 PM]
So I feel like there are two general categories of classes/objects in what I'd consider a well structured OO environment.
Data containment/manipulation objects, and command/functional objects.
@polerin
polerin / cleeng_resize.js
Last active May 4, 2018 23:39
Cleeng player resize
// Copy the below and use it to create a bookmarklet, or paste it into the developer console for the page.
// This should be used after the video is playing.
(function() {
var playerFrame = document.getElementsByTagName("iframe")[0];
console.log("changing size of iframe:", playerFrame);
playerFrame.style.width = "100%";
playerFrame.style.height = "100%";
console.log("changing max width of container");
@polerin
polerin / Pattern.js
Last active March 5, 2018 23:51
Pseudo-enum "allowed values" pattern for Javascript
/**
* New pattern, pseudo-enum.
* Benefits:
* - no magic strings!
* - possible IDE completion
* - easier to track down what values are allowable (explicit list location)
* - better self documenting (container naming describes the intent of the field)
* - easy to inspect the object and see valid states in dev tools
* - possibly better on memory? Need to check references
@polerin
polerin / roundmanager.cs
Last active February 15, 2018 21:22
First time StartRound() is called, everything flows through correctly, including waiting the correct amount of time. Second time, it flows through to the await, but that never returns from the await.
namespace Blah {
public class RoundManager {
// ... //
/// <summary>
/// Load up the right round inspector and , activate the appropriate bins and dispensers.
/// </summary>
protected async void StartRound(RoundStartEvent StartEvent)
{