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
# 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) { |
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
#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 |
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
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 |
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
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(); |
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
use strict; | |
use warnings; | |
use POSIX qw( WNOHANG ); | |
my $spawn_processes = 5; | |
my $forked = 0; | |
my ($err, $success) = (0, 0); | |
my $local_id = 0; | |
print "($$) parent has started\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
use strict; | |
use warnings; | |
use Data::Dumper; | |
use AnyEvent::Handle; | |
use AnyEvent; | |
my($pipe_w, $pipe_r); | |
pipe $pipe_r, $pipe_w; | |
my $cv = AnyEvent->condvar; |
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
use strict; | |
use warnings; | |
use Parallel::SubFork; | |
use Data::Dumper; | |
my $manager = Parallel::SubFork->new(); | |
for(1..10) { | |
$manager->start(\&cb, [$_]); |
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
Collections.sort(list, new Comparator<Pair>() { | |
public int compare(Pair p1, Pair p2) { | |
//Reverse order of i (integers) and lexicographic order of s (strings) | |
return p1.i < p2.i ? 1 : p1.i > p2.i ? -1 : p1.s.compareTo(p2.s); | |
} | |
}); |
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/perl | |
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Handle; | |
use Parallel::SubFork; | |
my $manager = Parallel::SubFork->new(); |
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
int ascii_int = (int) 'a'; | |
char ascii_char = (char) 97; |
OlderNewer