Skip to content

Instantly share code, notes, and snippets.

@codewings
codewings / ValueSetter.cs
Last active December 19, 2015 12:48
Get/Set the value of a property in arbitrary depth of an object by reflection.
class Reflector
{
public static object SetValue(object target, string path, object value)
{
Stack<PropertyInfo> s1 = new Stack<PropertyInfo>();
Stack<object> s2 = new Stack<object>();
string[] properties = path.Split('.');
Type type = target.GetType();
@codewings
codewings / StrExprConverter.cs
Last active December 22, 2015 08:38
String Expression Converter
namespace StringExprConverter
{
class StringExprConverter
{
public static Object Format(String str, Type type)
{
if (String.IsNullOrEmpty(str))
return null;
if (type == null)
return str;
@codewings
codewings / hlsl_dumpbin.py
Last active January 4, 2016 04:59
dump HLSL binary code
import sys
import os
import struct
#/Tvs_4_0 f:\default.vs
root = os.environ['DXSDK_DIR']
file = os.environ['TEMP'] + "output.bin"
expr = "\"" + root + "Utilities\\bin\\x86\\fxc.exe\" /Fo" + file
if len(sys.argv) >= 2:
def bytes_to_int32(bytes):
assert len(bytes) == 4
return sum((b << (k * 8) for k, b in enumerate(bytes)))
def MurmurHash64B(data, seed):
m = 0x5bd1e995
r = 24
MASK = 0xFFFFFFFF
data_as_bytes = bytearray(data)
@codewings
codewings / Photoshop_Constants_Rosetta_Stone
Last active August 9, 2024 13:39
Photoshop Constants Rosetta Stone
PSConstants -> value -> CharID TypeIDToStringID
---------- -> ----- -> ------ ----------------
phDialogDontDisplay -> 0 ->
phEnumBitDepthA1R5G5B5 -> 825570869 -> "1565"
phEnumBitDepthA4R4G4B4 -> 875836468 -> "4444"
phEnumAmiga -> 1097688929 -> "Amga"
phKeyArrowhead -> 1098019447 -> "Arrw"
phEventBackLight -> 1113678668 -> "BacL"
phClassBackLight -> 1113680716 -> "BakL"
phEnumBitDepth16 -> 1111765302 -> "BD16"
@codewings
codewings / OSX Dock LockerUnlocker
Created November 16, 2016 15:23
Lock or Unlock the OSX dock
-- Version 1.0.2
set currentStatus to "0"
try
set currentStatus to do shell script "defaults read com.apple.dock contents-immutable"
end try
if currentStatus is equal to "0" then
tell application "Finder" to display alert "Lock the icons in the Dock?" buttons {"Cancel", "Lock"}
else
@codewings
codewings / UnityAnimationWindowHotkeys.cs
Last active March 2, 2017 11:50
Adds some useful hotkeys to the Animation window in Unity.
// Tested on Unity 5.3.5 & Unity 5.5.1
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections;
using System.Reflection;
[ExecuteInEditMode]
public class AnimationWindowHotkeys : Editor
{
@codewings
codewings / Cubemap_SHProbeLight.cs
Created January 2, 2019 03:40
Bake SH Coefficients from Cubemap
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class SHLightingProbe : MonoBehaviour
@codewings
codewings / BlenderGpuGizmos.py
Created May 6, 2019 07:13
Simple gizmo drawer for blender 2.80
import bpy
import gpu
from random import random
from mathutils import Vector
from gpu_extras.batch import batch_for_shader
gizmos_line_vert = '''
uniform mat4 u_ViewProjectionMatrix;
in vec3 position;
in vec4 color;
# porting from https:#github.com/google/spherical-harmonics for blender [WIP]
import math, mathutils
from random import random, uniform
PI = math.pi
TWO_PI = 2.0 * PI
FACTORIAL_CACHE = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000]
DOUBLE_FACTORIAL_CACHE = [1, 1, 2, 3, 8, 15, 48, 105, 384, 945, 3840, 10395, 46080, 135135, 645120, 2027025]
FACTORIAL_CACHESIZE = 16