Skip to content

Instantly share code, notes, and snippets.

View JohnMurray's full-sized avatar

John Murray JohnMurray

View GitHub Profile
package trees
object Main extends App {
trait Node
case class InnerTreeNode ( left:Node, right:Node, value:Int ) extends Node
case object StopNode extends Node
def leaf(x: Int): Node = InnerTreeNode(StopNode, StopNode, x)
@JohnMurray
JohnMurray / Build.scala
Created November 19, 2015 16:42
AutoPlugin not overriding
import sbt._
import sbt.Keys._
object MyPlugin extends AutoPlugin {
override lazy val projectSettings: Seq[Setting[_]] = Seq(
resourceDirectory in Compile := file("/tmp")
)
}
object MyBuild extends Build {
@JohnMurray
JohnMurray / silly-use-of-threads.java
Created March 17, 2016 00:14
Silly Java Threads Question - MOAR THREADS!!!!
for (int i = 0; i < 10_000; i++) {
Thread t = new Thread(() -> System.out.println("doing something"));
t.start();
t.join();
}
// Eventually throws java.lang.OutOfMemoryError: unable to create new native thread
extern crate iron;
extern crate mysql;
use iron::prelude::*;
use iron::status;
use iron::{Handler};
struct Router {
routes: HashMap<String, Box<Handler>>
}
@JohnMurray
JohnMurray / Mail.scala
Created February 7, 2017 17:35 — forked from mariussoutier/Mail.scala
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@JohnMurray
JohnMurray / install-go.md
Created August 10, 2017 19:44
Instructions for setting up GoLang locally

Installing Go

Installation

Change Directory

cd ${HOME}

Install a binary distribution

@JohnMurray
JohnMurray / challenge-1.md
Last active August 16, 2017 07:41
Challenge 1 of go lunch-and-learn

Ping Pong

A big reason people love Go is the concurrency primitives. Let's try them out with a coding challenge.

Goal

Launch 2 go-routines that send messages to each other over a channel. One go-routine will send "Ping" and the other will send "Pong." Each go-routine can only respond after they've received a message from the other go-routine. The exception is that the go-routine sending "Ping" can send an initial message

@JohnMurray
JohnMurray / challenge-2.md
Created August 10, 2017 21:28
Challenge 2 of Go lunch-and-learn

Web Server

Another strong component of Go is the standard library. It is structured much like the Unix/Linux operating system. There are lots of small components that can be combined together for more complex tasks. There are also indespensible, modern primitives such as the ability to create a networking server.

Goal

Create a web-server that exposes a typical AppNexus "status" endpoint. The web-server will support

#include <google/protobuf/arena.h>
using namespace google::protobuf;
void main() {
Arena arena;
auto msg = Arena::CreateMessage<MyProto>(&arena);
setup_myproto(msg);
push_to_queue(msg);
}
#include <google/protobuf/arena.h>
using namespace google::protobuf;
void main() {
Arena arena;
auto msg = Arena::CreateMessage<MyProto>(&arena);
setup_myproto(msg, 1);
push_to_queue(msg);