Skip to content

Instantly share code, notes, and snippets.

View mtranter's full-sized avatar

Mark Tranter mtranter

View GitHub Profile
@mtranter
mtranter / deepAssign.js
Created April 4, 2018 05:52
Like Object.assign. But deep.
const deepAssign = (target, ...sources) =>
sources.reduce((total, src) =>
Object.keys(src).reduce((agg, n) =>
Object.assign({}, agg, {
[n]: (
typeof src[n] === "object" ?
deepAssign(target[n] || {}, src[n]) :
src[n]
)
}),
@mtranter
mtranter / Streams.scala
Created March 5, 2018 03:51
Kafka Streams Scala Stack Overflow Issue
package com.recursion
import com.lightbend.kafka.scala.streams.StreamsBuilderS
import org.apache.kafka.streams.kstream.Materialized
object Streams {
def build() = {
val sb = new StreamsBuilderS()
sb.table[String, String]("topic").filter((k,v) => v.length > 0, Materialized.as("STACKOVERFLOW"))
sb
@mtranter
mtranter / demo.scala
Created December 4, 2017 21:14
Scala Type Safe Configuration with Type Level Programming
import SharedStreamsCfg._
object SharedStreamsCfg {
abstract class HasConfig
case object Y extends HasConfig
case object N extends HasConfig
type Loaded = Y.type
type NotLoaded = N.type
def apply()= new SharedStreamsCfg[NotLoaded, NotLoaded, NotLoaded] ("", 0,0)
@mtranter
mtranter / DefaultFor.scala
Last active November 19, 2017 21:15
Generate Default Case Class instances with HLists
package com.trizzle
import java.util.UUID
import shapeless.{::, Generic, HList, HNil, Lazy}
trait DefaultFor[T] {
val default: T
}
package org.trizzle.kafka
import java.io.{ByteArrayOutputStream, DataOutputStream}
import java.util
import com.sksamuel.avro4s._
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient
import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer}
var boolExprMap = {
$and: function(a,b){ return a && b} ,
$or: function(a,b){ return a || b; }
}
var TreeNode = function(op,def){
op = (op || '$and').toLowerCase();
this.op = boolExprMap[op];
def = def || (op === '$and')
this.fns = [new LeafNode(function(){return def;})];
@mtranter
mtranter / AvroDeserializationSchema.java
Created July 25, 2016 19:06
Avro deserializer for Flink's Data Stream API Kafka Source
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.reflect.ReflectDatumReader;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.java.typeutils.TypeExtractor;
public class AvroDeserializationSchema<T> implements DeserializationSchema<T> {
@mtranter
mtranter / PimpedEtcdClient.scala
Last active February 27, 2016 17:52
Save and get Json from ETCD instance
package com.trizzle.etcd
import net.nikore.etcd.EtcdClient
import net.nikore.etcd.EtcdJsonProtocol.EtcdResponse
import spray.json._
import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
import scala.reflect.Manifest
import scala.util.{Failure, Try, Success}
/*
* ng-currency
* http://alaguirre.com/
* Version: 0.7.14 - 2015-04-14
* License: MIT
*/
angular.module('ng-currency', [])
.directive('ngCurrency', ['$filter', '$locale', function ($filter, $locale) {
return {
@mtranter
mtranter / gist:68db17c0fe777a080ea3
Last active August 29, 2015 14:09
Possible New Cypher API
class Test
{
static void Main()
{
IStartClause<Person> startClause = null;
startClause
.Start(ctx => ctx.AtAnyNode(p => p))
.Match(ctx => ctx.Node(p => p).Relates("has_job").To(p => p.Job))
.Where(p => p.Name == "Mark" && p.Job.Name == "MGND")