Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
sachin-handiekar / JollyJumper.java
Created June 11, 2011 21:38
10038 Jolly Jumpers
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
public class JollyJumper {
public static String JOLLY = "Jolly";
public static String NOT_JOLLY = "Not jolly";
public static void main(String[] args) {
@sachin-handiekar
sachin-handiekar / SampleHTTPCall.java
Created June 11, 2011 21:52
Using proxy with HttpClient
//~--- non-JDK imports --------------------------------------------------------
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@sachin-handiekar
sachin-handiekar / InterviewQ1.java
Created June 11, 2011 21:55
Interview Question [Java]
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.TreeMap;
import java.util.Iterator;
public class InterviewQ1 {
private TreeMap courseMarksMap = new TreeMap();
@sachin-handiekar
sachin-handiekar / InterviewQ2.java
Created June 11, 2011 21:59
Interview Question [Java]
/**
Desired Output
---------------
Country - India
State - Gujarat
City - Ahmedabad
City - Vadodara
State - MP
City - Bhopal
@sachin-handiekar
sachin-handiekar / InfiniteSeries.java
Created June 11, 2011 22:05
Interview Question - InfiniteSeries
public class InfiniteSeries {
public static void main(String[] args) {
int i = 100;
while (true) {
if (i > 0) {
System.out.println((100 - i) + " " + i);
i--;
} else if (i == -100) {
System.out.println((100 + i) + " " + 0);
i--;
@sachin-handiekar
sachin-handiekar / EmailValidator
Created June 16, 2011 14:53
Email Validator
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailValidator {
public boolean isValidEmailAddress(String emailAddress) {
String expression = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
CharSequence inputStr = emailAddress;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
@sachin-handiekar
sachin-handiekar / NamespaceTrimmer.xslt
Created September 21, 2011 17:28
Remove namespace from XML using XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
@sachin-handiekar
sachin-handiekar / AddNamespaceInRoot.xslt
Created September 21, 2011 17:29
Add namespace in root node using XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vbs="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<!-- Just change the match="/*" to match="*" ; if you want to add namespace in all elements -->
@sachin-handiekar
sachin-handiekar / basiclog4j.java
Created September 24, 2011 16:42
log4j Basic Configurator
import com.foo.Bar;
// Import log4j classes.
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class MyApp {
// Define a static logger variable so that it references the
// Logger instance named "MyApp".
@sachin-handiekar
sachin-handiekar / enqueue_jms_msg_oracle_aq.sql
Created October 15, 2011 11:45
Enqueue JMS type message in Oracle AQ
declare
-- Local variables here
queue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
message_id RAW(16);
agent SYS.AQ$_AGENT := SYS.AQ$_AGENT(' ', null, 0);
my_message SYS.AQ$_JMS_TEXT_MESSAGE;
begin
my_message := SYS.AQ$_JMS_TEXT_MESSAGE.construct;
my_message.set_text('<< sample message >>');