Skip to content

Instantly share code, notes, and snippets.

@devnulled
devnulled / gist:2026961
Created March 13, 2012 05:18
Generate Secure RSA Key on Mac
ssh-keygen -t rsa -b 4096 -C "[email protected]"
@devnulled
devnulled / gist:2303585
Created April 4, 2012 16:31
Scala Test + Mockito + TestNG Template for IntelliJ
#if (${PACKAGE_NAME} == "" )package ${PACKAGE_NAME}
#end
import org.scalatest.Assertions
import org.scalatest.mock.MockitoSugar
import org.testng.annotations.Test
import org.scalatest.Assertions
import org.scalatest.mock.MockitoSugar
import org.testng.Assert._
@devnulled
devnulled / gist:2369299
Created April 12, 2012 17:21
Using Commons HTTP Client 3.1 With a Proxy + SSL Self Generated Certificate
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
HttpClient client = new HttpClient();
HostConfiguration config = client.getHostConfiguration();
config.setProxy("localhost", 8888);
@devnulled
devnulled / gist:2369406
Created April 12, 2012 17:33
Build A Simple Expiring Cache Based On Time
// Requires Google Guava 10 or greater
Cache<Key, Graph> graphs = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.weakKeys()
.maximumSize(10000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader<Key, Graph>() {
public Graph load(Key key) throws AnyException {
@devnulled
devnulled / gist:2401262
Created April 16, 2012 20:22
Jackson 1.9 - Ignore Properties That Don't Exist on Bean
ObjectMapper mapper = new ObjectMapper();
mapper.getDeserializationConfig().without(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
@devnulled
devnulled / gist:2407714
Created April 17, 2012 17:42
Parse a Microsoft .NET style JSON Date/Timestamp into a Java Date
package devnulled;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DateTimeUtils {
/**
* <p>
* Parses a Microsoft .NET style JSON timestamp and returns a Java Date irrespective of time zones (but can parse them)
@devnulled
devnulled / elite.txt
Created May 24, 2012 02:26 — forked from rodhilton/gist:2777936
Secret Awesome Code
* g o a t s e x * g o a t s e x * g o a t s e x *
g g
o / \ \ / \ o
a| | \ | | a
t| `. | | : t
s` | | \| | s
e \ | / / \\\ --__ \\ : e
x \ \/ _--~~ ~--__| \ | x
* \ \_-~ ~-_\ | *
g \_ \ _.--------.______\| | g
@devnulled
devnulled / OptionCheatsheet.scala
Created June 27, 2012 15:45
Scala Option Cheatsheet
// flatMap
// This code is equivalent to:
// option.flatMap(foo(_))
option match {
case None => None
case Some(x) => foo(x)
}
// flatten
// This code is equivalent to:
@devnulled
devnulled / gist:3417585
Created August 21, 2012 17:31
How To Specify an Ivy Style Resolver for sbt
resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
@devnulled
devnulled / Microbenchmark.scala
Created August 30, 2012 18:28
Example Code To Microbenchmark In Scala
def doSomething() = {
val s = System.nanoTime
// do stuff here
println("time: "+(System.nanoTime-s)/1e6+"ms")
}