Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
@aras-p
aras-p / gist:3952285
Created October 25, 2012 12:22
keywords
multi_compile A B C
multi_compile D E
A B C D E
+ . . + .
. + . + .
. . + + .
+ . . . +
. + . . +
. . + . +
class DataBuffer {
var internalData: NSData;
init(fromData: NSData) {
self.internalData = NSData.dataWithData(fromData) as NSData;
}
init(fromFilePath: String) {
self.internalData = NSData.dataWithContentsOfFile(fromFilePath, options: .DataReadingMappedIfSafe, error: nil) as NSData;
}
@mildmojo
mildmojo / GoogleAnalytics.cs
Last active December 11, 2015 22:09
Reporting Unity game events to Google Analytics from the Unity Webplayer. Calls out to the Google javascript library loaded on the page, so the class is configuration-free.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/* Google Analytics integration. Web page must be configured for GA with Google's javascript snippet.
*
* Based on a comment from 2010 found here:
* http://blog.mostlytigerproof.com/2009/10/06/gathering-statistics-using-google-analytics-and-unity-3d/
*
* Analytics category/action/label/value descriptions:
@janderit
janderit / zmqexample.cs
Created April 11, 2013 15:56
ZeroMQ 3.1 Router/Dealer example
public sealed class Host
{
private readonly string _zmqEndpoint;
private readonly Action<Action> _dispatcher;
private static ZmqSocket _server;
private static readonly ConcurrentQueue<Action> WaitToSend = new ConcurrentQueue<Action>();
public Host(string zmqEndpoint, Action<Action> dispatcher)
{
_zmqEndpoint = zmqEndpoint;
@fossil12
fossil12 / C.sublime-build
Created January 15, 2014 19:50
Sublime Text 2 Build System for C on OS X. (Just move/copy file to `Packages/User`.)
{
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}", "-Wall"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
@stramit
stramit / SpecialEventClass.cs
Last active November 21, 2018 06:36
SpecialEventClass
/*
* When developing the UI system we came across a bunch of things we were not happy
* with with regards to how certain events and calls could be sent in a loosely coupled
* way. We had this requirement because with a UI you tend to implement widgets that receive
* certain events, but you don't really want to have lots of glue code to manage them
* and keep track of them. The eventing interfaces we developed helped with this. One of
* the interesting things, is that they are not justfor the UI system! You can use this as
* a type-safe, fast, and simple alternative to SendMessage (never use SendMessage!).
* So how does it all work?
@Kink3d
Kink3d / MainLightNode.cs
Created May 8, 2018 00:13
A custom lighting node example for Shader Graph and Lightweight Render Pipeline
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Lighting", "Main Light")]
public class MainLightNode : AbstractMaterialNode, IGeneratesBodyCode
{
public MainLightNode()
{
@fredrikaverpil
fredrikaverpil / maya_sublime.py
Created March 25, 2014 14:58
Open ports in Maya for Sublime Text #maya
import maya.cmds as cmds
# Close ports if they were already open under another configuration
try:
cmds.commandPort(name=":7001", close=True)
except:
cmds.warning('Could not close port 7001 (maybe it is not opened yet...)')
try:
cmds.commandPort(name=":7002", close=True)
except:
@aras-p
aras-p / rgbm.c
Created September 7, 2011 04:50
Encoding to RGBM
// in our case,
const float kRGBMMaxRange = 8.0f;
const float kOneOverRGBMMaxRange = 1.0f / kRGBMMaxRange;
// encode to RGBM, c = ARGB colors in 0..1 floats
float r = c[1] * kOneOverRGBMMaxRange;
float g = c[2] * kOneOverRGBMMaxRange;
float b = c[3] * kOneOverRGBMMaxRange;
@mstevenson
mstevenson / ShuffleBag.cs
Last active May 25, 2020 12:16
Shuffle bag algorithm implemented in C#
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ShuffleBag<T> : ICollection<T>, IList<T>
{
private List<T> data = new List<T> ();
private int cursor = 0;
private T last;