Skip to content

Instantly share code, notes, and snippets.

View vmarquez's full-sized avatar

Vincent Marquez vmarquez

  • Irvine, CA
View GitHub Profile
@johnynek
johnynek / async_stream.scala
Last active December 18, 2015 23:09
A simple API using Future and Promise to create an async stream.
// could easily be ported to Scala Future
import com.twitter.util.{Promise, Future}
trait Source[+T] { self =>
def head: Option[T]
def tail: Future[Source[T]]
def map[U](fn: T => U): Source[U] = new Source[U] {
def head = self.head.map(fn)
def tail = self.tail.map { _.map(fn) }
}
@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?
@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;
}
import scalaz._, Free.Trampoline, Scalaz._
sealed trait Command[T]
case class Wait(ms: Long) extends Command[Unit]
case object Evaluator extends (Command ~> Trampoline) {
override def apply[T](cmd: Command[T]) = cmd match {
case Wait(t) => Trampoline.done(Thread.sleep(t))
}
}
@shajra
shajra / invitation.md
Last active August 29, 2015 14:07
an open invitation

If you're interested in making great software by discovering the deeper truth of logic and abstraction, then this is an open invitation for your participation in our community. Unfortunately, most software communities are notoriously imbalanced, creating needless hurdles for people of various gender identities, races, religions, political groups, sexual orientation, and disabled communities (to name a few). Such exclusion services no one's best interest. So, we want to actively call for participation from anyone interested in making our software better.

We guarantee a safe environment where we promote well-reasoned arguments that lead to the greatest software we can possibly make. Unfortunately, along the way someone may make an error, or worse yet, exercise malice. We'll work hard towards keeping conversations objective and inclusive. Sometimes it's tough work, but we're completely invested in the process. If you feel a public forum has not served you well, please contact us privately so we have a ch