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 Main { | |
public static void main(String[] args) { | |
Data d = new Data(); | |
Thread p1 = new Thread(new Producer(d, 1)); | |
Thread c1 = new Thread(new Consumer(d, 1)); | |
Thread c2 = new Thread(new Consumer(d, 2)); | |
p1.start(); |
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 Data { | |
private int data; | |
private boolean available = false; | |
synchronized public void put(int value) { | |
// there's already something in data | |
while (available) { | |
try { | |
wait(); |
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 Consumer implements Runnable { | |
private Data data; | |
private int id; | |
public Consumer(Data data, int id) { | |
this.data = data; | |
this.id = id; | |
} | |
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 Producer implements Runnable { | |
private Data data; | |
private int id; | |
public Producer(Data data, int id) { | |
this.data = data; | |
this.id = id; | |
} |
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
def fromS3(bucket: String, path: String): MyObject = { | |
val AWSCredentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY) | |
val amazonS3Client = new AmazonS3Client(AWSCredentials) | |
def readFile(fn: String) = {scala.io.Source.fromInputStream(amazonS3Client.getObject(bucket, path + fn).getObjectContent).getLines}.toList | |
getMyObject(readFile) | |
} |
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
private static List<String> getData(InputStream input) { | |
List<String> result = new ArrayList<>(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(input)); | |
while (true) { | |
String line = null; | |
try { | |
line = reader.readLine(); | |
} catch (IOException exception) { } | |
if (line == null) break; |
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
def fromCustomFunc(customFunc: String => java.util.List[String]) = { | |
def readFile(fn: String) = { customFunc(fn) } | |
getMyObject(readFile) | |
} |
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 scala.runtime.AbstractFunction1; | |
// somewhere | |
sc = ScalaClass.fromCustomFunc(new AbstractFunction1<String, List<String>>() { | |
@Override | |
public List<String> apply(String fn) { | |
BasicAWSCredentials AWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY); | |
AmazonS3Client amazonS3Client = new AmazonS3Client(AWSCredentials); | |
return getData(amazonS3Client.getObject(BUCKET, PATH + fn).getObjectContent()); | |
} |
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
Instance Type | vCPU | Memory (GiB) | |
---|---|---|---|
t2.nano | 1 | 0.5 | |
t2.micro | 1 | 1 | |
t2.small | 1 | 2 | |
t2.medium | 2 | 4 | |
t2.large | 2 | 8 | |
t2.xlarge | 4 | 16 | |
t2.2xlarge | 8 | 32 | |
m4.large | 2 | 8 | |
m4.xlarge | 4 | 16 |
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
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo "You must provide a keyword to search" | |
exit 1 | |
fi | |
mapfile -t options < <(grep -Ir "$1") | |
PS3="Please enter your choice: " |
OlderNewer