Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
🏕️
Just gopher it

Doug Tangren softprops

🏕️
Just gopher it
View GitHub Profile
import scala.language.implicitConversions
class Mult[A, B] {
def commute: Mult[B, A] = new Mult[B, A]
def associate[C, D](implicit ev: B =:= Mult[C, D]): Mult[Mult[A, C], D] = new Mult[Mult[A, C], D]
}
object Simplify {
implicit def commute[A, B, M <% Mult[A, B]](m: M): Mult[B, A] = m.commute
implicit def associate[A, B, C, M <% Mult[A, Mult[B, C]]](m: M): Mult[Mult[A, B], C] = m.associate
@SethTisue
SethTisue / gist:8977033
Last active November 27, 2018 21:16
Example of `lazy val` inside `implicit class`
// `lazy val` inside `implicit class`
implicit class RichStream[T](s: Stream[T]) {
lazy val circular: Stream[T] =
s #::: circular
}
// in order to make this work with `extends AnyVal`, you have to make the
// lazy val local, as follows:
@agleyzer
agleyzer / akamai2graphite.py
Created January 29, 2014 21:30
Bulk loader for Akamai traffic reports CSV to Graphite
#!/usr/bin/env python
import socket
from datetime import datetime
import csv
import sys
import pickle
import struct
import threading
import urllib2
import shapeless._
import record._
import syntax.singleton._
object ScaldingPoC extends App {
// map, flatMap
val birds =
List(
"name" ->> "Swallow (European, unladen)" :: "speed" ->> 23 :: "weightLb" ->> 0.2 :: "heightFt" ->> 0.65 :: HNil,
scala> :javap MongoDB
public class MongoDB$ extends java.lang.Object {
public static final MongoDB$ MODULE$; // actual instance of our `object`
public static {};
public MongoDB$();
// ...
}
There are five nodes, using master-slave replication. When we start A is the master.
The nodes are capable of synchronous replication, when a client writes,
it gets as relpy the number or replicas that received the write. A client
can consider a write accepted only when "3" or more is returned, otherwise
the result is not determined (false negatives are possbile).
Every node has a serial number, called the replication offset. It is always
incremented as the replication stream is processed by a replica. Replicas
are capable of telling an external entity, called "the controller", what
@bdd
bdd / gcb
Last active December 29, 2015 07:29 — forked from evnm/gcb
a shorter, faster and a bit more helpful version of gcb.sh
#! /bin/sh
match=`git rev-parse --abbrev-ref --branches="*$1*"`
case `wc -w <<< "$match" | tr -d ' '` in
"0") echo "error: '$1' did not match any branch." 2>&1 ;;
"1") git checkout $match ;;
*) echo "error: '$1' is ambigious among:\n$match" 2>&1
esac
#!/bin/bash
set -o errexit -o nounset -o pipefail
function -h {
cat <<USAGE
USAGE: ln_libjvm.bash
Symlink a likely libjvm.so into /usr/bin.
USAGE
}; function --help { -h ;}
@nuxlli
nuxlli / unix_socket_request.sh
Last active January 25, 2024 04:37
Examples of http request in unix domain socket with shell, using socat, netcat or curl
#!/bin/bash
# References
# http://www.computerhope.com/unix/nc.htm#03
# https://github.com/daniloegea/netcat
# http://unix.stackexchange.com/questions/26715/how-can-i-communicate-with-a-unix-domain-socket-via-the-shell-on-debian-squeeze
# http://unix.stackexchange.com/questions/33924/write-inside-a-socket-open-by-another-process-in-linux/33982#33982
# http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
# http://www.dest-unreach.org/socat/
# http://stuff.mit.edu/afs/sipb/machine/penguin-lust/src/socat-1.7.1.2/EXAMPLES
@ryanlecompte
ryanlecompte / gist:7287415
Last active December 27, 2015 07:18
Immutable PrefixMap
import scala.collection.generic.CanBuildFrom
import scala.collection.immutable.MapLike
import scala.collection.mutable
/**
* Immutable version of the PrefixMap demonstrated in the Scala collections
* guide here: http://www.scala-lang.org/docu/files/collections-api/collections-impl_6.html
*
* This version also has a smarter remove method (doesn't leave behind dead nodes with empty values)
*/