Skip to content

Instantly share code, notes, and snippets.

@rzubek
rzubek / Fixnum.cs
Created July 3, 2019 18:41
Very simple fixnum implementation for currency (dollars and cents)
using System;
using System.Collections.Generic;
using System.Globalization;
namespace SomaSim.Util
{
//
// very simple fixnum implementation that holds two digits after the decimal (so e.g. dollars and cents)
public struct Fixnum : IEquatable<Fixnum>, IComparable<Fixnum>
@rzubek
rzubek / Characters.cs
Created December 27, 2017 20:40
Unity C# script loading at runtime
// note: this interface will be referenced in loaded source code:
public interface ICharacter
{
int Height { get; }
string Language { get; }
}
public class Human : ICharacter
{
public int Height { get { return UnityEngine.Random.Range(150, 200); } }
/// <summary>
/// Uploads an image to Imgur
///
/// Credit: http://answers.unity3d.com/questions/1151550/how-can-i-upload-a-screenshot-directly-to-imgur.html
/// </summary>
public class ImgurScreenshotUploader {
/// <summary>
/// Blocking call that uploads an image and returns the results of the API call.
/// Results can be inspected to get the URL of the newly uploaded image, or the error code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
namespace Benchmark.Test
{
class InstanceSpawner : MonoBehaviour
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
namespace Benchmark.Test
{
class InstanceSpawner : MonoBehaviour
{
@rzubek
rzubek / Context3DDetector.as
Last active December 19, 2015 22:09
Helper class to query various Context3DProfiles, and figure out the highest one available for the current hardware configuration. Unfortunately Stage3D doesn't have a simple property we can look up, we have to do this cascading async kluge instead.
package
{
import flash.display.Stage;
import flash.display.Stage3D;
import flash.display3D.Context3DProfile;
import flash.display3D.Context3DRenderMode;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.utils.setTimeout;
@rzubek
rzubek / MemoryScanner.as
Last active December 19, 2015 05:19
Very simple memory scanner class, keeps track of memory allocs and deletes between invocations
package
{
import flash.sampler.*;
import flash.system.System;
import flash.utils.Dictionary;
import flash.utils.getQualifiedClassName;
/**
* Tracks memory allocation / deallocation between two points in time,
* and prints out information about leaks
@rzubek
rzubek / GATracker.as
Last active December 17, 2015 08:49
Simple and very rough AS3 hookup for Google Analytics. It's limited in scope, but it's tiny and requires no external libraries.
package
{
import flash.display.Stage;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.utils.Timer;