An introduction to curl using GitHub's API.
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
| user> (use 'criterium.core) | |
| nil | |
| user> (def sites (vec (for [i (range 1000)] {:stations (vec (for [j (range 10)] [{:id (str i "-" j)}]))}))) | |
| #'user/sites | |
| user> (bench (doall (mapcat (fn [site] (map :id (:stations site))) sites))) | |
| Evaluation count : 74280 in 60 samples of 1238 calls. | |
| Execution time mean : 802.413222 µs | |
| Execution time std-deviation : 10.087328 µs | |
| Execution time lower quantile : 786.940250 µs ( 2.5%) | |
| Execution time upper quantile : 823.245990 µs (97.5%) | 
| (ns pdf2svg | |
| (:require [clojure.java.io :as io]) | |
| (:import [org.apache.pdfbox.pdmodel PDDocument PDPageable] | |
| [org.apache.batik.dom GenericDOMImplementation] | |
| [org.apache.batik.svggen SVGGeneratorContext SVGGraphics2D])) | |
| (let [document (PDDocument/load "hoge.pdf") | |
| pageable (PDPageable. document) | |
| dom-impl (GenericDOMImplementation/getDOMImplementation) | |
| svg-document (.createDocument dom-impl "http://www.w3.org/2000/svg" "svg" nil) | 
| object x { | |
| // stream a sql query | |
| def sql( str:String ):Stream[ResultSet] = withStatement { s => | |
| val rs = s executeQuery str | |
| new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream | |
| } | |
| // loan a sql statement | 
| (require '[clojure.core.async :as async :refer :all]) | |
| (defn fake-search [kind] | |
| (fn [query] | |
| (Thread/sleep (int (* (java.lang.Math/random) 1000))) | |
| (str kind " result for " query))) | |
| (def web (fake-search "Web")) | |
| (def image (fake-search "Image")) | |
| (def video (fake-search "Video")) | 
| (comment | |
| This is the easiest and most concise way of calling an external process in Java. The inheritIO methods causes the command to output stdout and errout to the same place as your current process (which most of the times is the console), no need to create mechanisms for reading asynchronously from input streams to get at the information. | |
| http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html | |
| ) | |
| (def ret (.waitFor (-> (ProcessBuilder. ["gzip" "-t" "g.txt.gz"]) .inheritIO .start))) | |
| ; nREPL 0.1.7-preview | |
| user> (use 'seesaw.core) | |
| nil | |
| user> (def myframe (frame :title "Hello" :on-close :exit)) | |
| #'user/myframe | |
| user> (import com.mxgraph.view.mxGraph) | |
| com.mxgraph.view.mxGraph | |
| user> (def mygraph (mxGraph.)) | |
| #'user/mygraph | |
| user> (defn display [content] | 
| (ns busy-cursor.core | |
| (:use seesaw.core)) | |
| (defn long-running-task | |
| [] | |
| (Thread/sleep 5000) | |
| "The result") | |
| (defn run-task-with-busy-cursor | |
| [c] | 
| ;; Generating static HTML using Clojure macros | |
| ;; It is possible to write a DSL in Clojure that generates HTML markup without the need to write a separate parser and compiler (e.g. HAML). | |
| ;; Our aim here would be to write code that converts the following Clojure code into the HTML below it | |
| ;; (html | |
| ;; (head) | |
| ;; (body | |
| ;; (h1 "An example") | 
| (ns table-test.core | |
| (:use [seesaw core table swingx])) | |
| ; A predicate that decides whether a row should be highlighted | |
| ; adapter is an instance of JXTable.TableAdapter | |
| ; http://projects.joshy.org/projects/painterreview/swingx/org/jdesktop/swingx/JXTable.TableAdapter.html | |
| (defn hl-predicate [renderer adapter] | |
| ; Highligh all rows where :age is over thirty | |
| (> (.getValueAt adapter (.row adapter) 0) 30)) | 
An introduction to curl using GitHub's API.
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin