Skip to content

Instantly share code, notes, and snippets.

View Vengarioth's full-sized avatar
🌈
casting rays into space

ven Vengarioth

🌈
casting rays into space
View GitHub Profile

Course Notes 16.07.2018

Singleton

Singletons are the most pragmatic, but most dangerous way of structuring code. They impose static dependencies that can not be mocked during testing and generally lead to confusing implementations (spaghetti code).

Example

In this example MyComponent has a static dependency on MyService.

/*
Basic Sprite Shader for aligning pixel art to the same grid, based on the Unity Sprite Shader.
Create one Material where you assign the same Pixels Per Unit value you use on your imported Sprites,
then reuse this Material on all appropriate Sprite Renderers.
(As far as I know there's no possiblity to get this value automatically.)
This is not for scaled or rotated artwork. If you need those features, look at low res render textures.
Use this however you want.
Shader "Outline/OutlineBlendPass" {
Properties {
[HideInInspector] _MainTex ("Base (RGB)", 2D) = "white" {}
[HideInInspector] _OutlineBuffer ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass
{
Name "OutlineBlendPass"
Blend Off
@Vengarioth
Vengarioth / CircuitBreaker.cs
Created October 7, 2015 15:29
Lightweight, locking implementation of the Circuit Breaker pattern.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Integrations
{
/// <summary>
/// Circuit Breaker stability pattern.
///
@Vengarioth
Vengarioth / gist:1a4812150d40fd21b94d
Created May 14, 2015 19:40
PolygonCollider2d to Mesh
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[ExecuteInEditMode]
[RequireComponent(typeof(PolygonCollider2D))]
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
@Vengarioth
Vengarioth / gist:978e80892b6300b3669b
Last active February 4, 2024 06:13
Parallel for Unity3d
/// <summary>
/// Unity Parallelism Helper
/// </summary>
public static class Parallel
{
/// <summary>
/// Executes a for loop in which iterations may run in parallel.
/// </summary>
/// <param name="iterations"></param>
/// <param name="function"></param>
@Vengarioth
Vengarioth / dependency injector
Created March 5, 2015 13:54
dependency injector
public class Injector
{
private Dictionary<Type, object> injectables;
public Injector()
{
injectables = new Dictionary<Type, object>();
}
public void SetInjectable<Type>(object injectable)
@Vengarioth
Vengarioth / restObject.js
Created May 9, 2014 14:59
Wrapper arround express.js routing/middleware & mongoose to easily create REST API Objects
var restObject = function(name, collection) {
this.name = name;
this.collection = collection;
};
restObject.prototype.register = function(app) {
var that = this;
app.get('/api/' + this.name, function(req, res) {