This file contains 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.Arrays; | |
public class Power2 { | |
static int resultLen = 5000; | |
public static void main(String[] args) { | |
Power2 power = new Power2(); | |
String s = power.power(10000); | |
System.out.println(s); | |
} | |
String power(int n) { |
This file contains 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.Arrays; | |
public class SumOfThreads implements Runnable { | |
static int sum[] = new int[3]; | |
static int idx = 0; | |
int n1, n2; | |
SumOfThreads(int n1, int n2) { | |
this.n1 = n1; | |
this.n2 = n2; |
This file contains 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
/* Design a class to represent a deck of cards, and implement a | |
shuffle method for the deck of cards. http://goo.gl/T4Bk9 */ | |
import java.util.Arrays; | |
import java.util.Random; | |
public class DeckOfCards { | |
public static String deck = "23456789TJQKA"; | |
public static int numOfShuffles = 13; | |
public static void main(String[] args) { |
This file contains 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
N = 1001 | |
def collatz_sequences(n): | |
while n > 1: | |
print n | |
if (n % 2) != 0: | |
n = (3 * n) + 1 | |
else: | |
n = n / 2 | |
print n |
This file contains 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
# Add the following code to your ~/.bash_profile. | |
pman() | |
{ | |
PMANFILE="/tmp/pman-${1}.pdf" | |
if [ ! -e $PMANFILE ]; then # only create if it doesn't already exist | |
man -t "${1}" | pstopdf -i -o "$PMANFILE" | |
fi | |
if [ -e $PMANFILE ]; then # in case create failed | |
open -a /Applications/Preview.app/ "$PMANFILE" | |
fi |
This file contains 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
# Add following snippet to your ".bash_profile" to google from the terminal. | |
# google from Terminal | |
google() { | |
python -c "import sys, webbrowser, urllib; webbrowser.open('http://www.google.com/search?' + urllib.urlencode({'q': ' '.join(sys.argv[1:]) }))" $@ | |
} | |
# Usage: $ google recursion |
This file contains 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.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class WordTotal100 { | |
public static void main(String[] args) { | |
// read big.txt file | |
try { | |
String fileStr = readFileAsString("words.txt"); | |
String[] words = fileStr.split("\\r?\\n"); |
This file contains 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
#!/usr/bin/env sh | |
## | |
# This is script with usefull tips taken from: | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# | |
# install it: | |
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
# |
This file contains 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 static String concat(String arg, String... args) { | |
StringBuilder builder = new StringBuilder(arg); | |
for(String s:args){ | |
builder.append(s); | |
} | |
return builder.toString(); | |
} |
This file contains 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 HashTable { | |
private static int INITIAL_SIZE = 16; | |
private HashEntry[] entries = new HashEntry[INITIAL_SIZE]; | |
public void put(String key, String value) { | |
int hash = getHash(key); | |
final HashEntry hashEntry = new HashEntry(key, value); | |
if(entries[hash] == null) { | |
entries[hash] = hashEntry; | |
} | |
// If there is already an entry at current hash |