Skip to content

Instantly share code, notes, and snippets.

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

Deepak Mishra d3ep4k

🏠
Working from home
View GitHub Profile
@d3ep4k
d3ep4k / Parenthesis Matching
Last active August 29, 2015 14:12
Parenthesis Matching using stack
str = '{{{[({})[()]]}}}'
Stack s = new Stack()
i = 0
while(i< str.length()){
c = str[i]
if(c == '[' || c == '{' || c== '(')
s.push(c)
else if(!s.empty() &&
@d3ep4k
d3ep4k / String encoding - character count
Created January 6, 2015 11:26
String Encoding - Character Count
str = 'aaaabbbccddddd'
out = ''
Stack s = new Stack()
i=0
while(i<str.length()){
//if element matched
if(!s.empty() && s.peek() != str[i] ){
out = out + s.peek() + '' + s.size()
@d3ep4k
d3ep4k / Paper folding problem
Created January 6, 2015 11:28
Paper folding problem - Folding paper n times
x = []
def fold(n) {
if (n == 1)
x.add('V')
else {
fold(n-1)
x.add('V')
reverse(n-1)
}
}
@d3ep4k
d3ep4k / Sorting Map on Value
Created January 13, 2015 10:12
Java/Groovy - Sorting Map on Value
map = new LinkedHashMap();
map.put('a', 7);
map.put('b', 6);
map.put('c', 9);
list =new LinkedList<Map.Entry<String, Integer>>( map.entrySet() );
Collections.sort( list, { Map.Entry o1, Map.Entry o2 ->
return (o2.getValue()).compareTo( o1.getValue())
})
@d3ep4k
d3ep4k / Construct String from data array
Created January 14, 2015 07:38
Function to Construct String from array of data
String construct(String start, String middle, String end, String data){
StringBuilder construct = new StringBuilder();
String[] tokens = data.split(",");
int i=0;
construct.append(start);
while(i<tokens.length -1){
construct.append(middle.replaceAll("%s", tokens[i]));
i++;
}
construct.append(end.replaceAll("%s", tokens[i]));
@d3ep4k
d3ep4k / BaisedCoin.java
Last active August 29, 2015 14:15
Biased coin toss converted to unbiased coin toss.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
*
* @author deepak
*/
public class BiasedCoin {
@d3ep4k
d3ep4k / string-char.groovy
Last active December 3, 2015 12:36
String to List of characters
def str = "VVPVVPPVVVPPVPPVVVPVVPPPVVPPVPPVVVPVVPPVVVPPVPPPVVPVVPPPVVPPVPP"
print Arrays.asList(str.toCharArray())
@d3ep4k
d3ep4k / XSDValidation.java
Last active August 29, 2015 14:23
Java XML Validation using XSD
import javax.xml.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.validation.*;
import java.io.*;
import java.net.*;
import org.xml.sax.*;
public class XSDValidation{
public static void main(String[] args) throws Exception{
@Grab(group='org.apache.poi', module='poi', version='3.9')
@Grab(group='org.apache.poi', module='poi-ooxml', version='3.9')
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFCellUtil;
import org.apache.poi.ss.util.CellRangeAddress;
@d3ep4k
d3ep4k / FindJar.bat
Last active August 29, 2015 14:24
Windows - Find jar containing a name
for /R %G in (*.jar) do @jar -tvf %G | find "ClassName" > NUL && echo %G