Skip to content

Instantly share code, notes, and snippets.

@pomadchin
pomadchin / shapelessExperiments1.scala
Last active December 27, 2015 22:29
HList as a parameter
def split[H, T <: HList](l: H :: T) = l.head
@pomadchin
pomadchin / covertMatrixJob.scala
Last active December 28, 2015 13:09
Hadoop practice, a small converter for matrix.
/*
@daunnc, stackoverflow: http://stackoverflow.com/questions/20020967/transforming-matrix-format-scalding-solved
converts
1 2 3
3 4 5
6 7 8
to
@pomadchin
pomadchin / shapelessFuncFilter.scala
Last active December 29, 2015 06:19
shapeless custom type filter for functions
/**
* Type class supporting access to the all elements of this `HList` for functions from type `U` ~(`U => V`).
*
* author of original HList Filter Alois Cochard
*
* @author Grigory Pomadchin
*/
object am3 {
trait FuncFilter[L <: HList, U] extends DepFn1[L] { type Out <: HList }
@pomadchin
pomadchin / hmacSha1.scala
Last active August 29, 2015 14:00
hmacSha1 function
def hmacSha1(value: String, key: String) = {
// Get an hmac_sha1 key from the raw key bytes
val keyBytes = key.getBytes
val signingKey = new SecretKeySpec(keyBytes, "HmacSHA1")
// Get an hmac_sha1 Mac instance and initialize with the signing key
val mac = Mac.getInstance("HmacSHA1")
mac.init(signingKey)
// Compute the hmac on input data bytes
#!/usr/bin/env bash
#
# Compile and install MongoDB with SSL support
# tested an works on Ubuntu 12.04 LTS x64 and Ubuntu 14.04 LTS x64
#
set -e
set -u
set -o pipefail
@pomadchin
pomadchin / Build.scala
Created April 10, 2015 08:24
Gt-Admin fix failed
// val akkaV = "2.3.4-spark"
val akkaV = "2.2.3-shaded-protobuf"
val sprayV = "1.2.2"
val geotrellisV = "0.10.0-SNAPSHOT"
Seq(
"io.spray" % "spray-can" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" % "spray-routing" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" % "spray-caching" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" %% "spray-json" % "1.2.6" excludeAll ExclusionRule("com.typesafe.akka"),
@pomadchin
pomadchin / Build.scala
Created May 4, 2015 19:33
Spray-Spark example
// val akkaV = "2.2.3-shaded-protobuf"
val akkaV = "2.3.4-spark"
val sprayV = "1.2.2"
Seq(
"io.spray" % "spray-can" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" % "spray-routing" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" % "spray-caching" % sprayV excludeAll ExclusionRule("com.typesafe.akka"),
"io.spray" %% "spray-json" % "1.2.6" excludeAll ExclusionRule("com.typesafe.akka"),
"org.spark-project.akka" %% "akka-actor" % akkaV,
@pomadchin
pomadchin / applyToType.scala
Last active November 5, 2015 10:25
Implement product type in Scala with generic update function working on its parts
// Stackoverflow discussion: http://stackoverflow.com/questions/33541107/implement-product-type-in-scala-with-generic-update-function-working-on-its-part
// shapeless 2.2.5
import shapeless._
import ops.hlist._
import ops.traversable._
import shapeless.syntax.std._
import shapeless.syntax.std.traversable._
case class A(fieldA: String)
@pomadchin
pomadchin / BuildUtil.scala
Created November 12, 2015 11:53
Build util
// http://scastie.org/13093
/***
sbtPlugin := true
*/
import sbt._
import Keys._
object BuildUtil {
private val localLibs = scala.util.Try(IO.read(file("local-libs.txt"))).map(_.split('\n').map(_.trim).toSet).getOrElse(Set())
@pomadchin
pomadchin / Test.scala
Created November 19, 2015 10:31
Example of the correct values call.
import annotations.template
import reflect.runtime.universe.TypeTag
case class SW(s: String)
case class IW(c: Int)
case class BW(d: Double)
case class PD(sw: SW, iw: IW, bw: BW)
@template((i: Int, s: String, d: Double) => PD(SW(s), IW(i), BW(d)))
object Test2 {