Skip to content

Instantly share code, notes, and snippets.

View cvogt's full-sized avatar

Jan Christopher Vogt cvogt

  • Symbiont.io
View GitHub Profile
@aloiscochard
aloiscochard / Stream.scala
Created November 2, 2011 16:06
Scala [In]finite Stream Constructor
import Stream._
/** A possibly finite stream that repeatedly applies a given function to a start value.
*
* @param start the start value of the stream
* @param f the function that's repeatedly applied
* @return the stream returning the possibly finite sequence of values `start, f(start), f(f(start)), ...`
*/
def iterate[A](f: A => A, a: A): Stream[A] = unfold((x: A) => Some((x, f(x))), a)
@gcatlin
gcatlin / gist:1847248
Created February 16, 2012 19:43
Install specific version of Homebrew formula
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@umpirsky
umpirsky / A.markdown
Last active August 3, 2023 18:14 — forked from olivierlacan/An_example.markdown
Sublime Text Monokai Sidebar Theme.
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T](data: Option[T])(f: T => X => scala.slick.lifted.Column[Boolean]) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
def find(id: Option[Int], createdMin: Option[Date], createdMax: Option[Date], modifiedMin: Option[Date], modifiedMax: Option[Date]) = {
@cvogt
cvogt / gist:9239494
Last active September 9, 2019 01:30
Slick app architecture cheat sheet
// Please comment in case of typos or bugs
import scala.slick.driver.H2Driver._
val db = Database.for...(...)
case class Record( ... )
class Records(tag: Tag) extends Table[Record](tag,"RECORDS"){
...
def * = ... <> (Record.tupled,Record.unapply)
// place additional methods here which return values of type Column
@deech
deech / Subtyping.hs
Last active September 22, 2015 06:23
Subtyping, OO-Style
{-# LANGUAGE GADTs, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, FlexibleContexts, OverlappingInstances, ScopedTypeVariables #-}
-- The goal of the code below is to emulate OO method dispatch.
--
-- The use-case is binding to a C++ GUI framework that is heavily OO and
-- providing the user with a familiar experience.
--
-- This scheme sketched out below emulates not only OO style method dispatch
-- but also allows users to "sub-class", "override" and even arbitrarily
-- change the type signature of overridden methods, all without touching the
-- original library code.
@etorreborre
etorreborre / mini.scala
Created June 3, 2015 00:35
Minimal spec based on specs2
import org.specs2._
import execute._
import specification._
import core._
class TestSuite(tests: Fragment*) extends Specification {
def is = br ^ Fragments.foreach(tests)(f => Fragments(f, br))
}
object TestSuite {
"biz.enef" %% "slogging-slf4j" % "0.3"
"biz.enef" %% "surf-akka" % "0.0.1"
"bound" %% "bound-core" % "1.3.0"
"bound" %% "bound-f0-binding" % "1.3.0"
"bound" %% "bound-scalacheck-binding" % "1.3.0"
"com.elderresearch" %% "monadic-jfx" % "0.1.0"
"com.geteit" %% "geteit-app" % "0.1"
"com.geteit" %% "geteit-utils" % "0.3"
"com.github.gearzero" %% "slick-threeten-mapper" % "0.1.0"
"com.github.imapi" %% "spark-sqs-receiver" % "1.0.1"
@etorreborre
etorreborre / implicits.scala
Created May 25, 2016 06:35
Show applied implicits in the REPL
scala> import cats.implicits._
import cats.implicits._
scala> (1 -> 2) === (1 -> 3)
res0: Boolean = true
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> showCode(reify { (1 -> 2) === (1 -> 3) }.tree)
import scalatags.Text.all._
import collection.mutable
// http://flatuicolors.com/
val red = "#c0392b"
val green = "#27ae60"
val yellow = "#f39c12"
val blue = "#2980b9"
val magenta = "#8e44ad"
val cyan = "#16a085"
val black = "#000"