Skip to content

Instantly share code, notes, and snippets.

@rplevy
rplevy / gist:54ba1146160be418e67d
Last active August 29, 2015 14:03
failing _validation, but _search works
curl -s -XGET 'http://localhost:9200/4af9aae4-7ec1-458d-8c50-692ddb0f2c6d/msg,file,file-info/_validate/query?explain=true' -d '{"fields":["id"],"filter":{"not":{"and":[{"numeric_range":{"msg-size":{"gte":1000}}},{"query":{"prefix":{"content-type.verbatim":"application/"}}}]}}}' | python -mjson.tool
{
"_shards": {
"failed": 0,
"successful": 1,
"total": 1
},
"explanations": [
{
"error": "org.elasticsearch.index.query.QueryParsingException: [4af9aae4-7ec1-458d-8c50-692ddb0f2c6d-0] request does not support [fields]",
cd /path/to/dir/with/Vagrantfile
VBoxManage controlvm $(cat .vagrant | awk 'BEGIN { FS = ":" } { print $3 }' | sed 's/["\}]//g') poweroff
@rplevy
rplevy / rplevy-public.txt
Last active August 29, 2015 13:57
GPG public key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - https://gpgtools.org
mQINBFM0880BEADa1RfEdG6mtWuG/0eu1Ep9waegDOLuQ6VMcZbSAkIDMzes/eWa
5VjlekM1w0Ha92CfaZ0qKFk5NJjJTZzCWAVZGJsL8NZJPBr1CcTz5xXceGh+TP3N
6qCzUacyibuupoWGYzZjdbZEL5eX4ESzH5n3S6JmAx3Ih5YkZ5AU9bvrqd4iYtZT
DSfwY7U0SE1dJIy3ufuFbySbz7SlxUmwuh7VQqv9+VFT+uXE09CAWqy0EedwjH/L
mqnJV+N7m401BWlp3ec7Jd9suEbXm2JwimXCqGaA/0isOfkJgkSopj88NNlvEr2W
JNC6rOWicN4Lw+Gjmrnb7CH6tBM2sZEC9n0MiaabE6rK0dEs21c1GcIdWiDnfi9U
;; 1. in checkouts dir, ln -s ../../clj-http .
;; 2. stick in clj-http.core/request:
(println
(str "curl -X" (.toUpperCase (name request-method)) " '"
(name scheme) "://" server-name ":" server-port uri
(or query-string "")
"' "
(reduce-kv (ƒ [r k v]
(str r " -H '" k ": " v "'")) "" headers)
@rplevy
rplevy / vinepeek.clj
Last active December 11, 2015 21:19
A non-browser-based imitation of http://vinepeek.com (play random videos from http://vine.co) in 50 lines of Clojure in the REPL. Another way in which this is different from vinepeek.com is that it doesn't repeat videos that have already been viewed (unless you restart the process). Make sure to set video-player to a video-player application tha…
(require '[cemerick.pomegranate :refer [add-dependencies]])
(add-dependencies
:coordinates '[[clj-http "0.6.3"]
[swiss-arrows "0.5.1"]]
:repositories {"clojars" "http://clojars.org/repo"})
(require '[clj-http.client :as client]
'[swiss-arrows.core :refer [-<>]]
'[clojure.string :as str]
'[clojure.java.shell :refer [sh]])
@rplevy
rplevy / two-useful-macros.clj
Created June 29, 2012 23:29
with and within
(defmacro with
"do things with the first expression passed,
and produce the result"
[expr & body]
`(let [~'% ~expr] ~@body))
(defmacro within
"do things with the first expression passed (for side effects),
but produce the value of the first expression"
[expr & body]
@rplevy
rplevy / furcula_use.clj
Created May 1, 2012 13:26
furcula example
(apply
format
"%d-%02d-%02d %02d:%02d:%02d"
(-< (doto (Calendar/getInstance)
(.setTime (Date. 112 4 17 14 15 0))
(.add Calendar/MINUTE (* 15 offset)))
(.get Calendar/YEAR)
(.get Calendar/MONTH)
(.get Calendar/DAY_OF_MONTH)
(.get Calendar/HOUR)
@rplevy
rplevy / qq.clj
Created April 24, 2012 17:25
string that can contain quotes (for reader-valid content only)
(defmacro qq [& body]
`(->>
(map (fn [s#]
(if (string? s#)
(format "\"%s\"" s#) (str s#)))
(quote ~body))
(interpose " ")
(apply str)))
(defn myfn "docstring \"the normal way\" sort of a pain" [] )
@rplevy
rplevy / furcula.clj
Created April 17, 2012 17:13
trystero furcula use case
(ns example
(:require [clojure-csv.core :as csv]
[swiss-arrows.core :refer [-<<]]))
(let [[headers rows]
((juxt (partial take 4)
(partial drop 4))
(csv/parse-csv (slurp csv-file))))]
,,,)
@rplevy
rplevy / serialize-lambda
Created March 14, 2012 20:57
possible solution to fake being able to serialize lambdas in Cascalog?
(import 'java.util.UUID)
(defn uuid-gensym [& [prefix]]
(gensym (format "%suuid%s-"
(str (when prefix (str prefix "-")))
(UUID/randomUUID))))
(defmacro mk-var [to-bind]
`(def ~(uuid-gensym) ~to-bind))