Skip to content

Instantly share code, notes, and snippets.

@timcharper
timcharper / README.md
Last active January 15, 2025 12:45
Macvlan using systemd

Before

yum install -y systemd-networkd
modprobe macvlan # make sure this returns no errors

Put config files in place

eth0.network and mac0.{netdev,network} go in /etc/systemd/network/

package m
import akka.stream.scaladsl._
import akka.stream._
import akka.actor._
import akka.stream.stage._
import scala.collection.mutable
trait IngestionMethods[A] {
def submit(value: A): Unit
@timcharper
timcharper / Main.scala
Last active April 29, 2016 23:08
Demonstrate issue with gracefully stopping actorRef Source
package m
import akka.stream.scaladsl._
import akka.stream._
import akka.actor._
object Main extends App {
implicit val system = ActorSystem("hi")
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
package m
import akka.stream.scaladsl._
import akka.stream._
import akka.actor._
object Main extends App {
implicit val system = ActorSystem("hi")
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
@timcharper
timcharper / toggle-test.el
Created April 19, 2016 16:42
the functions are specific for scala... but this is general enough to work for anything
(defvar scala-test:main-file-format
"%s/src/main/scala/%s%s.scala"
"scala test format")
(defvar scala-test:test-file-format
"%s/src/test/scala/%s%sSpec.scala"
"scala test format")
;; (setq scala-test:main-file-format "%s/src/main/scala/%s%s.scala")
;; (setq scala-test:test-file-format "%s/src/test/scala/%sTest%s.scala")
@timcharper
timcharper / generic_unmarshalling.scala
Created February 21, 2016 18:28
generic unmarshalling implementation
import scala.language.higherKinds
implicit class FlowUnmarshalling[I[P1, P2] <: FlowOps[P1, P2], M](val f: I[HttpResponse, M]) {
// Throws IOException on error
def unmarshallSuccess[T](implicit um: Unmarshaller[HttpEntity, T], ec: ExecutionContext, m: Materializer): I[HttpResponse, M]#Repr[T] = {
f.mapAsync(1) { response =>
if (response.status.isSuccess)
um(response.entity)
else
throw new IOException("invalid status code: "+ response.status)
}
@timcharper
timcharper / Makefile
Created September 20, 2015 21:33
multirust source downloader
# Save this file to ~/.multirust/Makefile
# to run, cd ~/.multirust; make toolchains/1.3.0/src
.PHONY: clean
rust.git:
git clone https://github.com/rust-lang/rust.git --bare
toolchains/nightly/src: toolchains/master/src
ln -sf $$(pwd)/toolchains/master/src $$(pwd)/$@
protected [helpers] val singleSession = databaseConnection.createSession
val noDataSource = new JdbcDataSource {
def createConnection(): Connection = throw new RuntimeException("Tried to allocate another connection in test mode. This is an issue because the test database assumes that only one database connection in used. RolledbackDatabase needs to be improved.")
def close(): Unit = ()
}
// backend.BaseSession
class DelegatingSession(session: backend.SessionDef) extends backend.SessionDef {
override def database = session.database
package m
import shapeless.HMap
object leData {
object Name
object Age
object Address
object Street
// psuedo-code; will not actually compile
import com.spingo.op_rabbit.Json4sSupport._ // allows you to use Json4s directly to serialize / deserialize published messages
trait MarketOrEv
case class Market(mkt_id: Int, ev_id: Int, model_type:”Market”) extends MarketOrEv
case class Ev(ev_id: Int, model_type:”Ev”) extends MarketOrEv