By Scott Adams
We’ve won the war on boredom! If you have a smartphone in your pocket, a game console in the living room, a Kindle in your backpack and an iPad in the kitchen, you never need to suffer a minute without stimulation. Yay!
{ | |
"size": 10, | |
"from": 0, | |
"query": { | |
"filtered": { | |
"filter": { | |
"or": [{ | |
"term": { | |
"publish_id": "1" | |
} |
By Scott Adams
We’ve won the war on boredom! If you have a smartphone in your pocket, a game console in the living room, a Kindle in your backpack and an iPad in the kitchen, you never need to suffer a minute without stimulation. Yay!
;; Example: | |
;; (doseq-indexed idx [name names] | |
;; (println (str idx ". " name) | |
(defmacro doseq-indexed [index-sym [item-sym coll] & body] | |
`(let [idx-atom# (atom 0)] | |
(doseq [~item-sym ~coll] | |
(let [~index-sym (deref idx-atom#)] |
;; (require '[clojure.string :as str] '[clojure.java.shell :as shell] '[taoensso.timbre :as timbre]) | |
(defn with-free-port! | |
"Attempts to kill any current port-binding process, then repeatedly executes | |
nullary `bind-port!-fn` (which must return logical true on successful | |
binding). Returns the function's result when successful, else throws an | |
exception. *nix only. | |
This idea courtesy of Feng Shen, Ref. http://goo.gl/kEolu." | |
[port bind-port!-fn & {:keys [max-attempts sleep-ms] |
This is a handy bit of code I've written more than once. I thought I'd throw it in here so I can refer back to it later. Basically, it lets you read a config file to produce a Clojure map. The config files themselves can contain one or more forms, each of which can be either a map or a list. Maps are simply merged. Lists correspond to invocations of extension points, which in turn produces a map, which is merged along with everything else.
Consider the following files:
names.edn
-- Open a SQLite shell by issuing the command below | |
-- sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* | |
select LSQuarantineDataURLString from LSQuarantineEvent order by LSQuarantineTimeStamp asc limit 1; | |
-- For me, it's GNU Emacs. | |
-- sqlite> select LSQuarantineDataURLString from LSQuarantineEvent order by LSQuarantineTimeStamp asc limit 1; | |
-- http://bandwidth.porkrind.org/emacs-builds/Emacs-24.2-universal-10.6.8.dmg |
(ns ^{:doc "Word frequencies in a text file." | |
:author "Baishampayan Ghose <[email protected]>"} | |
meetup.freq | |
(:require [clojure.java.io :as io] | |
[clojure.string :as s])) | |
(def stop-word? #{"is" "the" "am" "i" "that" "if"}) ;; fill it up! | |
;;; all these functions are written in a "point free" style | |
(def get-lines (comp line-seq io/reader)) |
(ns ^{:doc "Read Java properties file." | |
:author "Baishampayan Ghose <[email protected]>"} | |
in.freegeek.props | |
(:import java.util.Properties) | |
(:require [clojure.java.io :refer [resource reader]] | |
[clojure.string :refer [split]])) | |
(defn- load-props | |
"Load a Java properties file. File should be in classpath." | |
[props-file] |
(ns props.core | |
(:require [clojure.string :refer [split]] | |
[clojure.java.io :refer [reader]]) | |
(:import java.util.Properties)) | |
(defn- split-key | |
"Split a string key to its subparts. | |
foo -> [foo] | |
foo.bar.baz -> [foo bar baz]" |
; STM history stress-test | |
(defn stress [hmin hmax] | |
(let [r (ref 0 :min-history hmin :max-history hmax) | |
slow-tries (atom 0)] | |
(future | |
(dosync | |
(swap! slow-tries inc) | |
(Thread/sleep 200) | |
@r) |