Skip to content

Instantly share code, notes, and snippets.

@JamesTryand
JamesTryand / about.md
Created August 10, 2011 18:16 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@JamesTryand
JamesTryand / uri.js
Created April 23, 2012 20:58 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@JamesTryand
JamesTryand / NuGet.targets.xml
Created May 3, 2012 09:47 — forked from half-ogre/NuGet.targets.xml
A replacement for the NuGet.targets file that requires nuget.exe be on the path, so you don't have to commit it.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Windows specific commands -->
<PackagesConfig Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir Condition=" '$(OS)' == 'Windows_NT'">$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
@JamesTryand
JamesTryand / gist:2630087
Created May 7, 2012 20:11 — forked from mausch/gist:2630024
VB.NET funcs
Just found out that VB.NET can infer function types correctly. I.e. this won't work in C#:
var withMemoryStream =
(Action<MemoryStream> f) => () => {
using (var ms = new MemoryStream())
f(ms);
};
("Cannot assign lambda expression to implicitly-typed local variable", because it can't tell a Func<T> from an Expression<Func<T>>).
But the exact same code in VB.NET does work:
@JamesTryand
JamesTryand / MonadExamples.fs
Created May 9, 2012 18:57 — forked from t0yv0/MonadExamples.fs
Emulating higher kinds with F# inline functions.
(* F# lacks proper support for higher-kinded abstraction such as ML
functors or Haskell typeclasses. In particular it makes it seemingly
impossible to define functions that work for every type constructor.
The code below demonstrates that this functionality can be partially
recovered by using inline functions with static member constraints.
The approach requires explicitly passing typeclass instance values.
Error messages and derived types are horrible. Nonetheless, there is
some type safety - if the typeclass instances have been defined right,
type-unsafe code will be rejected by the typechecker, albeit with a
hairy message. Another disadvantage is the need to invent operators. *)
@JamesTryand
JamesTryand / .gitconfig
Created June 8, 2012 20:51 — forked from isaacs/.gitconfig
These are my shortcuts for git.
# A bunch of the stuff above relies on this, especially the aliases.
[user]
# you probably want to change this bit.
name = isaacs
email = [email protected]
signingkey = 0x6C481CF6
[alias]
ci = commit
st = status
br = branch
@JamesTryand
JamesTryand / SpecificationFixture.cs
Created July 21, 2012 19:23 — forked from yevhen/SpecificationFixture.cs
NUnit support for Greg Young's Simple.Testing "framework"
[TestFixture]
public class SpecificationFixture
{
[Test, TestCaseSource("GetSpecificationTestCases")]
public void Verify(SpecificationToRun spec)
{
var runner = new SpecificationRunner();
RunResult result = runner.RunSpecifciation(spec);
if (result.Passed)
using System;
using System.IO;
using MsgPack.Serialization;
using ZeroMQ_MessagePack_Testbed.Models;
using ZMQ;
namespace ZeroMQ_MessagePack_Testbed
{
class Program
{

The Indexed State Monad in Haskell, Scala, and C#

Have you ever had to write code that made a complex series of succesive modifications to a single piece of mutable state? (Almost certainly yes.)

Did you ever wish you could make the compiler tell you if a particular operation on the state was illegal at a given point in the modifications? (If you're a fan of static typing, probably yes.)

If that's the case, the indexed state monad can help!

Motivation

namespace PKI
{
class Results : IEquatable<Results>
{
internal static readonly Results NotFound = new Results
{
Directory = "",
KeyName = ""
};