Skip to content

Instantly share code, notes, and snippets.

View vmarquez's full-sized avatar

Vincent Marquez vmarquez

  • Irvine, CA
View GitHub Profile
@Mortimerp9
Mortimerp9 / Memoizer.md
Created May 31, 2013 18:22
As an exercise, I was trying to implement a memoization of single parameter functions with a bounded cache size; a very simple approach with a First In First Out strategy but with a good concurrent behaviour. It's probably not perfect, let me know what you think of it.

#Bounded Memoizer

As an exercise, I was trying to implement a memoization of single parameter functions with a bounded cache size; a very simple approach with a First In First Out strategy. It's probably not perfect, let me know what you think of it.

The specs are that the memoizer should be concurrent and kick out the "oldest" computation. For instance, with a maximum size of 2 slots in the cache:

  foo(0) //computes and cache the result for 0
  foo(1) //computes and cache the result for 1
  foo(0) // returns the cached result
 foo(2) // computes and cache the result for 2 and kicks out the result for 0)
@tpolecat
tpolecat / gist:5633028
Last active December 17, 2015 15:39
Ideas re: IO and Future
// Some thoughts on IO and Futures
object Future {
// A future must have the option of performing IO during its computation; this
// is one of the primary uses of Futures. So we construct with an IO[A]. Construction
// is itself an effect because it forks execution of `a`.
def ioFuture[A](a: IO[A]): IO[Future[A]]
// Unit, but it has to be eager, so not super useful. What if it's not really a monad at all?
@dscleaver
dscleaver / Fib.scala
Created February 27, 2013 14:45
Port of http://t.co/KvoY7PDGSg. Created in a Scala IDE worksheet.
import scalaz._
import Scalaz._
object monads {
def fix[A](f: (=> A) => A): A = f(fix(f)) //> fix: [A](f: => A => A)A
type Gen[A] = (=> A) => A
def gFib: Gen[Int => Int] = (self) => n =>
@aloiscochard
aloiscochard / qsbt.sh
Last active March 5, 2018 21:34
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
#!/usr/bin/env bash
############
# QuickSBT #
############
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
# http://github.com/aloiscochard / https://gist.github.com/4698501
# Error format for SBT, and shortcut to open SBT quickfix file :
@vmarquez
vmarquez / ReaderMonad.cs
Last active February 20, 2020 20:30
This is an example of using the Reader Monad for Dependency Injection using LINQ in C#. I learned about this from Tony Morris and Rúnar Bjarnason's video here: http://www.youtube.com/watch?v=ECPGTUa1WAI To figure out the (slightly weird) SelectMany peculiarities I found http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
//Reader Monad and its extension class to give it SelectMany(bind/flatMap) capabilities for use in LINQ queries
public static class ReaderMonadExt
{
public static ReaderMonad<T, C> SelectMany<T, A, B, C>(this ReaderMonad<T, A> rm, Func<A, ReaderMonad<T, B>> bindf, Func<A, B, C> select)
{
return new ReaderMonad<T, C>(t =>
{
var a = rm.Run(t);
return select(a, bindf(a).Run(t));
});
@dtchepak
dtchepak / lens.cs
Created August 3, 2012 07:04
Attempt at lens in c#
public class Lens<T, TValue>
{
public Func<T, TValue> Get { get; private set; }
public Func<TValue, T, T> Set { get; private set; }
public Lens(Func<T, TValue> get, Func<TValue, T, T> set)
{
Get = get;
Set = set;
}