Skip to content

Instantly share code, notes, and snippets.

def peak(list: List[Int]): Option[Int] =
list.sliding(3).collectFirst{case(List(x, y, z)) if(y > x && y > z) => y}
def raisePeak(list: List[Int]): Option[List[Int]] =
peak(list).map(p => List(p + 1))
import java.util.HashSet;
import java.util.Set;
public class MagicalLand {
public static void main(String[] args) {
for (int i = 0; i < (Math.random() * 500) + 2; i++) {
if (Unicorn.pat()) {
System.out.println("UNICORN #1: PAT THIS UNICORN ONCE");
}
}
(function () {
//From: http://yasintrm.blogspot.no/2012/05/how-to-install-syntax-highlighter-on.html
var arr, counter = 0,
doc = document,
len, load, callBack, url = 'http://agorbatchev.typepad.com/pub/sh/3_0_83/';
if (window.SyntaxHighlighter && !window.SyntaxHighlighterLoading) {
SyntaxHighlighter.highlight();
} else if (!window.SyntaxHighlighterLoading) {
window.SyntaxHighlighterLoading = true;
def message(date: DateTime) =
messages collectFirst {
case (pred, msg) if pred(date) => msg
}
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("root");
rootElement.appendChild(doc.createTextNode("A\u0000B"));
doc.appendChild(rootElement);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import static java.lang.System.currentTimeMillis;
import static org.apache.commons.lang.time.DateUtils.MILLIS_PER_SECOND;
public class DelayQueueMain {
public static void main(String[] args) throws InterruptedException {
4 1
5 3
6 5
7 8
8 12
9 17
10 24
11 32
12 42
13 54
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class BookstoreWjugTest {
@Resource
private BookstoreSEI bookstore;
@Test
public void shouldReturnTrueForCxfBook() throws Exception {
Book book = new Book("Apache CXF Web Service Development", "Naveen Balani & Rajeev Hathi");
@nurkiewicz
nurkiewicz / gc
Created March 30, 2011 07:08
Useful JVM options
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-XX:+TraceClassLoading
-XX:+TraceClassUnloading
-XX:+PrintTenuringDistribution
-Xloggc:gc.log
-XX:+PrintGC
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ContextConfiguration {
@Bean
public DataSource dataSource() {