Skip to content

Instantly share code, notes, and snippets.

@Steell
Steell / ReactiveUndoRedoRecorder.cs
Last active April 30, 2018 14:47
Rx Implementation of an Undo/Redo Recorder.
using System;
using System.Collections.Immutable;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace Steellworks.Rx.UndoRedo
{
/// <summary>
/// Defines properties for fetching a value and its inverse.
@Steell
Steell / ReactiveUndoRedoSamples.cs
Last active August 29, 2015 14:08
ReactiveUndoRedoRecorder sample
using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
public static void Example()
{
// Subjects and functions for performing undos and redos
Subject<Unit> undoSubject = new Subject<Unit>();
Subject<Unit> redoSubject = new Subject<Unit>();
@Steell
Steell / zoom.hs
Created September 27, 2016 18:01
Generic lens zoom for MonadState
module Zoom where
import Control.Lens
import Control.Lens.Internal.Zoom
import Control.Monad.State
zoom' :: MonadState t m => LensLike' (Focusing m b) t s -> StateT s m b -> m b
zoom' l st = do
(a, s) <- get >>= runStateT (zoom l st)
put s
@Steell
Steell / mtl-recursive.hs
Last active September 28, 2016 20:55
Why doesn't this typecheck?
import Control.Monad.Reader
data Foo m = Foo { action :: m Int }
runFoo :: (MonadReader (Foo m) m) => m Int
runFoo = ask >>= action
bar :: IO Int
bar = runReaderT runFoo (Foo readLn)
data PlayerInfo c = PlayerInfo { _playerName :: String
, _playerAttack :: forall m. c m => m ()
}
data AttackInfo a = AttackInfo { _infoAttacker :: PlayerInfo a
, _infoTarget :: PlayerInfo a
}
data GameInfo a = GameInfo { _gamePlayer1 :: PlayerInfo a
, _gamePlayer2 :: PlayerInfo a
}
@Steell
Steell / readerlens.hs
Last active June 21, 2017 21:56
MonadReader + Lens
data Foo a = Foo { _unFoo :: a }
makeLenses ''Foo
newtype Newline = Newline { unNewline :: String }
instance Monoid Newline where
mempty = Newline []
mappend (Newline []) b = b
mappend a (Newline []) = a
mappend (Newline a) (Newline b) = Newline $ a `mappend` "\n" `mappend` b
@Steell
Steell / default.nix
Created May 21, 2018 02:50
open-zwave src override
let
pkgs = import <nixpkgs> {};
gitHub = pkgs.fetchFromGitHub;
in
with pkgs;
openzwave.overrideAttrs (oldAttrs: {
src = gitHub {
owner = "Steell";
repo = "open-zwave";
class Butt {
interface ButtDBAdapter {
public function insertFinger($force);
public function feel();
}
function __construct($dbAdapter) {
$db = $dbAdapter;
}
@Steell
Steell / butt-injection.php
Last active June 21, 2018 21:22
"Dependency" injection
class Butt {
interface DBAdapter {
public function insertFinger($force);
public function feel();
}
function __construct($dbAdapter) {
$db = $dbAdapter;
}
@Steell
Steell / foo.nix
Last active September 28, 2018 19:12
Haskell + Nix testing
# shell.nix
let
releaseDrv = import ./release.nix;
cabal = releaseDrv.haskellPackages.cabal;
in
releaseDrv
.haskell-nix-sandbox
.env
.overrideAttrs (drv: {