Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
import shapeless._
import shapeless.HList._
import Report._
import Chronograph._
val sample = ReportLine(1,1,Micros)
def toHList = Generic.product[ReportLine].to _
val sampleH = toHList(sample)
@pedrofurla
pedrofurla / gist:9905079
Created April 1, 2014 00:06
An instance of the scalaz.Show time class
import scalaz.Show._
import scalaz.Show
implicit val reportline2show: Show[ReportLine] = shows { rl =>
val unitName = rl.timeUnit.name
s"Rows: ${rl.rows}, totalTime: ${rl.time} $unitName, time per row: ${rl.timePerRow} $unitName"
}
@pedrofurla
pedrofurla / gist:9885465
Last active August 29, 2015 13:57
A little combinator to measure the time of side effects. YES, *side effects* for now
object Chronograph {
/** Chronon is the quantum of time, here in our silly computers it got be a Long */
type Chronon = Long
sealed case class TimeUnit(chrononsInSecond: Chronon, name:String, getTime: => Chronon)
val Nanos = new TimeUnit(1e9.toLong, "ns", System.nanoTime)
val Micros = new TimeUnit(1e6.toLong, "μs", System.nanoTime*1000)
val Millis = new TimeUnit(1e3.toLong, "ms", System.currentTimeMillis())
/**
* Created by pedrofurla on 26/03/14.
*/
package slicks.docs
import slicks.docs.dao.{Entity, IdentifiableTable, CrudComponent, Profile}
case class User(id: Option[Long], first: String, last: String) extends Entity[Long]
trait UserComponent extends CrudComponent { outer: Profile =>
@pedrofurla
pedrofurla / gist:9711330
Created March 22, 2014 17:43
Is this tailrec? Doesn't look to me
@tailrec private def isEvenlyDivisible(i: Int, a: Int, b: Int): Boolean = {
if (i > b) true
else (a % i == 0) && isEvenlyDivisible(i+1, a, b)
}
@pedrofurla
pedrofurla / gist:9680957
Created March 21, 2014 06:56
Pretty print from WebIDL for WebGL
typedef GLenum = unsigned long
typdef GLboolean = boolean
typdef GLbitfield = unsigned long
typdef GLbyte = byte
typdef GLshort = short
typdef GLint = long
typdef GLsizei = long
typdef GLintptr = long long
typdef GLsizeiptr = long long
typdef GLubyte = octet
@pedrofurla
pedrofurla / gist:9355837
Created March 4, 2014 21:16
A very humble usage of SYB (so far)
isIdent :: String -> Ident -> Bool
isIdent s (Ident id') = id' == s
isIdentG :: forall a. Typeable a => String -> a -> Bool
isIdentG s = False `mkQ` (isIdent s)
{-| One level search of `Ident`s -}
withId1 :: forall a. Data a => String -> a -> Bool
withId1 s = or . (gmapQ (isIdentG s)) -- This saves me from matching against 7 different constructors
@pedrofurla
pedrofurla / gist:9025691
Created February 15, 2014 21:54
A little model for a subset of WebIdl
{-# LANGUAGE ExistentialQuantification #-}
module WebIdl.Ast where
import WebIdl.Lex
type Ident = String
type ExtAttributes = String
type Default = Maybe Literal
@pedrofurla
pedrofurla / gist:9004626
Created February 14, 2014 16:48
Trifecta conflicting everywhere.
comonad-4.0 (reinstall) changes: semigroups-0.12.2 -> 0.12.1
exceptions-0.3.3 (new package)
newtype-0.2 (new package)
constraints-0.3.4.2 (new package)
parsers-0.10.3 (new package)
scientific-0.2.0.1 (reinstall) changes: hashable-1.1.2.5 -> 1.2.1.0
aeson-0.7.0.1 (new version)
semigroupoids-4.0 (reinstall) changes: semigroups-0.12.2 -> 0.12.1
bifunctors-4.1.1 (new version)
pointed-4.0 (new version)
@pedrofurla
pedrofurla / example.js
Created January 23, 2014 07:12
Mapping from source JS (generated from .scala) to the actual Scala source(s)
ScalaJS.impls.example_WebAudio$AudioParam$class__$init$__Lexample_WebAudio$AudioParam__V = (function($this) {
$this.value_$eq__Lscala_scalajs_js_Number__V(ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing());
$this.example$WebAudio$AudioParam$_setter_$defaultValue_$eq__Lscala_scalajs_js_Number__V(ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing())
});
ScalaJS.impls.example_WebAudio$GainNode$class__$init$__Lexample_WebAudio$GainNode__V = (function($this) {
$this["example$WebAudio$GainNode$_setter_$gain"] = ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing()
});
/** @constructor */