This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // `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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import socket | |
| from datetime import datetime | |
| import csv | |
| import sys | |
| import pickle | |
| import struct | |
| import threading | |
| import urllib2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scala> :javap MongoDB | |
| public class MongoDB$ extends java.lang.Object { | |
| public static final MongoDB$ MODULE$; // actual instance of our `object` | |
| public static {}; | |
| public MongoDB$(); | |
| // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 ;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| */ |