Skip to content

Instantly share code, notes, and snippets.

@bchetty
bchetty / DatabaseResourceLoader.java
Created May 24, 2013 20:55
Seam v2 Database Resource Loader.
@Scope(ScopeType.STATELESS)
@BypassInterceptors
@Install(precedence = Install.APPLICATION, dependencies = "org.jboss.seam.security.identity")
@Name("org.jboss.seam.core.resourceLoader")
public class DatabaseResourceLoader extends ResourceLoader {
@Override
public ResourceBundle loadBundle(String bundleName) {
return new ResourceBundle() {
public Enumeration<String> getKeys() {
//Locale locale = org.jboss.seam.core.Locale.instance();
@bchetty
bchetty / MissingNumbers.java
Created May 24, 2013 20:45
Missing Number's problem.
public class MissingNumbers {
public static void main(String[] args) {
//In the below code: Array Size = 8 and n = 10.
//So 2 missing numbers!
int n = 10;
int[] intArr = new int[] {3,1,2,5,4,7,10,8};
MissingNumbers missingNums = new MissingNumbers();
int[] missingNums = missingNums.findMissingNumber(intArr, n);
@bchetty
bchetty / MissingNumber.java
Created May 24, 2013 20:44
Missing Number Problem.
public class MissingNumber {
public static void main(String[] args) {
MissingNumber missingNum = new MissingNumber();
System.out.println("Missing Number : " + missingNum.findMissingNum(new int[] {3,1,2,5,4,7,9,8}, 9));
}
private int findMissingNum(int[] intArray, int n) {
int res = 0;
int sum = 0;
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:40
Plugin repository for Maven YUI compressor plugin.
<pluginrepositories>
<pluginrepository>
<name>oss.sonatype.org</name>
<id>oss.sonatype.org</id>
<url>http://oss.sonatype.org/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:39
Maven plugin for YUI compressor.
<build>
<plugins>
<plugin>
<groupid>net.alchim31.maven</groupId>
<artifactid>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:35
Maven-Shade plugin usage
<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupId>
<artifactid>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
@bchetty
bchetty / BigIntTest.java
Created May 24, 2013 20:22
Looping through a range of BigInteger values.
import java.math.BigInteger;
public class BigIntTest {
public static void main(String[] args) {
BigInteger bigInt1 = new BigInteger("1000000000000000");
BigInteger bigInt2 = new BigInteger("1000000000000500");
//Loop from bigInt1 to bigInt2
for(BigInteger bigInt = bigInt1; bigInt.compareTo(bigInt2) < 0; bigInt = bigInt.add(BigInteger.ONE)) {
System.out.println("I'm so big now : " + bigInt);
@bchetty
bchetty / JCompiler.java
Created May 24, 2013 20:11
Compile Java files at runtime.
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
@bchetty
bchetty / Googol.java
Created May 23, 2013 22:59
Googol Number
public class Googol {
public static void main(String[] args) {
long googol1 = (long) Math.pow(10,100);
System.out.println("Googol1 : " + googol1);
System.out.println("Max Value of Long : " + Long.MAX_VALUE);
BigDecimal googol2 = new BigDecimal(Math.pow(10,100) + "");
System.out.println("Googol2 : " + googol2);
BigDecimal bigDecimal = googol2.multiply(new BigDecimal(Math.PI + ""));
@bchetty
bchetty / ReverseWords.java
Created May 23, 2013 22:48
Reverse Words - GCJ 2010 (Africa)
import java.util.*;
import java.io.*;
public class ReverseWords {
public String reverseWords(String phrase) {
List<string> wordList = Arrays.asList(phrase.split("[ ]"));
Collections.reverse(wordList);
StringBuilder sbReverseString = new StringBuilder();
for(String word: wordList) {