Skip to content

Instantly share code, notes, and snippets.

@hvesalai
hvesalai / ScalatraServer.scala
Created October 24, 2011 19:41 — forked from casualjim/ScalatraServer.scala
dsl proposal for embedded servers
object Main {
def main(args: Array[String]) {
MySquerylScheme.initialize()
WebServer("src/main/webapp", Config.webServerPort) { server =>
server.inContext("/api") { context =>
context.mount("validate", new ValidateApp)
context.mount("channels", new MessageChannelApp)
context.mount("streams", new StreamsApp)
@hvesalai
hvesalai / ScalatraServer.scala
Created October 25, 2011 04:12 — forked from casualjim/ScalatraServer.scala
dsl proposal for embedded servers
object Main {
def main(args: Array[String]) {
MySquerylScheme.initialize()
WebServer("src/main/webapp", Config.webServerPort) { server =>
server.inContext("/api") { context =>
context.mount("validate", new ValidateApp)
context.mount("channels", new MessageChannelApp)
context.mount("streams", new StreamsApp)
def (o1: Option[B], o2: Option[C]): A = {
val a: A = new A
val b: A = o1.map(o => A.foo(o)).getOrElse(a)
o2.map(o => A.bar(o)).getOrElse(b)
}
@hvesalai
hvesalai / gist:407a3a6543e01b2909e2
Last active August 29, 2015 14:19
gulp error handler
(add-hook 'js-mode-hook '(lambda ()
;; /home/hvesalai/projects/foo/Bar.jsx: line 6, col 63
(add-to-list 'compilation-error-regexp-alist-alist
`(eslint-compact
,(rx line-start
(group (zero-or-one letter ":") (1+ (not (any ": "))))
": line " (group (1+ digit))
", col " (group (1+ digit)))
1 2 3))
import scalaz.stream.{Process, Tee, tee}
import Process.{awaitL, awaitR, emit}
import tee.{feed1R, feed1L}
object StreamSupport {
/* A Tee that drop from left while the predicate `p` is true for the
* values, then continue with the Tee `rest` */
def dropWhileL[L,R,O](p: L => Boolean)(rest: Tee[L,R,O]): Tee[L,R,O] =
awaitL[L].flatMap { v =>
trait VectorSpace[A] { } // isomorphisms
trait Iso[A, B] {
def to(a: A): B
def from(b: B): A
}
trait TensorAlgebra {
type * [V]
type ⨂ [V, W]
type ⨁ [V, W]
type Z
@hvesalai
hvesalai / issue.scala
Last active May 16, 2018 06:34 — forked from MarkRBM/issue.scala
monadic join issue
val sensorDatas = TableQuery[SensorDataTable]
val sensorRoomLinks = TableQuery[SensorRoomLinks]
private def sensorsForRoomsForRange(roomLinks: Seq[SensorRoomLink], from: ZonedDateTime, to: ZonedDateTime): Query[(tables.SensorRoomLinks, tables.SensorDataTable), (SensorRoomLink, UtilizationData), Seq] = {
import IdTable._
val joined = sensorDatas join sensorRoomLinks on (_.sensorId === _.sensorUid)
val filtered = joined.filter { case (data, link) => (link.roomId inSet roomLinks) && (data.sensorUid inSet sensorIds) && /* other conditions here */ }
val grouped = filtered.groupBy { case (data, link) => link.roomId }
val aggregated = grouped.map { case (roomId, rows) => roomId -> rows.map{ case (data, link) => data.value }.max }
aggregated
import com.onomatics.phonetic.Syllable
import com.onomatics.phonetic.Syllable.SyllableVector
import com.onomatics.phonetic.Phoneme.loadSymbolFeatures
def caRaw(syllable: String) = {
val s = SyllableVector.parse(syllable, featuresBySymbol)
val (onsetCore, onsetAffix) = Syllable.splitCoreAffix(s.onsetFull, false)
val (codaCore, codaAffix) = Syllable.splitCoreAffix(s.codaFull, true)
List(onsetAffix.reverse, onsetCore.reverse, codaCore, codaAffix)
< 009935751
< 009935801
< 013893805
< 014865117
< 014947295
< 015963391
< 016432221
< 016434284
< 016434921
< 016436719
> 000256818
> 002436376
> 002666030
> 002786168
> 002904902
> 004229985
> 004524492
> 004798311
> 005266051
> 005592704