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 com.sun.org.apache.xml.internal.security.utils.Base64; | |
import javax.crypto.SecretKeyFactory; | |
import javax.crypto.spec.PBEKeySpec; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.SecureRandom; | |
import java.security.spec.InvalidKeySpecException; | |
/** | |
* Hash a password using PBKDF2 with hman and sha1 algorithm. |
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 com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException; | |
import com.sun.org.apache.xml.internal.security.utils.Base64; | |
import javax.crypto.*; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.PBEKeySpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.io.UnsupportedEncodingException; | |
import java.security.*; | |
import java.security.spec.InvalidKeySpecException; |
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.ArrayList; | |
/** | |
* Classes that produce and consume data from a shared store to demonstrate the wait/notify mechanism. | |
*/ | |
public class WaitNotifyMechanism { | |
static ArrayList<Integer> dataStore = new ArrayList<Integer>(); | |
static class Producer extends Thread { |
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 sys | |
class MyClass(object): | |
def func1(self, arg1): | |
print "Invoked: func1({0})".format(arg1) | |
def func2(self, arg1, arg2): | |
print "Invoked: func2({0}, {1})".format(arg1, arg2) | |
def main(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
import java.io.IOException; | |
import java.nio.file.*; | |
import java.nio.file.attribute.BasicFileAttributes; | |
/** | |
* Traverse a directory and print every file that matches a Glob pattern. In this example, the users home dir is | |
* searched for .java and .py files. | |
*/ | |
public class FileFinder extends SimpleFileVisitor<Path> { |
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
list1 = ['item1', 'item2', 'item3'] | |
list2 = ['subitem1', 'subitem2', 'subitem3'] | |
mapped_dict = {x: {"subtitle" :y} for x, y in zip(list1, list2)} |
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.Console; | |
/** | |
* Take in username and password from the console. | |
*/ | |
public class ConsoleInput { | |
public static void main(String[] args) { | |
Console console = System.console(); |
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.IOException; | |
import java.nio.file.*; | |
import static java.nio.file.StandardWatchEventKinds.*; | |
/** | |
* Watch a directory for changes using a WatchService. | |
*/ | |
public class DirWatcher { |
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.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* A thread pool with the executor framework to execute tasks. Also demonstrates a simple timeout mechanism. | |
*/ | |
public class ThreadPool { | |
private static final int NTHREADS = Runtime.getRuntime().availableProcessors(); |
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.concurrent.*; | |
/** | |
* Use a callable to retrieve values from tasks executed in a thread pool. | |
*/ | |
public class CallableFuture { | |
public static void main(String[] args) { | |
Callable<Long> task = new Factorial(20); |
OlderNewer