Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
@cb372
cb372 / Bar.scala
Created August 26, 2015 15:09
Example Thrift model and Scrooge-generated code
/**
* Generated by Scrooge
* version: 3.16.3
* rev: b8593c83072d94fc44feaa8d97940b9266d84ed0
* built at: 20140806-054445
*/
package com.mycorp
import com.twitter.scrooge.{
TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftStructFieldInfo, ThriftUtil}
@cb372
cb372 / example-hydra-job.json
Created February 17, 2014 07:50
Example Hydra job configuration file
{
type : "map",
source: {
type:"mesh2",
hash:true,
mesh: {
files:["hydra-input/*"]
},
format:{
type:"column",
@cb372
cb372 / ScalaCacheMemcachedSample.scala
Created April 23, 2014 01:35
Simple examples of using ScalaCache in a webapp, using Memcached for caching
package sample
import scalacache._
import memoization._
import memcached._
import scala.concurrent.duration._
import scala.language.postfixOps
case class User(id: Int, name: String)
@cb372
cb372 / burned-in-subs.sh
Created May 3, 2014 13:22
Adding burned-in Japanese subs with mencoder
#!/bin/sh
if [ $* -n 3 ]; then
echo "Usage: $(basename $0) subs.srt in.avi out.avi"
exit 1
fi
mencoder -oac copy -ovc lavc -sub "$1" -utf8 -subfont-text-scale 3.3 -subpos 96 "$2" -o "$3"
@cb372
cb372 / bf.lol
Created May 6, 2014 03:01
Brainf*ck interpreter in LOLCODE
HAI
BTW BrainFuck interpreter in LOLCODE by Chris Birchall
I HAS A MEMORY BTW array of size 30,000
I HAS A POINTER
POINTER R 0
I HAS A BRACKETS BTW array mapping opening and closing brackets
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
AWSUM THX
IM IN YR BRACKETSLOOP
@cb372
cb372 / repl.scala
Created May 21, 2014 23:19
Case class WTF
// case class Tweet(userId: Long, country: String, firstName: String, secondName: String)
res57: Seq[Tweet] = ArrayBuffer(Tweet(625052628,United States,matt,todorowski), Tweet(625052628,United States,matt,todorowski))
scala> res57(0).id == res57(1).id
res59: Boolean = true
scala> res57(0).country == res57(1).country
res60: Boolean = true
@cb372
cb372 / gist:15053455fbf9700bd576
Last active August 29, 2015 14:06
String concatenation is done very early
String concatenation happens before the tree is passed to your macro,
so you get passed a Literal(Constant("ab"))
scala> reify(() => "a" + "b")
res14: res0.universe.Expr[() => String] = Expr[() => java.lang.String]((() => "ab"))
This is not the case with other String ops.
I guess + is special because it's a Java operator, not a method on StringLike.
@cb372
cb372 / gist:8afd80a63f224595c943
Created October 3, 2014 08:49
Java 8 comes with a JavaScript REPL
$ $JAVA_HOME/bin/jjs
jjs> print([] + {});
[object Object]
jjs> print("WAT");
WAT
jjs>
@cb372
cb372 / Attempts.scala
Last active August 29, 2015 14:22 — forked from jroper/Attempts.scala
import scalaz.Reader
case class User(id: Int, name: String)
case class Interest(name: String)
trait Database
trait Attempt1 {
// How every explanation of Reader monad I've seen/read goes:
@cb372
cb372 / Hello.scala
Last active August 29, 2015 14:24
Timing scalac phases
import scala.annotation.tailrec
class Hello {
val foo = "abc"
def bar(a: String) = foo + a
def fib(n: Int) = {
@tailrec