Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
[chris@ChracBookAir 1074 ~/tmp]
: cd foo
cd: no such file or directory: foo
[chris@ChracBookAir 1075 ~/tmp]
: fuck
mkdir -p foo && cd foo
[chris@ChracBookAir 1076 ~/tmp/foo]
:
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_40).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
// Nameable is now a typeclass, not an interface
trait Nameable[P] {
def getName(p: P): String
@cb372
cb372 / fizzbuzz.scala
Created July 12, 2011 11:58
FizzBuzz code golf for Shibuya Scala meeting no 42 (http://atnd.org/events/17769)
for(i<-1 to 100){var m=0;if(i%3==0){m=1;print("Fizz")};if(i%5==0){m=1;print("Buzz")};if(m<1)print(i);println} // 110
@cb372
cb372 / codejam-small.scala
Created October 20, 2011 04:07
CodeJam 問題C. ビット数 first attempt
/*
* Ridiculous bit counting algorithm
* http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
*/
def f(x:Int):Int = {
var v = x - ((x >> 1) & 0x55555555)
v = (v & 0x33333333) + ((v >> 2) & 0x33333333)
(((v + (v >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24
}
@cb372
cb372 / codejam-large.scala
Created October 23, 2011 05:27
CodeJam 問題C. ビット数 second attempt
def calcAandB(N:BigInt):(BigInt,BigInt) = {
def setIth(i: Int, a:BigInt, b:BigInt, carry:Boolean):(BigInt, BigInt, Boolean) =
(N.bitLength-i, carry) match {
case (n,_) if n<1 => (a,b,carry) // finished all bits of N
case (1,true) => (a,b,carry) // finished all bit of N except msb, and there is no carry
case (n,_) => { // recurse
// handle the carry
val (n_i, c) = (N.testBit(i), carry) match {
case (true, true) => (false, false)
case (false, true) => (true, true)
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.0.r26005-b20111114020239 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val a = 1
missing argument
bad option: '-bootclasspath'
a: Int = 1
@cb372
cb372 / gist:1778448
Created February 9, 2012 08:27
Time until the musical kills Andy :(
scala> def step(an: Int, xn: Double): Stream[(Int, Double)] = Stream.cons((an, xn), step(an + 1, xn - (0.2 * 365)))
step: (an: Int, xn: Double)Stream[(Int, Double)]
scala> val ageNow = 28
ageNow: Int = 28
scala> val lifeExpectancy = 80
lifeExpectancy: Int = 80
scala> val marchOfTime = step(ageNow * 365, lifeExpectancy * 365)
@cb372
cb372 / gist:1872753
Created February 21, 2012 01:16
Scoobi sbt compile OOM error
[chris@birchall-work 1250 ~/code/mapreduce-sandbox]
: git clone https://github.com/NICTA/scoobi.git
Initialized empty Git repository in /home/chris/code/mapreduce-sandbox/scoobi/.git/
remote: Counting objects: 3955, done.
remote: Compressing objects: 100% (1840/1840), done.
remote: Total 3955 (delta 1608), reused 3710 (delta 1375)
Receiving objects: 100% (3955/3955), 14.39 MiB | 2.15 MiB/s, done.
Resolving deltas: 100% (1608/1608), done.
@cb372
cb372 / gist:1872775
Created February 21, 2012 01:21
Scoobi sbt compile OOM error - sbt log
[debug]
[debug] Initial source changes:
[debug] removed:Set()
[debug] added: Set(/home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/impl/exec/MscrReducer.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/java/com/nicta/scoobij/DTable.java, /home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/io/InputStore.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/impl/plan/Smart.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/impl/exec/MscrMapper.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/java/com/nicta/scoobij/Ordering.java, /home/chris/code/mapreduce-sandbox/scoobi/src/main/java/com/nicta/scoobij/impl/DGroupedTableImpl.java, /home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/io/Helper.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/scala/com/nicta/scoobi/impl/exec/TaggedMapper.scala, /home/chris/code/mapreduce-sandbox/scoobi/src/main/java/
@cb372
cb372 / gist:2299692
Created April 4, 2012 08:29
Steps to build 64bit native libs for Hadoop 0.23.1

Hadoop 0.23.1 only comes with 32bit libs. Here is how to rebuild them for your platform.

Compile them

  1. Install gcc, autoconf, automake, libtool, zlib-devel packages

  2. Fix pom.xml to avoid classpath error when running javah:

    1. in hadoop-common-project/hadoop-common/pom.xml, find the dependency on hadoop-annotations
  3. change the scope of the dependency from provided to compile