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
(set 'cleanmode 1) | |
(defun toggle-cleanmode () | |
"toggles clean mode" | |
(interactive) | |
(cond ((not cleanmode) | |
(menu-bar-mode -1) | |
(tool-bar-mode -1) | |
(scroll-bar-mode -1) | |
(set 'cleanmode 1)) | |
((eq 1 cleanmode) |
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 urllib.request | |
address = 'http://apod.nasa.gov/apod/astropix.html' | |
file = urllib.request.urlopen(address) #read in the site and hunt for the image url | |
html = file.read() | |
data = html.decode('utf-8') | |
#print (data) | |
s = data.find("<a href=\"image")+14 #find the first instance of the image hyperlink |
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
(ns chan-test.core | |
(:gen-class) | |
(:require [clojure.core.async :as async] | |
[kuroshio.core :as k])) | |
(defn create-string [] | |
(apply str (take 10000 (repeat ".\r\n")))) | |
(defn println-err [& args] | |
(binding [*out* *err*] |
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
(defn gen-graph [s] | |
(graph ;;generate loom graph | |
(reduce merge {} ;; format... | |
(apply concat ;; for loom | |
(for [r (range s)] ;;for each row | |
(for [c (range s)] ;;for each column in the row | |
(let [nl [[r (+ 1 c)] | |
[(- r 1) c] | |
[r (- c 1)] | |
[(+ 1 r) c]]] |
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
(defn v-> [s v] | |
"pushes value onto stack, if possible, returns new head/tail" | |
(let [p (promise)] | |
(if (deliver s (cons v (list p))) | |
p))) | |
(defn v<- [s] | |
"returns lazy sequence of actual values, without head/tail" | |
(when (realized? s) | |
(cons (first @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
(import 'java.util.concurrent.LinkedBlockingQueue) | |
(use 'criterium.core) | |
(defn lbq-test [] | |
(let [q ^LinkedBlockingQueue (LinkedBlockingQueue.)] | |
(.start(Thread. #(dotimes [n 50000] (.take q)))) | |
(.start(Thread. #(dotimes [n 50000] (.take q)))) | |
(.start(Thread. #(dotimes [n 50000] (.take q)))) | |
(.start(Thread. #(dotimes [n 1000000] (.add q 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
(let [i 128900, b (map #(unchecked-byte(bit-shift-right i (* % 8))) (range 0 4))] | |
{i (reduce +(map #(bit-shift-left (bit-and %1 255) (* %2 8)) b (range 0 4)))}) |
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
(defn- bits-lit [b] | |
"cerates seq of bits that are flagged" | |
(map #(bit-and b (bit-shift-left 1 %)) (range 8))) | |
(bits-lit 23) ;;(1 2 4 0 16 0 0 0) | |
(map pos? (bits-lit 23)) ;; (true true true false true false false false) |
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
(defn get-chunk [conn buf] | |
"returns map of bytes and size of buffer for data recieved in stream (buffered input stream); | |
buf would be something like: (make-array Byte/TYPE 4096)" | |
(let [bufsize (.read conn buf)] ;;blocking | |
{:size bufsize :data buf})) | |
(defn- ws-decode [frame] | |
"decodes websocket frame" | |
(let [data (:data frame) |
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
(def clients (atom {})) | |
(defn remove-client [ch] (close ch)(swap! clients dissoc ch)) | |
(defn purge-clients! [] | |
(doseq [c @clients] | |
(if (> (- (.getTime (java.util.Date.)) (.getTime (:last-seen (val c)))) 60000) | |
(remove-client (key c))))) |