Skip to content

Instantly share code, notes, and snippets.

@jjvdangelo
jjvdangelo / Timer.fsx
Last active August 29, 2015 14:17
Turning a regular game timer into a sequence to experiment with looking at the game loop as something that iterates the timer sequence instead of an imperative while loop.
module Timer
open System.Diagnostics
type TimeInfo =
{ TotalElapsed: float
Delta: float }
let start () =
let last =
open System
open System.ComponentModel
open System.Configuration
open System.Runtime.InteropServices
open System.Security.Permissions
open System.Security.Principal
[<AutoOpen>]
module private Helpers =
[<DllImport("advapi32.dll", SetLastError = true)>]
@jjvdangelo
jjvdangelo / AngularJsTimer.ts
Created March 21, 2014 21:48
Trying to figure out why three $http.gets are fired at a time with this controller.
mod.controller("MyController",
[
"$scope", "$http",
($scope: any, $http: ng.IHttpService) => {
var queueChecker = setInterval(() => {
var url = "/foo/count";
$http.get(url, { params: { cacheBuster: new Date().getMilliseconds() } })
.success((data: any) => {
$scope.QueueView = data;
$scope.QueueView.lastUpdated = new Date();
// --Snip--
let getEntity id =
use conn = EntityContext.GetDataContext()
query { for t1 in conn.Table_1 do
join t2 in conn.Table_2 on (t1.id = t2.table_1_id)
where (t1.id = id)
select t2
headOrDefault } |> function
| null -> Unchecked.defaultof<_>
| t2 -> { Id = t2.id; Value = t2.value }
module Counter =
type State = { Value: int }
static member Zero = { Value: 0 }
type Command =
| Incremement
| Decrement
type Event =
| Incremented
[<RequireQualifiedAccess>]
module Authentication
open System
open System.Collections.Generic
open Simple.Web
open Simple.Web.Http
open Simple.Web.Authentication
type Payload = { UserId: Guid; Name: string; Expires: int64 }
[<RequireQualifiedAccess>]
module Authentication
open System
open System.Collections.Generic
open Simple.Web
open Simple.Web.Http
open Simple.Web.Authentication
type Payload = { UserId: Guid; Name: string; Expires: int64 }
open System.Web.Hosting
open Simple.Web.Helpers
type PathUtility() =
interface IPathUtility with
member __.MapPath virtualPath =
virtualPath |> HostingEnvironment.MapPath
module CommandBus =
let createCommandRouter handlers =
let event = Event<Command>()
handlers |> List.iter(fun handler -> event.Publish |> Event.add handler)
let agent = MailboxProcessor.Start(fun inbox ->
let loop() = async {
let! cmd = inbox.Receive()
cmd |> event.Trigger
return! loop() }
@jjvdangelo
jjvdangelo / HashExtensions.cs
Created July 13, 2013 23:44
A simple helper for implementing GetHashCode().
namespace Helpers
{
// Used like:
// public override int GetHashCode() {
// return 17.CombineHashWith(foo).CombineHashWith(bar).CombineHashWith(GetType());
// }
public static int CombineHashWith<T>(this int initialHash, T other)
{
var otherHash = other == null ? 0 : other.GetHashCode();
return initialHash + initialHash * 23 + otherHash;