Skip to content

Instantly share code, notes, and snippets.

QEmployee qEmployee = QEmployee.employee;
List<Employee> emps = sqlQuery.from(qEmployee)
.where(qEmployee.name.eq(name))
.list(new QBean<Employee>(Employee.class, qEmployee.id, qEmployee.name));
// QBean defines a Bean populating projection, the first argument is the Bean class and the rest the paths to be used for Bean population
@cgopalan
cgopalan / tailrecursivesum.scala
Created September 8, 2011 17:52
Scala Tail Recursive Sum
object FirstClassFunctions {
def sum(f: Int => Int)(a: Int, b:Int): Int = {
def iter(a: Int, result: Int): Int =
if (a > b) result
else iter(a + 1, f(a) + result)
iter(a,0)
}
def main(args: Array[String]) {
println("Sum is: " + sum(x => x)(1,10))
@kdonald
kdonald / JsonNodeRowMapper.java
Created March 20, 2012 16:35
Auto Mapping a JDBC ResultSet to JSON
// convenient Spring JDBC RowMapper for when you want the flexibility of Jackson's TreeModel API
// Note: Jackson can also serialize standard Java Collections (Maps and Lists) to JSON: if you don't need JsonNode,
// it's simpler and more portable to have Spring JDBC simply return a Map or List<Map>.
package org.springframework.jdbc.core;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
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
@jboner
jboner / latency.txt
Last active August 1, 2024 10:59
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@chitan
chitan / WsChatServlet.java
Created July 7, 2012 01:44
How to use WebSocket of Tomcat
//This sample is how to use websocket of Tomcat.
package wsapp;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.ArrayList;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
@jasonrudolph
jasonrudolph / 00-about.md
Created September 21, 2012 18:42
Rough Notes from Strange Loop 2012
@SeanTAllen
SeanTAllen / gist:3790659
Created September 26, 2012 21:21
The many things I ended up bookmarking at StrangeLoop 2012
Many of these are from Strangeloop talks and tweets, I can't promise all are as it was a fast paced mess (if anyone cares, these are in reverse order):
I found this last night: blueprints graph db adapter for datomic:
https://github.com/datablend/blueprints/tree/master/blueprints-datomic-graph
The Boundary crew continue building great things & sharing their experience via excellent blogging:
http://boundary.com/blog/2012/09/26/incuriosity-killed-the-infrastructur/
Disruptor Workshop Materials:
http://mechanitis.blogspot.com/2012/09/strangeloop-disruptor-workshop-materials.html
@rymawby
rymawby / undo-git-rebase.sh
Created June 14, 2013 18:37
Undoing a git rebase
# find head commit
git reflog
# now reset hard - where N is the head commit found in the reflog
git reset --hard HEAD@{N}