Skip to content

Instantly share code, notes, and snippets.

View codahale's full-sized avatar
🦆
Look at all these chickens

Coda Hale codahale

🦆
Look at all these chickens
View GitHub Profile
@RunWith(Enclosed.class)
public class ThingTest {
public static class An_Empty_Thing {
private Thing thing;
@Before
public void setup() throws Exception {
this.thing = new Thing();
}
lunchbox /tmp> ministat -w 60 iguana chameleon
x iguana
+ chameleon
+------------------------------------------------------------+
|x * x * + + x +|
| |________M__|___A____________M__A___________________| |
+------------------------------------------------------------+
N Min Max Median Avg Stddev
x 7 50 750 200 300 238.04761
+ 5 150 930 500 540 299.08193
tell application "Mail"
set selectedMessages to the selection
set mailboxMap to {{accountName:"Work", archive:"All Mail"}, {accountName:"Gmail", archive:"All Mail"}}
repeat with mapItem in mailboxMap
set archiveMailbox to the mailbox (archive of mapItem) of account (accountName of mapItem)
set messagesToMove to {}
repeat with msg in selectedMessages
if name of the mailbox of msg is "INBOX" then
if name of the account of the mailbox of msg is (accountName of mapItem) then
val encoded = BERT(1, 2, 3).toArray
BERT.parse(encoded) match {
case BERT(Tuple(x, y, z)) => println("Parsed a tuple: " + x + ", " + y + ", " + z)
case e => println("Unable to parse a tuple: " + e)
}
> GET /49XTeU HTTP/1.1
> User-Agent: curl/7.19.6 (i386-apple-darwin10.0.0) libcurl/7.19.6 OpenSSL/0.9.8k zlib/1.2.3
> Host: bit.ly
> Accept: */*
>
< HTTP/1.1 301 Moved
< Server: nginx/0.7.42
< Date: Sat, 31 Oct 2009 18:54:25 GMT
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
var item = things.get(k)
if (item eq null) {
val newItem = new Item()
item = things.putIfAbsent(k, newItem)
if (item eq null) {
item = newItem
}
}
return item
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
class Monitored extends SomeClass with JmxManaged {
val currentThings = new AtomicLong
val totalThings = new AtomicLong
enableJMX() { jmx =>
jmx.addAttribute("total-things") { totalThings.get }
jmx.addAttribute("current-things") { currentThings.get }
}
// ...
scala> object Thing1 {
| var things = 0
| }
defined module Thing1
scala> class Thing1 {
| Thing1.things +=1
| }
defined class Thing1
// Scala 2.7.7, immutable map, uses foldLeft to loop over files/words
import java.io._
import scala.io._
def time(f: => Unit) = {
val t1 = System.currentTimeMillis
f
((System.currentTimeMillis - t1)/1000.0)
}