Skip to content

Instantly share code, notes, and snippets.

View karanmalhi's full-sized avatar

Karan Singh Malhi karanmalhi

  • MuleSoft
  • San Francisco
View GitHub Profile
@karanmalhi
karanmalhi / index.jsp
Created December 6, 2011 22:04
A simple index.jsp file which shows some session information
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Apache Tomcat Examples</TITLE>
<META http-equiv=Content-Type content="text/html">
</HEAD>
<BODY>
<h3>Session ID = <%=session.getId()%></h3>
<h3>Creation Time = <%=session.getCreationTime()%></h3>
</BODY></HTML>
@karanmalhi
karanmalhi / Debugger.java
Created July 28, 2011 19:37
ThreadLocal example
import java.util.ArrayList;
import java.util.List;
public class Debugger {
public static void main(String[] args) {
ThreadGroup cleanupThreads = new ThreadGroup("Cleanup group");
Thread t1 = new Thread(cleanupThreads, new Printer());
Thread t2 = new Thread(cleanupThreads, new Printer());
t1.start();
t2.start();
@karanmalhi
karanmalhi / Manager.java
Created July 28, 2011 19:21
Example of countdown latch
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@karanmalhi
karanmalhi / Test.java
Created July 28, 2011 21:25
Challenge to invoke methods using reflection and annotation processing
package learnquest;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.Date;
@karanmalhi
karanmalhi / ProxyCreator.java
Created August 17, 2011 17:23
Creating a proxy with JavAssist
package mit.proxy;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
public class ProxyCreator {
@karanmalhi
karanmalhi / intellij_error
Created August 31, 2012 13:32
intellij error
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7534 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 11.app/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 11.app/lib/idea_rt.jar:/Applications/IntelliJ IDEA 11.app/plugins/junit/lib/junit-rt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/deploy.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/dt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javaws.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jconsole.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/management-agent.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/plugin.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/sa-jdi.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Content
@karanmalhi
karanmalhi / gist:2765027
Created May 21, 2012 22:15
deploymentStatus
private DeploymentStatus getDeploymentStatus(DeploymentAction latest) {
DeploymentStatus status;
if (Action.DELETE.equals(latest.getAction())) {
status = DeploymentStatus.DELETING;
} else {
boolean inProcess = false;
int failCount = 0;
// if size is 0, that means we do not have any status yes, a typical indication that the deployment on servers has not started yet.
if (latest.getStatuses().size() == 0) {
// the deployment is still in progress, i.e. about to start
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<distributable/>
@karanmalhi
karanmalhi / uriworkermap.properties
Created December 6, 2011 21:21
uriworkermap.properties to map URL Path patterns to workers
#/foo and /foo/* are both mapped to balancer worker
/foo|/*=balancer
#/jkstatus is mapped to the stats worker
/jkstatus/=stats
@karanmalhi
karanmalhi / worker.properties
Created December 6, 2011 21:18
Used to configure workers
#The list of workers
worker.list=balancer,stats
#The template contains default values. Each worker will inherit
#these values and override the port
# the worker type
worker.template.type=ajp13
#This could also be an IP address. Since all Tomcat instances
#and IIS are installed on the same host, hence "localhost"