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
getCurrentDocument = function() { | |
var doc = JSON.parse(localStorage.getItem("currentDocument")); | |
doc.__proto__ = JSONDocument.prototype; | |
return doc; | |
} |
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
"loadDocument": function (doc_id, handler ) { | |
/* | |
Calls handler with an object associated with requested document of the `doc_id` | |
The first argument of handler is error object or null depending on if error occured or not.(Like NodeJS) | |
Second argmuent is the object literal containing | |
.hash of the object is the MD5 hash of the data |
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
/* Comment next line if your implementation doesn't support TR1 | |
It will then use STL's map instead of TR1's unordered_map, | |
thus will be a little slow (map take worst case log(N) access time) | |
If you don't care about memory, the solution can be sped up using arrays | |
instead of std::map | |
*/ | |
#define TR1 | |
#include <iostream> | |
#ifdef TR1 |
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
from scipy.stats import expon | |
from scipy import cumsum,maximum,empty,insert | |
def getRandomArrivalServiceTimes(n_process, arrival_rate, service_rate): | |
time_intervals = expon.rvs(scale = 1/arrival_rate, size = n_process - 1) | |
arrival_times = insert(cumsum(time_intervals), 0, 0) | |
service_times = expon.rvs(scale = 1/service_rate, size = n_process) | |
return arrival_times, service_times | |
def mm1(arrival_times, service_times): | |
n_process = arrival_times.size |
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 random | |
def isProbablePrime(n): | |
''' | |
Miller-Rabin primality test. | |
from http://rosettacode.org/wiki/Miller-Rabin_primality_test#Python | |
''' | |
_mrpt_num_trials = 5 # number of bases to test | |
assert n >= 2 | |
# special case 2 | |
if n == 2: |
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
from operator import add, sub, le | |
def vector(operator): | |
''' | |
Apply operator to each element of vector and returns | |
the resultant vector: | |
from operator import add, sub, mul | |
vector(add)([1,2,3], [2,3,4]) => [3,5,7] | |
''' | |
return lambda A, B: map(operator, A, B) |
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
function verify_har(har) { | |
if (!har.log) { | |
return { | |
status: false, | |
errors: [ | |
'HAR file should have a logs section.', | |
], | |
}; | |
} | |
if (!har.log.entries) { |
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
function verify_har(har) { | |
if (har.log) { | |
return { | |
status: false, | |
errors: [ | |
'Too many 403 errors found', | |
], | |
}; | |
} | |
return {status: true}; |
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
function my_new_recipie(har) { | |
if (har.log.entries[0].time > 3) { | |
return { status: false, errors: ['Too big']}; | |
} | |
return {status: true}; | |
} |
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.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.FileWriter; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
URL url = new URL(args[0]); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); |