Skip to content

Instantly share code, notes, and snippets.

@stuhood
stuhood / private final vs private[this] vs private
Last active August 29, 2015 13:57
The differences between `private final` and `private[this]` seem to be that: 1) the scala compiler will inline `private final`, 2) the accessor method for the field is generated, but also marked final.
// private[this] val yo = "yo"
$ javap -c -private -classpath . BlahThis
Compiled from "blah.scala"
public class BlahThis {
private final java.lang.String yo;
public java.lang.String toString();
Code:
0: aload_0
1: getfield #14 // Field yo:Ljava/lang/String;
try {
`(╯°□°)╯︵ ┻━┻`
} catch {
`┬─┬ ノ( ゜-゜ノ)`
}
def `┬─┬ ノ( ゜-゜ノ)`: PartialFunction[Throwable,Any] = {
case e => println("caught " + e)
}
@stuhood
stuhood / gist:8425008
Last active January 3, 2016 06:49
A sketch of how you'd implement an IterableStore for Redis, with a *private* Cursor type.
class RedisStore[K,V] extends IterableStore[K,V] {
private type Cursor = ???
private val InitialCursor: Cursor = ???
/** Get the next batch from Redis, and return a new Cursor. */
private def getBatch(cursor: Cursor): Future[(Seq[(K,V)],Cursor)] = ???
private def getAllHelper(cursor: Cursor): Future[Spool[Seq[(K,V)]]] =
getBatch(cursor).map {
case (batch, nextCursor) => batch *:: getAllHelper(nextCursor)
@stuhood
stuhood / StringTest.scala
Last active December 24, 2015 02:59
(pretend this is using caliper) Scala compiler version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL java version "1.7.0_17" Java(TM) SE Runtime Environment (build 1.7.0_17-b02) Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
/**
* $ for i in javabuilder javaformat javaconcat scalaformat scalaconcat scalainterp scalabuilder; do
* $ echo $i; rm -f *.class ; javac *.java && scalac -classpath . *.scala && scala -cp . StringTest $i
* $ done
*
* javabuilder
* Time after for loop 3500
* javaformat
* Time after for loop 85845
* javaconcat
@stuhood
stuhood / assert.java
Created August 23, 2011 22:57
CliTest Assertion
[junit] WARN 15:50:02,614 Generated random token Token(bytes[ce229b8ce46ec77dc8763200c4ac47d6]). Random tokens will result in an unbalanced ring; see http://wiki.apache.org/cassandra/Operations
[junit] ERROR 15:50:03,369 Fatal exception in thread Thread[ScheduledTasks:1,5,main]
[junit] java.lang.AssertionError
[junit] at org.apache.cassandra.service.GCInspector.logGCResults(GCInspector.java:110)
[junit] at org.apache.cassandra.service.GCInspector.access$000(GCInspector.java:41)
[junit] at org.apache.cassandra.service.GCInspector$1.run(GCInspector.java:85)
[junit] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
[junit] at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
[junit] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
[junit] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
@stuhood
stuhood / gist:988452
Created May 24, 2011 09:57
XOR Metric Example
/**
* Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@stuhood
stuhood / gist:988443
Created May 24, 2011 09:51
XOR Metric Example Buckets
Localhost: /68.27.46.62
Random addresses from each bucket:
Peers in bin 1
at 0x6a06d0d8: /46.29.254.230
at 0x6a301c9a: /46.43.50.164
at 0x5b0a180a: /31.17.54.52
at 0x5c277b3d: /24.60.85.3
at 0x5c131d3b: /24.8.51.5
at 0x56552d91: /18.78.3.175
at 0x5c017525: /24.26.91.27
@stuhood
stuhood / gist:988438
Created May 24, 2011 09:47
XOR Metric Example Buckets
Localhost: /68.27.46.62
Random addresses from each bucket:
Peers in bin 1
at 0x5c0f3a4e: /24.20.20.112
at 0x5c35c2ee: /24.46.236.208
at 0x5ca4eb83: /24.191.197.189
at 0x6273e530: /38.104.203.14
at 0x5cd40272: /24.207.44.76
at 0x5c58a904: /24.67.135.58
at 0x760b4811: /50.16.102.47
[junit] Exiting for size: {0=true}
[junit] Exiting for size: {1=false, 0=true, 2=false}
[junit] Exiting for size: {1=false, 0=true, 2=false}
[junit] ------------- ---------------- ---------------
[junit] Testcase: testResolve(org.apache.cassandra.service.ResolveRaceTest): FAILED
[junit] Failed to resolve: {1=false, 0=true, 2=false}
[junit] junit.framework.AssertionFailedError: Failed to resolve: {1=false, 0=true, 2=false}
[junit] at org.apache.cassandra.service.ResolveRaceTest.runResolve(ResolveRaceTest.java:90)
[junit] at org.apache.cassandra.service.ResolveRaceTest.testResolve(ResolveRaceTest.java:47)
[junit]
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*