Skip to content

Instantly share code, notes, and snippets.

@allenday
allenday / scalding_cos_cor.scala
Last active August 29, 2015 13:58
Scalding cosine and correlation coefficient
// cosine distance and pearson correlation
// see http://ow.ly/vtm44
package com.allenday
import com.twitter.scalding._
import com.twitter.scalding.mathematics._
import com.twitter.scalding.mathematics.Matrix._
class SimJob(args : Args) extends Job(args) {
@Mortimerp9
Mortimerp9 / RefreshEvery.scala
Created May 2, 2014 21:07
Sort of a lazy val, but that refreshes itselfs every so often; or a temporary cache for a value T, will be refreshed at a minimun at the specified interval.
import com.twitter.util.{Duration, Time}
/**
* Sort of a lazy val, but that refreshes itselfs every so often; or a temporary cache for a value T,
* will be refreshed at a minimun at the specified interval.
* In practice, the refresh is done only when the value is accessed, so there are no guarantees
* to when it will actually be refreshed. You can just be sure that it won't be refreshed if two calls
* are made within `every`.
*/
class RefreshEvery[T](every: Duration)(refresh: => T) {
@milessabin
milessabin / gist:aae285025a32fac0f5c1
Last active August 26, 2017 10:28
Trivial type safe heterogenous map using only dependent method types, singleton-typed String literal keys and implicits.
scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
scala> def mkAssoc[V0](k: String, v: V0): Assoc[k.type] { type V = V0 } =
| new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [V0](k: String, v: V0)Assoc[k.type]{type V = V0}
scala> implicit def nameAssoc = mkAssoc("Name", "Mary")
nameAssoc: Assoc[String("Name")]{type V = String}
@EverythingSmartHome
EverythingSmartHome / All open windows and doors
Last active April 1, 2026 12:54
A collection of useful templates for Home Assistant dashboards
{{ states.binary_sensor
| selectattr('attributes.device_class', 'in', ['door','window'])
| selectattr('state', 'equalto', 'on')
| list | count }}