Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
@teropa
teropa / resources.md
Last active December 4, 2020 05:42
Clojure Resources

Tutorials

@travisbrown
travisbrown / noncompilation.scala
Last active January 13, 2016 18:00
Testing for compiler errors with untyped macros.
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
scala> import scala.reflect.macros.{ Context, TypecheckException }
import scala.reflect.macros.{Context, TypecheckException}
scala> object NoncompilationTests {
| def compiles(code: _): Boolean = macro compiles_impl
| def compiles_impl(c: Context)(code: c.Tree) = c.literal(
| try {
@gseitz
gseitz / build.scala
Created February 19, 2013 22:52
SBT task for running all main classes
import sbt._
import Keys._
import Build.data
object build extends Build {
lazy val runAll = TaskKey[Unit]("run-all")
lazy val standardSettings = Seq(
runAllIn(Compile)
)
@MLnick
MLnick / StreamingCMS.scala
Created February 13, 2013 15:00
Spark Streaming with CountMinSketch from Twitter Algebird
import spark.streaming.{Seconds, StreamingContext}
import spark.storage.StorageLevel
import spark.streaming.examples.twitter.TwitterInputDStream
import com.twitter.algebird._
import spark.streaming.StreamingContext._
import spark.SparkContext._
/**
* Example of using CountMinSketch monoid from Twitter's Algebird together with Spark Streaming's
* TwitterInputDStream
@etorreborre
etorreborre / gist:3870064
Created October 11, 2012 03:54
Unboxed union types with a context bound
/**
* this is an experiment to create unboxed union types with a phantom type and a context bound.
* All the good ideas come from @milessabin post, comments and links: http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/#comment-22
*/
/** trait for anything that can be A or B */
trait Or[A, B] {
// a phantom type, there will be no instance of this type that we'll use
type l[T]
// an alias for l[t]
trait Option[+A] {
@inline final def cata[Z](some: A => Z, none: => Z) = this match {
case Some(a) => some(a)
case None => none
}
}
object Option {
private[Option] case class Some[+A](a: A) extends Option[A]
private[Option] case object None extends Option[Nothing]
@tonymorris
tonymorris / Fold.hs
Created September 18, 2012 01:14
Anna meets Cata
foldr ::
(a -> b -> b)
-> b
-> [a]
-> b
-- same:
foldr ::
((a, b) -> b)
@Chouser
Chouser / gist:3687532
Created September 9, 2012 21:52
Lazy seq as event subscription mechanism
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous.
;; This defines the event stream, in this case just a series of numbers,
;; a new one produced each second
(defn timer []
(lazy-seq
(do
(Thread/sleep 1000)
(cons (System/nanoTime) (timer)))))
@tonymorris
tonymorris / ListZipper.scala
Created August 29, 2012 01:15
List Zipper
case class ListZipper[+A](lefts: List[A], x: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
sys.error("todo")
// map with zipper context
def coFlatMap[B](f: ListZipper[A] => B): ListZipper[B] =
sys.error("todo")
def findRight(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
@headius
headius / gist:3491618
Created August 27, 2012 19:34
JVM + Invokedynamic versus CLR + DLR

Too much for teh twitterz :)

JVM + invokedynamic is in a completely different class than CLR + DLR, for the same reasons that JVM is in a different class than CLR to begin with.

CLR can only do its optimization up-front, before executing code. This is a large part of the reason why C# is designed the way it is: methods are non-virtual by default so they can be statically inlined, types can be specified as value-based so their allocation can be elided, and so on. But even with those language features CLR simply cannot optimize code to the level of a good, warmed-up JVM.

The JVM, on the other hand, optimizes and reoptimizes code while it runs. Regardless of whether methods are virtual/interface-dispatched, whether objects are transient, whether exception-handling is used heavily...the JVM sees through the surface and optimizes code appropriate for how it actually runs. This gives it optimization opportunities that CLR will never have without adding a comparable profiling JIT.

So how does this affect dynamic