Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
@arosien
arosien / runar-io-free.scala
Last active September 10, 2016 07:17
Translation of Runar's ScalaIO 2013 presentation on IO and Free monads (http://blog.higher-order.com/assets/scalaio.pdf) to scalaz.
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {
@helena
helena / Topology.scala
Last active December 23, 2015 21:59
Creates a topology based on configurations. How would you improve it, and how would you write it in Scalaz?
import java.lang.System.{ currentTimeMillis ⇒ newTimestamp }
import scala.util.Try
import scala.collection.immutable
import scala.collection.JavaConverters._
import akka.actor._
import akka.japi.Util.immutableSeq
import com.typesafe.config._
@non
non / infset.scala
Last active December 22, 2015 04:18
Examples of non-container set implementations for Scala.
package spire.examples
import spire.algebra._
import spire.math.{Natural, UInt}
import scala.collection.mutable
object SetUtil {
def powerStream[A](members: Stream[A]): Stream[Set[A]] = {
val done = Stream.empty[Set[A]]
@tonyg
tonyg / mtl2.rkt
Last active December 18, 2015 22:59
From zero to cooperative threads in 15 lines of Racket code (after <http://www.haskellforall.com/2013/06/from-zero-to-cooperative-threads-in-33.html>)
#lang racket/base
(require data/queue)
(provide fork yield done run-threads)
(define current-runqueue (make-parameter #f))
(define (fork thunk)
(enqueue! (current-runqueue) (lambda () (thunk) (done))))
(define (yield)
@tylerneylon
tylerneylon / learn.lua
Last active April 3, 2025 04:11
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@gigasquid
gigasquid / brackets.clj
Created June 5, 2013 13:23
Clojure and Coffee with Instaparse
(ns brackets.core-test
(:use clojure.test
brackets.core
instaparse.core))
(def my-parser
(parser
"S = func-apply | vector | integer
integer = #'[0-9]+'
<space> = <' '>
@vmarquez
vmarquez / TxMapTest.scala
Last active November 28, 2021 12:33
A mini STM if you will. I've made a'Transactional' map that mutates in a referentially transparent way.
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.CountDownLatch
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import ExecutionContext.Implicits.global
object TxMapTest {
/*
* Example Usage
* We want to show two threads working with the same data source having both of their effects succeed
@mrb
mrb / coll.rkt
Last active December 17, 2015 13:29
Annoted mark and sweep collector in Racket, with the test code removed. From https://github.com/plt/racket/blob/master/collects/tests/plai/gc/good-collectors/good-collector.rkt#L28-L30
#lang plai/collector
;; A tri-color mark and sweep algorithm. There are three sets of heap nodes:
;; gray, white, and black. Black nodes are known to not be garbage or hold
;; references to garbage, gray nodes are known to not be garbage but their
;; references have not been checked, and white nodes, the rest, are garbage.
;; * The black set begins empty
;; * The gray set begins with the roots
;; * All non root nodes begin in the white set
;; * Iterate over the gray set. "Blacken" each node by "graying" the nodes
@debasishg
debasishg / gist:5567328
Created May 13, 2013 10:08
regex interpolation fails ..
Apples-MacBook-Pro:~ debasishg$ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
implicit class RContext(sc: StringContext) {
def r =