Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
@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

@cb372
cb372 / ApacheCommonExec.java
Created March 28, 2012 07:37 — forked from sakamotodesu/ApacheCommonExec.java
apache commons exec "write end dead" sample
package com.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
@cb372
cb372 / hide-promoted-tweets.user.js
Created March 24, 2012 08:06
A simple userscript to hide promoted tweets on twitter.com
// ==UserScript==
// @match http://twitter.com/*
// @match https://twitter.com/*
// ==/UserScript==
elems = document.getElementsByClassName('tweet')
for (var i=0; i<elems.length; i++) {
e = elems[i];
if (e.nodeName.toLowerCase() == 'div' &&
e.attributes['data-promoted'] &&
e.attributes['data-promoted'].value == "true") {
@cb372
cb372 / MyTest.java
Created February 23, 2012 00:49
Maven + JUnit example
// put this file in src/test/java/foo/
package foo;
import org.junit.Test;
import org.junit.Assert;
import static org.junit.Assert.assertTrue;
public class MyTest {
@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: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: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)
[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 / 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)
@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
}