Stone Gao stonegao

View Main.scala
1 2 3 4 5 6 7 8 9 10
import scala.slick.session.Database
import scala.slick.driver.H2Driver.simple._
 
 
case class Club(name: String, id: Option[Long] = None)
 
case class Student(name: String, classroom: String, clubId: Option[Long], id: Option[Long] = None)
 
 
trait DAO {
View ssh.rb
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env ruby
 
# Inspired by http://jeffmiller.github.com/2011/01/10/ssh-host-color
 
# == What this version does:
# 1) Launch an SSH process
# 2) Grab the IP that SSH connected to
# 3) Hash that IP and generate a colour from it
# 4) Change Terminal.app's background colour to that colour.
# 5) Change the colour back when SSH exits.
View set_iTerm_background.sh
1 2 3 4 5 6 7 8 9 10
#!/usr/local/bin/bash
 
set_term_bgcolor(){
local R=$1
local G=$2
local B=$3
/usr/bin/osascript <<EOF
tell application "iTerm"
tell the current terminal
tell the current session
View gist:5661072

Context: I was asked for a list of interesting reading relating to "distributed databases, behavior under partitions and failures, failure detection." Here's what I came up with in about an hour.

For textbooks, "Introduction to Reliable and Secure Distributed Programming" is a superb introduction to distributed computing from a formal perspective; it's really not about "programming" or "engineering" but about distributed system fundamentals like consensus, distributed registers, and broadcast. Used in Berkeley's Distributed Computing course (and HT to @lalithsuresh) Book Site

Notes from courses like Lorenzo Alvisi's Distributed Computing class can be great.

There are a bunch of classics on causality, [Paxos](ht

View DuplicateRequestFilter.scala
1 2 3 4 5 6 7 8 9 10
package com.tumblr.fibr.service.filter
 
import com.tumblr.fibr.config.FilterConfig
import com.tumblr.fibr.tsdb.{TsdbRequest, TsdbResponse}
import com.google.common.cache.{Cache, CacheBuilder}
import com.twitter.finagle.Service
import com.twitter.util.Future
import java.util.concurrent.{Callable, TimeUnit}
 
/**
View raskell.rb
1 2 3 4 5 6 7 8 9 10
$stack, $draws = [], {}
 
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
 
class Array
def +@
View yuml.md
View examples.scala
1 2 3 4 5 6 7 8 9 10
import Pattern._
import Family._
 
def pattern[B](pf: PartialFunction[Name,B]) = new Extractor(pf.lift)
 
val Parents = new Extractor(parents.get)
val Children = new Extractor(children.get)
 
"Julie" match {
case Parents(p) => "Julies parents are: " + p
View zwtfpd.c
1 2 3 4 5 6 7 8 9 10
// Minimal WTFP server in 0MQ
#include "czmq.h"
 
static void *
wtfp_server (void *args)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);
View EncryptionUtil.java
1 2 3 4 5 6 7 8 9 10
package lv.org.substance.crypt
 
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
 
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
Something went wrong with that request. Please try again.