Skip to content

Instantly share code, notes, and snippets.

@osgix
osgix / CheckParanthesis.java
Created May 10, 2017 08:47
Check paranthesis in given string whether they are closed appropriately or not.
import java.util.Stack;
public class CheckParanthesis {
public static void main(String[] args) {
System.out.println(isValidParanthesis("a(bcd)d"));
System.out.println(isValidParanthesis("(kjds(hfkj)sdhf"));
System.out.println(isValidParanthesis("(sfdsf)(fsfsf "));
System.out.println(isValidParanthesis("{[]}()"));
@osgix
osgix / ChainOfNames.java
Created May 10, 2017 08:45
Creating output of given names in order that each name is followed by other with starting letter same with preceding one.
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
public class ChainOfNames {
public static void main(String[] args) {
String[] names = new String[] { "Raymond", "Nora", "Daniel", "Louie", "Peter", "Esteban" };
String chainOfNames = createChain(names);
@osgix
osgix / GenerateValidParanthesisPermutations.java
Created May 10, 2017 08:42
Generating valid paranthesis (e.g. (()()), ()()(), ....) is a challenge from Cracking Code Interview Book
import java.util.LinkedList;
import java.util.List;
public class GenerateValidParanthesisPermutations {
private static final String OPEN = "(";
private static final String CLOSE = ")";
public static void main(String[] args) {
@osgix
osgix / AesDemo.java
Created May 10, 2017 08:29
How to use (AES) symmetric key cryptography with java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Base64;
@osgix
osgix / PrintableHashMap.java
Created May 10, 2017 07:52
Printing key value pairs with given string format e.g. "%s is key of %s"
package com.example.collection;
import java.util.HashMap;
import java.util.Iterator;
public class PrintableHashMap<K, V> extends HashMap<K, V> {
private static final long serialVersionUID = 1L;
public String toString(String format) {
@osgix
osgix / git_tips.md
Created March 2, 2017 06:42 — forked from fguillen/git_tips.md
Git Tips

(Several of these git examples have been extracted from the book 'Pragmatic guide to GIT' of Travis Swicegood )

Git tips

Global git user

git config --global user.name "Fernando Guillen"
git config --global user.email "fguillen.mail+spam@gmail.com"

Repository git user

cd /develop/myrepo

@osgix
osgix / rockpaperscissorsgame
Created January 8, 2014 09:35
Rock paper scissors game with javascript
var compare = function(userChoice, computerChoice) {
if(userChoice == 'R') {
if(computerChoice == 'S') {
return 1;
}
else if(computerChoice == 'P') {
return 2;
}
else {
return 0;