Skip to content

Instantly share code, notes, and snippets.

View eleco's full-sized avatar
🏠
Working from home

Elec eleco

🏠
Working from home
View GitHub Profile
@eleco
eleco / DivideBenchmark.java
Created April 1, 2013 20:20
bitwise ops benchmark
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static junit.framework.Assert.assertTrue;
public class DivideBenchmark {
@eleco
eleco / Breakout.scala
Created July 23, 2013 18:33
Scala Breakout
import scala.Some
import scala.swing._
import scala.util.Random
import java.awt.Color
import java.util.Timer
import java.util.TimerTask
import swing.event._
@eleco
eleco / MultithreadTest.java
Created September 30, 2013 11:19
Synchronized vs AtomicReference
import com.google.common.base.Stopwatch;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@eleco
eleco / Item.java
Last active December 26, 2015 04:08
log exception
package com.company;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Item {
Logger log = Logger.getLogger("ItemLogger");
public boolean function(String param) {
@eleco
eleco / Item.java
Last active December 26, 2015 04:08
hide exception
package com.company;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Item {
Logger log = Logger.getLogger("ItemLogger");
public boolean function(String param) {
@eleco
eleco / Builder.java
Created November 17, 2013 15:47
json builder
public class Builder {
private String name;
private String description;
public Thing build(){
return new Thing(name, description);
}
@eleco
eleco / src_main_java_foo_bar_Trade.java
Created December 1, 2013 19:30
jbehave spring example
package foo.bar;
public class Trade {
int price;
Trade (int price){
this.price = price;
}
@eleco
eleco / JsonUtils.java
Created July 25, 2014 15:28
transform json native object to java map
import sun.org.mozilla.javascript.internal.Context;
import sun.org.mozilla.javascript.internal.NativeArray;
import sun.org.mozilla.javascript.internal.NativeObject;
import sun.org.mozilla.javascript.internal.Scriptable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@eleco
eleco / RhinoEval.java
Created July 25, 2014 16:37
evaluate javascript function with mozilla's rhino
import org.mozilla.javascript.Context;
import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.Scriptable;
public class RhinoLoader {
public static void main(String args[]){
Context ctx = Context.enter();
try {
@eleco
eleco / SinglyListNode.java
Created November 8, 2014 18:30
reverse singly list recursively and iteratively
public class SinglyListNode {
SinglyListNode next;
String s;
public String toString(){return s;}
public SinglyListNode(String s){this.s=s;}
public static void main(String argsp[]){