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 / 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[]){
@eleco
eleco / BoundedPriorityQueue.java
Created March 4, 2015 14:19
Bounded priority queue
import java.util.PriorityQueue;
public class BoundedPriorityQueue<T> extends PriorityQueue<T> {
final private int maxSize ;
public BoundedPriorityQueue(int maxSize) {
this.maxSize = maxSize;
}
@eleco
eleco / ServoDemo.java
Created April 11, 2015 21:22
netflix servo demo
package servo;
import com.netflix.servo.monitor.Counter;
import com.netflix.servo.monitor.MonitorConfig;
import com.netflix.servo.monitor.Monitors;
import com.netflix.servo.monitor.PeakRateCounter;
public class ServoDemo {
@eleco
eleco / MyBenchmark.java
Created April 16, 2015 19:23
Simple Servo benchmark test
package jmh;
import com.netflix.servo.monitor.Counter;
import com.netflix.servo.monitor.MaxGauge;
import com.netflix.servo.monitor.MonitorConfig;
import com.netflix.servo.monitor.Monitors;
@eleco
eleco / StringInternTest.java
Created June 30, 2015 08:44
string intern benchmark with JMH
package jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.profile.StackProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.ArrayList;
import java.util.List;
@eleco
eleco / gist:309d8721272258ac8203
Last active December 6, 2015 20:57
angular v1 route debugging
// Credits: Adam's answer in http://stackoverflow.com/a/20786262/69362
// Paste this in browser's console
var $rootScope = angular.element(document.querySelectorAll("[ui-view]")[0]).injector().get('$rootScope');
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
});
$rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){
console.log('$stateChangeError - fired when an error occurs during transition.');
@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 / 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) {