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
public class Volatile { | |
private static boolean ready; | |
private static int number; | |
public static class ReaderThread extends Thread { | |
public void run() { | |
while(!ready) | |
{ | |
Thread.yield(); | |
} |
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
(define (stream-maker seed fx) | |
(letrec ([f (lambda(x) (cons x (lambda () (fx x))))]) | |
(lambda () (f seed)))) | |
(define naturals (stream-maker 1 (lambda (x) (+ x 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
def gather_futures[A](xs: Seq[Future[A]]): Future[Seq[A]]= { | |
def combine[A,B,C](f1: Future[A], f2: Future[B])(f: (A,B) => C): Future[C] ={ | |
for(a <- f1; b <- f2) | |
yield f(a,b) | |
} | |
xs.foldLeft(Future{Seq[A]()}){(acc: Future[Seq[A]],x: Future[A]) => combine(x,acc)((a: A,b: Seq[A]) => b ++ Seq(a))} | |
} |
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
fun count_and_sort [] = ([],0) | |
| count_and_sort [x] = ([x],0) | |
| count_and_sort xs = | |
let | |
fun count_and_sort_split_inversions([],ys,acc,sum) = (List.rev(acc) @ ys,sum) | |
| count_and_sort_split_inversions(xs,[],acc,sum) = (List.rev(acc) @ xs,sum) | |
| count_and_sort_split_inversions(x :: xs, y :: ys,acc,sum) = | |
if x < y | |
then count_and_sort_split_inversions(xs, y :: ys, x :: acc, sum) | |
else count_and_sort_split_inversions(x :: xs, ys, y :: acc, sum + List.length(x :: xs)) |
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 from(n: Int): Stream[Int] = n #:: from(n+1) | |
def sieve(nums: Stream[Int]): Stream[Int] = nums.head #:: sieve(nums.tail.filterNot(_ % nums.head == 0)) | |
def primes: Stream[Int] = sieve(from(2)) |
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
val r = new scala.util.Random() | |
val data = List.fill(10)(r.nextInt(100)) | |
def msort(data: List[Int]): List[Int] = { | |
def merge(xs: List[Int], ys: List[Int]): List[Int] = (xs, ys) match { | |
case (List(), _) => ys | |
case (_, List()) => xs | |
case (x :: xs1, y :: ys1) => if (x < y) x :: merge(xs1, ys) else y :: merge(xs, ys1) | |
} |
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
val r = new scala.util.Random() | |
val data = List.fill(10)(r.nextInt(100)) | |
def isort(xs: List[Int]): List[Int] = { | |
def insert(x: Int, xs: List[Int]): List[Int] = xs match { | |
case List() => List(x) | |
case y :: ys => if (x < y) x :: y :: ys else y :: insert(x, ys) | |
} |
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
here is the full compile log: http://gist.github.com/266605 | |
the relevant part is: | |
`check/crc32_x86.S:96:suffix or operands invalid for 'push' | |
check/crc32_x86.S:97:suffix or operands invalid for 'push' | |
check/crc32_x86.S:98:suffix or operands invalid for 'push' | |
check/crc32_x86.S:99:suffix or operands invalid for 'push' | |
check/crc32_x86.S:265:suffix or operands invalid for 'pop' | |
check/crc32_x86.S:266:suffix or operands invalid for 'pop' |
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
$ brew install xz | |
==> Downloading http://tukaani.org/xz/xz-4.999.9beta.tar.bz2 | |
######################################################################## 100.0% | |
==> ./configure --prefix=/usr/local/Cellar/xz/4.999.9beta --disable-debug --disa | |
==> make install | |
Making install in src | |
Making install in liblzma | |
Making install in api | |
make[4]: Nothing to be done for `install-exec-am'. | |
test -z "/usr/local/Cellar/xz/4.999.9beta/include" || ../../../build-aux/install-sh -c -d "/usr/local/Cellar/xz/4.999.9beta/include" |
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
// no external dependencies, just :paste the entire gist into a scala 2.11 repl | |
// scala> import State._ | |
// scala> StackExample.computed.run(List.empty) | |
// #result of push(1), push(2), push(3), pop() | |
// res0: (List[Int], Option[Int]) = (List(2, 1),Some(3)) | |
// #naive fibonacci impl | |
// scala> time(FibExample.fib(42)) | |
// took 1204 ms |
NewerOlder