Skip to content

Instantly share code, notes, and snippets.

View MarounMaroun's full-sized avatar
🎹
♫♩♬

Maroun Maroun MarounMaroun

🎹
♫♩♬
View GitHub Profile
@MarounMaroun
MarounMaroun / Main.java
Last active April 19, 2016 10:48
Runs a simulation of producer-consumer pattern
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();
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();
public class Consumer implements Runnable {
private Data data;
private int id;
public Consumer(Data data, int id) {
this.data = data;
this.id = id;
}
@MarounMaroun
MarounMaroun / Producer.java
Last active April 19, 2016 11:41
Producer code
public class Producer implements Runnable {
private Data data;
private int id;
public Producer(Data data, int id) {
this.data = data;
this.id = id;
}
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)
}
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;
def fromCustomFunc(customFunc: String => java.util.List[String]) = {
def readFile(fn: String) = { customFunc(fn) }
getMyObject(readFile)
}
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());
}
@MarounMaroun
MarounMaroun / aws_instance_types.tsv
Created January 25, 2017 15:31
AWS instance types TSV (with vCPU and Memory info only)
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
@MarounMaroun
MarounMaroun / igrep.sh
Created September 5, 2017 13:59
Interactive grep
#!/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: "