Skip to content

Instantly share code, notes, and snippets.

@rplevy
rplevy / partitions.clj
Created February 5, 2011 18:24
partitions
(defn split-from
"like split-at but with an offset.
Usage:
(split-from 5 7 (range 10)) -->
[(5 6 7) (8 9)]
"
[offset to s]
(split-at (- to (dec offset))
(second (split-at offset s))))
@rplevy
rplevy / midjefreenode-2012-02-26
Created February 27, 2012 00:06
instead of an #irc log.
18:35 *** rob`` JOIN
18:35 *** NAMES rob`` ckirkendall alexbaranosky cch1 SeanTAllen
duck1123 @devn
18:35 /part
18:35 *** rob`` PART #midje
18:36 *** rplevy JOIN
18:36 *** NAMES rplevy ckirkendall alexbaranosky cch1 SeanTAllen
duck1123 @devn
18:36 <ckirkendall> alexbaranosky: I haven't thought about
reporting at all yet. Still trying to get my
@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))
@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 / 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_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 / 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 / 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]])
;; 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 / 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