Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
type Position = (Int, Int)
newtype PlayerData = PlayerData { _pos :: Position }
data GameStateData = GameStateData PlayerData [Position]
-- player typeclass and instance
class Player p where
@dcastro
dcastro / check-markdown-links.js
Created September 8, 2017 10:10 — forked from estliberitas/check-markdown-links.js
Script checking that all links with references are present in Markdown file.
@dcastro
dcastro / nested-nullables.kt
Last active September 4, 2017 18:41
Nested nullables in Kotlin
// A function that takes an instance of `T` and returns a nullable `T?`
fun <T>toNullable(t: T): T? {
return t
}
// If we pass in a `String`, we get back a `String?`
val s1 : String? = toNullable("" as String)
// So, if we pass in a `String?`, we get back a nested nullable `String??`, right?
// Wrong. We get a `String?`
@dcastro
dcastro / angular.testdoubles.js
Last active August 9, 2017 08:36
AngularJS - test doubles, cheat sheet
// Testing a service with no dependencies
it('description', inject(function(myService) {
expect(myService).to.work.dammit;
}));
// Setting up some test doubles (`dependency` and `dependency2`)
it('description2', function() {
module({
dependency: {
property: 'hello',
@dcastro
dcastro / option.purs
Created June 23, 2017 07:58
Church-encoding of `Option`/Maybe` in Purescript
module Main where
import Prelude
import Control.Monad.Eff.Console
import Data.Foldable (foldMap)
import TryPureScript
type Option a = forall b. (a -> b) -> b -> b
@dcastro
dcastro / Affjax in psci
Last active January 27, 2017 11:02
Using purescript-affjax in psci
-- npm i xhr2 --save
import Prelude
import Control.Monad.Aff
import Control.Monad.Eff.Console
import Network.HTTP.Affjax
void $ runAff logShow (\x -> log x.response) (get "https://httpbin.org/ip" :: Affjax (console :: CONSOLE) String)
void $ runAff logShow (\x -> log (x.response :: String)) (get "https://httpbin.org/ip")
@dcastro
dcastro / TakeWhileInclusiveAsync
Last active August 29, 2015 14:24
TakeWhileInclusive Async - using IAsyncEnumerable
/**
* Using Interactive Extensions Async / Ix-Async
* https://www.nuget.org/packages/Ix-Async/
* https://github.com/Reactive-Extensions/Rx.NET
*/
var tasks = Enumerable.Range(0, 10).Select(i => Task.Run(() =>
{
Debug.WriteLine("evaluating " + i);
@dcastro
dcastro / Enumerable.ZipAll
Created August 18, 2014 07:58
Enumerable.ZipAll
// https://dotnetfiddle.net/INhbdg
public static class EnumerableEx
{
public static IEnumerable<TReturn> ZipAll<T1, T2, TReturn>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
Func<T1, T2, TReturn> f,
T1 seed1,
T2 seed2)
@dcastro
dcastro / NUnit Resharper Templates
Created July 16, 2014 09:25
NUnit Resharper Templates
[NUnit.Framework.TestAttribute]
public void $TestMethodName$()
{
$END$
}
@dcastro
dcastro / Git hook - prefix commit message
Created March 13, 2014 10:53
Git hook - prefix commit message
PREFIX="SVC-41+2: "
ORIG_MSG_FILE="$1"
T="/tmp/git-temp-commit-msg"
(printf "%s" "$PREFIX"; cat "$ORIG_MSG_FILE") > "$T"
cat "$T" > "$ORIG_MSG_FILE"