Skip to content

Instantly share code, notes, and snippets.

View danielhopkins's full-sized avatar

Dan Hopkins danielhopkins

View GitHub Profile
@danielhopkins
danielhopkins / t.scala
Last active December 13, 2015 19:48
Timing out futures using Scala promises
// We're trying to express a future that can timeout but I don't
// want to use Await and block the current thread. I need to return
// a future that is either timed out or the value of the completed future
import concurrent.ExecutionContext.Implicits._
import concurrent.Future
import concurrent._
import concurrent.duration._
import akka.pattern.after
import scala.util.{Try, Success, Failure}
@danielhopkins
danielhopkins / nio.scala
Created December 15, 2012 22:59
Exploration of nio java
import java.io._
import java.nio._
import java.nio.channels._
/*
Initially I wanted to explore the nio api for file access and I ended up coming across a SO article
saying that nio isn't faster than just plain 'ol FileOutputStream. Curious about this I came up with
a benchmark suite and quickly found that is indeed true. After a couple of iterations I was able to
beat the default, but clearly it's not easy or obvious.
@danielhopkins
danielhopkins / InstallCert.java
Created May 6, 2012 15:44
Connecting to an untrusted certificate in java
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
class TryIt
def []=(k,v) return "I'm a return value, if I'm not returned where do I go?" end
end
t = TryIt.new
puts(t['blah'] = "It would be slightly surprising if I were returned, right?")
#=> "It would be slightly surprising if I were returned, right?"
@danielhopkins
danielhopkins / description
Created January 4, 2012 03:22
Full chunked sinatra
Got this working under jruby 1.6.5 with trinidad as a webserver (webbrick doesn't seem to work)