Skip to content

Instantly share code, notes, and snippets.

@grofit
grofit / AStarPathCalculator.cs
Last active August 29, 2015 14:13
An example of why inheritance is a poor substitute for composition
/*
This is a Path calculator which uses an A* approach
*/
public class AStarPathCalculator : IPathCalculator
{
IEnumerable<Vector3> FindPathTo(Vector3 startPosition, Vector3 endPosition)
{
var path = ABPath.Construct(startPosition, endPosition);
return path.vectorList;
}
@grofit
grofit / middleware.js
Created January 25, 2015 22:17
SocketIO + Passport + Cookie-Sessions
/*
This is just a hacky approach to get things moving, as passport-socketio library
does not support cookie-sessions.
*/
var Promise = require("bluebird");
var passport = require("passport");
var session = require("cookie-session");
var sessionConfig = {
@grofit
grofit / create-user-view-model.js
Created April 16, 2015 14:29
Some MVVM class based approach thing
// Imagine this is a starting page where the user creates their account
function CreateUserViewModel()
{
// could be done via IoC to improve testability and reuseability
var someAjaxService = {}; // Imagine it does something
this.user = new User();
var saveDataToServer = function() {
var data = ko.toJS(this.user);
someAjaxService.Post("/users", data);
@grofit
grofit / SceneExtensions.cs
Created October 1, 2015 20:28
uFrame MVVM View Instantiation Helpers
public static class SceneExtensions
{
public static TView InstantiatePrefabView<TView>(this IScene scene, ViewModel viewModel, string prefabName, string instanceName = null, Transform parent = null)
where TView : ViewBase, new()
{
var prefab = Resources.Load(prefabName) as GameObject;
if (prefab == null)
{ throw new Exception(string.Format("Cannot locate prefab [{0}]", prefabName)); }
var createViewCommand = new InstantiateViewCommand
{
@grofit
grofit / app.html
Created April 8, 2016 14:41 — forked from jdanyow/app.html
Aurelia Gist
<template>
<h1>${message}</h1>
</template>
@grofit
grofit / AttackAction.cs
Last active April 22, 2016 13:49
Example of interacting with uFrame from NodeCanvas
using System.Collections;
using System.Collections.Generic;
using NodeCanvas;
using NodeCanvas.Variables;
using UnityEngine;
/*
Let us assume you have a uFrame Entity which can attack
and when it does it needs to play an animation in the view layer
and also needs to tell the controller to trigger an attack
@grofit
grofit / validate-property-attribute.js
Created August 4, 2016 20:34
CommonJS test for validation group failure
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ValidateProperty = undefined;
var _dec, _dec2, _class;
var _aureliaFramework = require("aurelia-framework");
@grofit
grofit / EntityBatchOperation.cs
Created April 24, 2020 21:33
Entity Operation Batching
public class EntityBatchOperation
{
private const int NoComponentTypeId = -1;
private Entity _entity;
private List<int> _componentsAdded = new List<int>();
private List<int> _componentsRemoved = new List<int>();
public EntityBatchOperation(Entity entity)
{
@grofit
grofit / CompositionExample.cs
Created May 31, 2015 08:58
An example of inheritance woes
/* Ok lets start by expressing the intent for a vehicle to move */
public interface IVehicleMovement
{
public float Speed {get; set;}
public void Move(Vector2 direction);
}
/* This will implement the most common form of movement */
public class SimpleWheelMovement : IVehicleMovement
{
@grofit
grofit / NotUsingIoC.cs
Last active May 17, 2020 18:45
What is Inversion of Control
/*
This is worst case scenario
- You are unable to control the dependency or swap it for another without changing the NotUsingIoC source code.
- You are also going to have difficulties testing this as you cannot easily mock _someDependency.
*/
public class NotUsingIoC
{
private ISomeDependency _someDependency;