Skip to content

Instantly share code, notes, and snippets.

@DarrenTsung
DarrenTsung / AngryPufferfishExample1.cs
Created August 29, 2016 17:29
Example for my StateMachineBehaviour article
class RotateFacingDirection : LogicalStateMachineBehaviour {
[SerializeField] private float _rotationSpeed = 10.0f;
...
}
class AimInFacingDirection : LogicalStateMachineBehaviour {
[SerializeField] private LayerMask _targetLayerMask;
void OnStateUpdate() {
@DarrenTsung
DarrenTsung / FloatSpring.cs
Created July 21, 2016 17:31
Unity spring for floats
using System;
using System.Collections;
using UnityEngine;
namespace DT {
/// <summary>
/// uses the semi-implicit euler method. faster, but not always stable.
/// see http://allenchou.net/2015/04/game-math-more-on-numeric-springing/
/// </summary>
public class FloatSpring : MonoBehaviour {
@DarrenTsung
DarrenTsung / server.js
Created July 11, 2014 20:51
Simple node.js server which has two routes: '/write' which writes a string to a file & '/read' which returns the file data in the response.
// Load the http module to create an http server.
var http = require('http');
var fs = require('fs');
var path = require("path");
var url = require("url");
var sys = require("sys");
var qs = require('querystring');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function(request,response){
@DarrenTsung
DarrenTsung / gist:5219869
Created March 22, 2013 08:52
Prints out a histogram showing number of entries per bucket for a Hashtable using DLists as buckets. Also calculates the estimated Collision number and compares it to the actual collision number.
public void printHist() {
235 int collisions = 0;
236 for(int i=0; i<defTable.length; i++) {
237 list.DList temp = defTable[i];
238 list.DListNode tempy = (list.DListNode) temp.front();
239 System.out.print("Entry " + i + ": [ ");
240 for(int j=0; j<temp.size(); j++) {
241 try {
242 System.out.print("*");
243 tempy = (list.DListNode) tempy.next();