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
import java.util.concurrent.ConcurrentLinkedQueue | |
import scala.annotation.tailrec | |
import scala.concurrent.{ExecutionContext, Future, Promise} | |
implicit val ec = ExecutionContext.global | |
val data = Map( | |
"getBff 1" -> 3, | |
"getBff 2" -> 4, | |
"getFN 1" -> "Harry", | |
"getFN 2" -> "Biff", |
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
; list of winning positions | |
(def wp | |
[2r111000000 2r000111000 2r000000111 2r100100100 2r010010010 2r001001001 2r100010001 2r001010100]) | |
;; Is a particular bitmask winning? | |
(defn winner? [p] | |
(some (fn [c] (= (bit-and c p) c)) wp)) | |
;; list of possible moves, filtering out ones already made | |
(defn moves [p] | |
(filter pos? (map #(bit-and (bit-not p) (bit-shift-left 1%)) (range 9)))) | |
;; A board position comprises a bitarray for each player and an indicaiton of whose turn it is. |
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
trait ViewTransformer[-A,+B] { | |
def sequence(in: Iterable[A]) = transform(in.view).to(IterableFactory.toSpecific(in.iterableFactory)) | |
def transform(v: View[A]): View[B] | |
def map[C](f: B => C): ViewTransformer[A,C] = new ViewTransformerImpl[A,C,B](this) { | |
override def transform(v: View[A]): View[C] = prev.transform(v).map(f) | |
} | |
def flatMap[C](f: B => IterableOnce[C]): ViewTransformer[A,C] = new ViewTransformerImpl[A,C,B](this) { | |
override def transform(v: View[A]): View[C] = prev.transform(v).flatMap(f) | |
} | |
} |
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
{-# LANGUAGE RankNTypes #-} | |
import Data.STRef | |
import Data.Vector (fromList, toList, freeze, thaw) | |
import Control.Monad | |
import Data.Vector.Mutable (MVector, STVector, read, write, swap) | |
import qualified Data.Vector as V (Vector, length) | |
import Data.List (sortOn) | |
import Prelude hiding (read) | |
import GHC.ST |
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
(ns qaxl.core | |
(:use clojure.walk clojure.pprint qaxl.cache) | |
(:require [co.paralleluniverse.pulsar.async :as qa] | |
[clojure.core.async :as a] | |
[co.paralleluniverse.pulsar.core :as q] | |
[clojure.test :refer [function?]] | |
[co.paralleluniverse.fiber.httpkit.client :as hk] | |
[co.paralleluniverse.pulsar.core :refer [fiber]] | |
[clojure.core.match :refer [match]])) |
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
;; La bella vita di quattro finestre | |
(global-set-key "\C-col" 'windmove-left) | |
(global-set-key "\C-cor" 'windmove-right) | |
(global-set-key "\C-cou" 'windmove-up) | |
(global-set-key "\C-cod" 'windmove-down) | |
(global-set-key "\C-cow" 'ido-jump-to-window) | |
(defun windmove-opposite () (interactive) | |
(if (windmove-find-other-window 'up) (windmove-up) (windmove-down)) | |
(if (windmove-find-other-window 'right) (windmove-right)(windmove-left))) | |
(global-set-key "\C-coo" 'windmove-opposite) |
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
die "Note that there are two different algorithms here. Don't expect it to run as is." | |
#!/usr/bin/perl | |
# ~0.15s on i7 1.7GHz | |
my @all; | |
my $m=0; | |
while(<>) { | |
$l = length($_); | |
$m = $l if $l>$m; |
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
(defn maintain-non-primes [non-primes] | |
"Remove first non-prime entry, and create new entries based on it" | |
(let [[n ps] (first non-primes) | |
xs (dissoc non-primes n) | |
new-non-primes (map (fn [p] [(+ n p) (cons p (xs (+ n p))) ]) ps)] | |
(into xs new-non-primes))) | |
(defn seive | |
([] (seive (sorted-map) 2)) | |
([n] (take n (seive (sorted-map) 2))) | |
([non-primes n] |
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
#!/usr/bin/env python | |
from math import * | |
import sys | |
# draw line from x,y of length s at angle theta, spawn growth of length s*r, theta+/-q unless n==0 | |
def grow(x, y, theta, s, q, r, n): | |
ret = [(x,y,theta,s)] | |
n = n-1 | |
if n>0: | |
x2 = x + s*cos(theta) |
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
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> implicit def strToInt(x:String) = x.toInt | |
warning: there were 1 feature warning(s); re-run with -feature for details | |
strToInt: (x: String)Int | |
scala> class C[A](v:A){def a(implicit ev:A=>Int)=123+ev(v)} | |
defined class C |
NewerOlder