Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thesamet
thesamet / ReverseProxy.scala
Created November 5, 2014 23:36
Reverse-proxy in Play!
def reverseProxy = Action.async(parse.raw) {
request: Request[RawBuffer] =>
// Create the request to the upstream server:
val proxyRequest =
WS.url("http://localhost:8887" + request.path)
.withFollowRedirects(false)
.withMethod(request.method)
.withVirtualHost("localhost:9000")
.withHeaders(flattenMultiMap(request.headers.toMap): _*)
.withQueryString(request.queryString.mapValues(_.head).toSeq: _*)
@thesamet
thesamet / lvm-raid-ephemeral.yaml
Last active July 27, 2022 14:18
Create raid0 LVM on EC2 ephemeral storage with Ansible.
---
# Create a RAID0 LVM through all ephemeral devices and mounts it.
- hosts: all
gather_facts: false
become: true
tasks:
- apt: name=lvm2 state=present
# On ubuntu, sometimes first ephemeral is already mounted in /mnt.
- mount: name=/mnt src=/dev/xvdb fstype=ext4 state=absent
@thesamet
thesamet / ScalaPbSerializer.scala
Last active November 30, 2020 05:50
Akka serializer for ScalaPB messages
package protoser
import java.util.concurrent.atomic.AtomicReference
import akka.actor.ExtendedActorSystem
import akka.serialization.BaseSerializer
import com.trueaccord.scalapb.GeneratedMessageCompanion
class ScalaPbSerializer(val system: ExtendedActorSystem) extends BaseSerializer {
private val classToCompanionMapRef = new AtomicReference[Map[Class[_], GeneratedMessageCompanion[_]]](Map.empty)
case class DeserializeEnumExpression[T](child: Expression)(implicit clsTag: ClassTag[T]) extends UnaryExpression with NonSQLExpression {
override def nullable: Boolean = true
override protected def doGenCode(ctx: CodegenContext,
ev: ExprCode): ExprCode = {
val inputObject = child.genCode(ctx)
val javaType = ctx.javaType(dataType)
val code =
s"""
@thesamet
thesamet / gist:8104952
Created December 23, 2013 21:24
Angular directive that notifies when it detects element size change.
// Calls a function when a change in an element size is detected.
// Uses polling, since there is currently no way to detect resize
// events with CSS flow (without resorting to JQuery UI Resize)
.directive('taOnResize', function($interval) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var oldWidth = undefined;
var oldHeight = undefined;
var stop = $interval(function() {
@thesamet
thesamet / scalapb.proto
Created November 25, 2016 18:10
scalapb.proto v3
syntax = "proto3";
package scalapb;
option java_package = "com.trueaccord.scalapb";
import "google/protobuf/descriptor.proto";
message ScalaPbOptions {
// If set then it overrides the java_package and package.
@thesamet
thesamet / bay-scala-jobs
Last active June 29, 2016 05:23 — forked from ymasory/bay-scala-jobs
Companies hiring Scala developers in the Bay Area.
Companies hiring Scala developers in the Bay Area.
Created in response to a thread on scala-base.
My favorites:
- CloudPhysics
- Wordnik
Unbiased list:
- 10Gen
- Audax Health
@thesamet
thesamet / gist:7419702
Created November 11, 2013 20:22
Filter JS serialization
package controllers
import play.api.libs.json.Json
class Test {
case class Filter(id: Int, table: String, name: String, Type: String, structure: String)
implicit val filterWrites = Json.writes[Filter]