Skip to content

Instantly share code, notes, and snippets.

View NullEntity's full-sized avatar

Bryce Walther NullEntity

  • Philadelphia, PA
View GitHub Profile
@NullEntity
NullEntity / GetHashCodeBenchmark.cs
Last active February 5, 2019 20:33
Hash Code Distribution Test
using System.Collections;
namespace HashCodeDistributionTest
{
public class GetHashCodeBenchmark
{
private static readonly Hashtable _evenDistributes = new Hashtable();
private static readonly Hashtable _counters = new Hashtable();
public class EvenDistributed
private void BindStateMachineBehavioursInActiveScenes()
{
Enumerable.Range(0, SceneManager.sceneCount)
.Select(SceneManager.GetSceneAt)
.SelectMany(ZenUtilInternal.GetRootGameObjects)
.SelectMany(x => x.GetComponentsInChildren<Animator>(true))
.SelectMany(x => x.GetBehaviours<StateMachineBehaviour>())
.ForEach(Container.QueueForInject);
}
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace Domm.Engine
{
public class Recipe
{
private readonly IReadOnlyDictionary<IIngredient, int> _ingredients;
public class PostActionTransformation<T> : ISpecimenBuilderTransformation
{
private readonly List<ISpecimenCommand> _commands = new List<ISpecimenCommand>();
public ISpecimenBuilder Transform(ISpecimenBuilder builder)
{
return new Postprocessor(
builder,
new CompositeSpecimenCommand(_commands),
new IsAssignableToTypeSpecification(typeof(T)));
private static void RemoveMissingComponentsInCurrentScene(ILevelData levelData)
{
var badComponents = SceneManager
.GetActiveScene()
.GetRootGameObjects()
.Flatten()
.Select(gameObject => new
{
GameObject = gameObject,
Components = gameObject.GetComponents<Component>()
@NullEntity
NullEntity / CustomDictionaryConverter.cs
Created July 16, 2017 01:49
Saves a dictionary as key/value pairs. Importantly, it uses JsonConverters on the dictionary keys which the default JsonSerializer doesn't do.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
public class CustomDictionaryConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
@NullEntity
NullEntity / Error trace.txt
Created November 15, 2016 10:01
Damn Java verbosity
jetbrains.buildServer.maintenance.exceptions.UnknownServerStartupError: Could not create the main application servlet: Error creating bean with name 'buildArtifactsCleaner' defined in URL [jar:file:/C:/TeamCity/webapps/ROOT/WEB-INF/lib/server.jar!/META-INF/buildServerSpring.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [jetbrains.buildServer.serverSide.ServerSettings]: Error creating bean with name 'serverSettings' defined in URL [jar:file:/C:/TeamCity/webapps/ROOT/WEB-INF/lib/server.jar!/META-INF/buildServerSpring.xml]: Cannot resolve reference to bean 'buildServer' while setting bean property 'server'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'buildServer' defined in URL [jar:file:/C:/TeamCity/webapps/ROOT/WEB-INF/lib/server.jar!/META-INF/buildServerSpring.xml]: Cannot resolve reference to bean 'userModel' while setting bean property 'userModelEx'; nested exception is org.springframework.beans.factor
private readonly Dictionary<object, Dictionary<Type, Dictionary<object, object>>> _memos = new Dictionary<object, Dictionary<Type, Dictionary<object, object>>>();
public TOut Memoize<TIn, TOut>(TIn input, Func<TIn, TOut> expression)
{
if (_memos.ContainsKey(input)
&& _memos[input].ContainsKey(typeof (TIn))
&& _memos[input][typeof (TIn)].ContainsKey(expression))
return (TOut) _memos[input][typeof (TIn)][expression];
var result = expression(input);
private static void GetRetweets()
{
// oauth implementation details
var oauth_version = "1.0";
var oauth_signature_method = "HMAC-SHA1";
// unique request details
var oauth_nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
-- returns `fn` which memoizes its arguments
local function memoize( fn )
local cache = {}
local function memoize(...)
-- convert args into a string if they're a table
local args = {...}
local sArg = table.ToString(args)
-- get the item with the given arguments from the cache
local cached = cache[sArg]