Skip to content

Instantly share code, notes, and snippets.

@nbyouri
nbyouri / quickselect.java
Created August 20, 2017 17:14
Median in O(n)
public static int median(Vector a, int lo, int hi) {
if (lo == hi) {
return a.get(lo);
}
int n = a.size() / 2;
for (;;) {
int pivotIndex = randomPivot(lo, hi);
pivotIndex = partition(a, lo, hi, pivotIndex);
@nbyouri
nbyouri / file_stats_from_har.awk
Created November 25, 2017 14:51
Awk script to extract file statistic from a har file
function FileStats(file) {
nb_js = 0
nb_img = 0
nb_css = 0
nb_others = 0 # also html/text
nb_lines = 0
cmd = sprintf("%s %s", "jq '(.log.entries[]|[ .request.url])|@csv'", file)
while (cmd|getline) {
if (/\.png|\.jpg|\.gif/) {
nb_img++