Skip to content

Instantly share code, notes, and snippets.

View khan5v's full-sized avatar

Vladimir Orekhov khan5v

View GitHub Profile
@khan5v
khan5v / n_child_forking.pl
Last active November 3, 2016 13:27
Perl fork() example with multiple child processes involved
use strict;
use warnings;
my $spawn_processes = 5;
my $forked = 0;
my $err = 0;
print "($$) parent has started\n";
foreach(1..$spawn_processes) {
my $child_pid = fork();
@khan5v
khan5v / elementary_forking.pl
Created November 3, 2016 10:52
Basic perl fork() example
use strict;
use warnings;
my $child_pid = fork();
if(defined $child_pid && $child_pid > 0) {
## Parent
wait();
print "p($$) c($child_pid) child finished, exiting\n";
} else {
## Child
@khan5v
khan5v / filterout.py
Created August 29, 2015 16:49
Shows how to filter entries out based on some logic in Spark
#reading data from a file
logData = sc.textFile(logFile)
X = 10
#for each key finding entries that occur more than X times
outliers = logData.map(lambda (k, v): (k, 1)).reduceByKey(lambda a, b: a + b).filter(lambda (k, v): v > X).cache()
#filtering these entries out
@khan5v
khan5v / MongoQueryObjectID
Last active August 29, 2015 14:22
MongoDB query based on ObjectID, getting MongoDB ObjectID from String
# getting an objectId object from a string
getObjectID = function(str) {
return(mongo.oid.from.string(str))
}
database = ""
mongo = NULL
namespace = ""
connectToMongoDB = function(host, db, collection) {