This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
public class ArraySumWithMap { | |
private Map<Integer, Integer> numbers = new HashMap<Integer, Integer>(); | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WaitNotifyExample { | |
public static void main(String[] args) { | |
Integer lock = new Integer(0); | |
Thread waiter = new Thread(new Waiter(lock)); | |
waiter.start(); | |
Thread notifier = new Thread(new Notifier(lock)); | |
notifier.start(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArraySum { | |
private int[] array = new int[]{1,2,3,4,5,6,7,8,9}; | |
/** | |
* Do any 2 add up to this number | |
* @param number | |
* @return | |
*/ | |
public boolean canAdd(int number){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Stack; | |
public class Bucket { | |
private Stack<Long> stack = new Stack<Long>(); | |
private int MAX_SIZE = 20; | |
public Long consume(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Map { | |
public static void main(String[] args) { | |
HashMap<Integer,Long> map = new HashMap<Integer,Long>(); | |
for(int i = 0;i<100;i++){ | |
map.put(i,System.nanoTime()); | |
} | |
Iterator<Integer> it = map.keySet().iterator(); | |
while(it.hasNext()){ | |
map.remove(it.next()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkedList<T> { | |
private LinkedListNode<T> first = null; | |
/** | |
* Insert at the front of the list | |
* @param node | |
*/ | |
public void insert(LinkedListNode<T> node) { | |
node.setNext(first); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverseString(s:String) = (for(i<-s.length-1 to 0 by -1) yield s(i)).mkString | |
//Java Version here: | |
public class Test { | |
public final String reverse(String s) { | |
StringBuffer b = new StringBuffer(s.length()); | |
for(int i = s.length()-1; i >=0; i--){ | |
b.append(s.charAt(i)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PalindromeCheck { | |
public final boolean isPalindrome(String s) { | |
boolean isPalindrome = true; | |
for (int i = 0; i < s.length(); i++) { | |
if (!(s.charAt(i) == s.charAt(s.length() - i - 1))) { | |
isPalindrome = false; | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ign.traffic; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.entity.StringEntity; | |
import org.apache.http.impl.client.DefaultHttpClient; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: redis-server | |
# Required-Start: $syslog | |
# Required-Stop: $syslog | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: redis-server - Persistent key-value db |