This file contains 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
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 |
This file contains 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
/* | |
* 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 | |
} |
This file contains 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
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) |
This file contains 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
[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 |
This file contains 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> 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) |
This file contains 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
[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. | |
This file contains 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
[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/ |
This file contains 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
// 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 { |
This file contains 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
// ==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") { |
This file contains 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
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; |
OlderNewer