Skip to content

Instantly share code, notes, and snippets.

View tovbinm's full-sized avatar
⌨️
<typing sounds>

Matthew Tovbin tovbinm

⌨️
<typing sounds>
View GitHub Profile
@tovbinm
tovbinm / git-patch.sh
Created December 20, 2017 04:25
Apply git patch safely with rejects
git format-patch HEAD~X --stdout > patch
git apply --stat patch
git apply --reject --whitespace=fix patch
@tovbinm
tovbinm / udfs.scala
Last active June 29, 2017 21:33
Codegen dies (Spark 2.0.2 and 2.1.1) - no udf nesting
import spark.implicits._
import org.apache.spark.sql.functions.udf
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import org.apache.spark.sql.execution.debug._
val u = udf((a: Int) => a)
val df = spark.sparkContext.parallelize(Seq(0)).toDF("0")
val res = (1 until 20).foldLeft(df) { case (d, i) =>
package rs
import scala.language.higherKinds
import matryoshka.data._
import matryoshka.implicits._
import scalaz._, Scalaz._
trait Expr[A]
case class NumLit[A](value: Int) extends Expr[A]
@tovbinm
tovbinm / Id64.scala
Last active January 20, 2017 09:55
64 bit unique id generator
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
/**
* 64 bit unique id generator
* Features:
* 1. generate ascending or descending ids
* 2. 64 bit id consists of:
@tovbinm
tovbinm / 01-iptables.config
Created July 22, 2016 18:03
Piercing IPTables for Akka Cluster on AWS Beanstalk with ebextensions
files:
"/etc/init/eb-docker-iptables.conf":
mode: "000644"
content: |
description "Elastic Beanstalk Default Docker Container Iptables"
author "Matthew Tovbin <mtovbin@salesforce.com>"
start on started docker
stop on stopping docker
@tovbinm
tovbinm / build.gradle
Last active April 27, 2016 17:15
Scala repl with Gradle
task classpath << {
description 'Print project classpath.'
println sourceSets.main.runtimeClasspath.asPath
}
@tovbinm
tovbinm / gist:4220948
Created December 6, 2012 00:49
Setup Amazon CloudWatch for Debian
1. Install all the required libraries:
sudo apt-get update && sudo apt-get -y install \
unzip \
perl \
wget \
curl \
make \
ncftp \
liburi-perl \
@tovbinm
tovbinm / waves.js
Created January 26, 2014 05:24
Breaking waves sound (Open (http://myjavatools.com/js.html) in Chrome paste the code and hit run)
var AMP = 0.5; // amplitude
var len = 15; // seconds
e = new webkitAudioContext();
var source = e.createBufferSource();
var SR = e.sampleRate;
source.buffer = e.createBuffer(1, len * SR, SR);
var dat = source.buffer.getChannelData(0);
for (var i = 0; i < len * SR; i++) {
dat[i] = AMP * (Math.random() * 2 - 1);
}
@tovbinm
tovbinm / Build.scala
Created January 21, 2014 00:49
Kafka 0.8.0 with Zookeeper 3.4.5
<dependency org="org.apache.zookeeper" name="zookeeper" rev="3.4.5">
<exclude org="log4j" module="log4j"/>
<exclude org="org.slf4j" module="slf4j-log4j12"/>
<exclude org="jline" module="jline"/>
</dependency>
@tovbinm
tovbinm / ch5_streams.scala
Last active December 26, 2015 13:59
Reading Functional Programing In Scala
// Excercies from chapter 5: Strictness and laziness
def foldRight[A,B](z: => B)(s: Stream[A])(f: (A, => B) => B): B =
s match {
case hd #:: tail => f(hd, foldRight(z)(tail)(f))
case _ => z
}
def exists[A](s: Stream[A])(p: A => Boolean): Boolean =
foldRight(false)(s)((x,a) => if (p(x)) true else a)