Skip to content

Instantly share code, notes, and snippets.

View rjregenold's full-sized avatar

RJ Regenold rjregenold

  • Provider Science
  • Texas
View GitHub Profile
@YoEight
YoEight / State.hs
Last active August 29, 2015 14:07
A different State encoding (solution here https://gist.github.com/YoEight/0541aa293effbfff8d02)
{-# LANGUAGE RankNTypes #-}
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r }
stateReturn :: a -> State s a
stateReturn = undefined
stateMap :: (a -> b) -> State s a -> State s b
stateMap = undefined
{-# LANGUAGE RankNTypes #-}
newtype State s a = State { runState :: forall r. s -> (a -> s -> r) -> r }
stateReturn :: a -> State s a
stateReturn a = State $ \s k -> k a s
stateMap :: (a -> b) -> State s a -> State s b
stateMap f (State sa) = State $ \s kb -> sa s (kb . f)
@kwhinnery
kwhinnery / Person.js
Created July 19, 2011 22:52
Monkey patch for require in Titanium Mobile
exports.Person = function(firstName,lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
@mpilquist
mpilquist / gist:3428731
Created August 22, 2012 19:46
Example of trampolining iteratees with scalaz 7
import scalaz._
import Scalaz._
import scalaz.iteratee._
import EnumeratorT._
def counter[A, F[+_]: Pointed] =
IterateeT.fold[A, F, Int](0) { (acc: Int, a: A) => acc + 1 }
def count[A, F[+_]: Monad](e: EnumeratorT[A, F]) =
(counter[A, F] &= e).run
sealed trait KeyValueStore[+A] {
def map[B](f: A => B): KeyValueStore[B] =
this match {
case Put(k, v, q) => Put(k, v, f compose q)
case Get(k, q) => Get(k, f compose q)
case Del(k, q) => Del(k, f compose q)
}
}
case class Put[A](k: String, v: String, q: Option[String] => A) extends KeyValueStore[A]
case class Get[A](k: String, q: Option[String] => A) extends KeyValueStore[A]
@MichaelXavier
MichaelXavier / Gemfile
Last active December 18, 2015 21:29
Some ruby-based tooling for haskell projects that makes development easier for me. Sandboxing requires cabal >= 0.1.7
source "http://rubygems.org"
gem "guard-shell"
gem "rake"
@milessabin
milessabin / gist:6081113
Last active December 20, 2015 05:49
Slicing and dicing tuples in shapeless 2.0.0-SNAPSHOT.
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._
import shapeless._
scala> import syntax.tuple._
import syntax.tuple._
/* discovered njoin on this thread: https://github.com/functional-streams-for-scala/fs2/issues/251 - which also cites (adjusted to match example below):
If we increase maxQueued up to 100, and `handle` emits multiple `A` values, up to 100 will be prefetched
before we block on the consumer of results. (Not actually blocking by occupying a thread, but semantically blocking.)
If we increase maxOpen to 50, then we can have 50 `item` streams processing concurrently.
*/
import scalaz.stream.{Sink,Process,sink,channel}
import scalaz.stream.nondeterminism.njoin
@milessabin
milessabin / gist:25b7b669b5a9ac051a71
Created June 5, 2015 14:32
A safe ADT+shapeless drop-in replacement for the unsafe standard Scala Enumeration ...
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo extends App {
// Example from scala.Enumeration scaladoc. Terse ...
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
@fwenzel
fwenzel / lion-virtualenv.sh
Created July 21, 2011 17:42
Recreating virtualenvs after upgrading to OS X Lion.
# Upgrade to OS X Lion, notice your virtualenvs are all hosed.
# Install Xcode 4.1 from the app store (or //fs2/IT/Apple/).
# Make sure to actually *run* the install, it's an app inside Applications. Throw it away afterwards, if you want the space back.
sudo easy_install pip
sudo pip install virtualenv virtualenvwrapper ipython
# blow the old one(s) away
rmvirtualenv playdoh