Skip to content

Instantly share code, notes, and snippets.

View djspiewak's full-sized avatar

Daniel Spiewak djspiewak

View GitHub Profile
/* I'm trying to refactor $and and $or (which are essentially the same code returning a different outer query).
The problem is that currently only "String, Any" pairs work, and I need to be able to combine both those *AND* "Query Expression Objects".
Here's the $or spec right now
*/
"Casbah's DSL $or Operator" should {
"Accept multiple values" in {
val or = $or("foo" -> "bar", "x" -> "y")
import Data.List
import Data.Maybe
import Control.Monad
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
base = length alphabet
encode :: Int -> String
encode 0 = "a"
encode id = map $ ((!!) alphabet) (reverse . tail) (map snd options)
class TestSpec extends org.specs2.mutable.Specification {
sequential // this causes the printing to break
"many tests" should {
(1 to 1000).foreach { i =>
"example "+i >> {
("example "+i).pp
Thread.sleep((math.random*100).toLong)
ok
}
@djspiewak
djspiewak / Main.java
Created November 10, 2020 22:00 — forked from RaasAhsan/Main.java
minimized ARM memory barrier violation
import java.util.concurrent.atomic.*;
import java.util.concurrent.*;
public class Main {
private static ExecutorService executor = Executors.newFixedThreadPool(2);
private static int iterations = 10000000;
public static class Runner {
// writes to canceled happen before a CAS on suspended
// reads on canceled happen after a CAS on suspended