Skip to content

Instantly share code, notes, and snippets.

View atroche's full-sized avatar

Alistair Roche atroche

View GitHub Profile
FileReader fileReader = new FileReader("ten.json");
BufferedReader bufReader = new BufferedReader(fileReader);
int lines = 0;
while (bufReader.readLine() != null) {
lines++;
}
System.out.println(lines);
(reduce +
(pmap (fn [fname]
(with-open [rdr (io/reader fname)]
(count-lines rdr)))
["xaa" "xab" "xac" "xad"])) ;; 2.5gb JSON files
(ns sunshine.widefinder
(:import (java.io BufferedInputStream InputStreamReader BufferedReader RandomAccessFile FileInputStream File)))
(defn chunk-file
"Partitions a file into n line-aligned chunks. Returns a list of start and
end byte offset pairs."
[filename n]
(with-open [file (RandomAccessFile. filename "r")]
(let [offsets (for [offset (range 0 (.length file) (/ (.length file) n))]
(do (when-not (zero? offset)
#include <stdio.h>
#include <fcntl.h>
#include <err.h>
#include <unistd.h>
#include <inttypes.h>
#define BUF_SIZE (1048576 * 10)
int main(int argc, char *argv[])
{
(with-open [file-stream (FileInputStream. ten-gb-filename)]
(let [channel (chan 500)
;; make four workers to read byte arrays off the channel:
counters (for [_ (range 4)]
(go-loop [newline-count 0]
(let [barray (async/<! channel)]
(if (nil? barray) ;; channel is closed
newline-count
(recur (+ newline-count
(count-newlines barray)))))))]
(defn count-newlines [^bytes barray]
(let [num-bytes (alength barray)]
(loop [i 0
newlines 0]
(if (>= i num-bytes)
newlines
(if (= 10 (aget ^bytes barray i))
(recur (inc i)
(inc newlines))
(recur (inc i)
(ns sunshine.disk-read
(:require [clojure.core.async :as async :refer [>! <! go-loop chan close! <!!]]])
(:import (java.io BufferedReader FileReader FileInputStream BufferedInputStream InputStreamReader)))
(def ten-gb-filename "ten.json")
(def one-meg (* 1024 1024))
(defn ^FileInputStream input-stream [^String fname]
(FileInputStream. fname))
mdworker 20036
DashlaneAgent 24287
tmux 30025
fish 36820
WindowServer 43246
dtrace 48262
coreaudiod 48714
hidd 86578
iTerm2 102152
Google Chrome He 365060
sudo dtrace -o syscalls_by_process.txt -n 'syscall:::entry { @num[execname] = count(); }' &
sleep 60*10 && jobs -p|tail -1|xargs sudo kill
onion_address = "http://facebookcorewwwi.onion"
local_tor_proxy_address = "socks5://127.0.0.1:9050"
requests.get(onion_address, {}, proxies={"http": local_tor_proxy_address,
"https": local_tor_proxy_address})