Skip to content

Instantly share code, notes, and snippets.

Hey! Hope you're having an awesome day :-)

Peter Taoussanis ptaoussanis

Hey! Hope you're having an awesome day :-)
View GitHub Profile
ptaoussanis / transducers.clj
Last active Oct 25, 2020
Quick recap/commentary: Clojure transducers
View transducers.clj
(comment ; Fun with transducers, v2
;; Still haven't found a brief + approachable overview of Clojure 1.7's new
;; transducers in the particular way I would have preferred myself - so here goes:
;;;; Definitions
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as:
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation
;; (The `[]` arity is actually optional; it's only used when calling
;; `reduce` w/o an init-accumulator).
ptaoussanis / sente-ring-jetty9-adapter-example.clj
Last active Jul 29, 2020
Example of how to use Sente and Jetty 9 via `ring-jetty9-adapter`
View sente-ring-jetty9-adapter-example.clj
;; Please see

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

ptaoussanis / free-port.clj
Created Dec 14, 2012
A little utility to allow simple redeployment of Clojure web servers with zero downtime, and without the need for a proxy or load balancer. Just wrap any port-binding calls, and the utility will auto kill pre-existing servers as necessary. *nix only. Based on the blog post by Feng Shen,
View free-port.clj
;; (require '[clojure.string :as str] '[ :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."
[port bind-port!-fn & {:keys [max-attempts sleep-ms]
ptaoussanis /
Created Feb 26, 2016 — forked from bgrins/
Prevent errors on console methods when no console present and expose a global 'log' function.

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,
rediscli=`which redis-cli`
s3cmd=`which s3cmd`
lsave=`$rediscli lastsave`
echo "LASTSAVE $lsave"
saved="`$rediscli config get dir | xargs | cut -d ' ' -f 2`/`$rediscli config get dbfilename | xargs | cut -d ' ' -f 2`"
$rediscli bgsave
while [ $lsave -eq `$rediscli lastsave` ]; do
View externs_for_cljs.clj
(ns n01se.externs-for-cljs
(:require [ :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
ptaoussanis / more-ifs.clj
Created Jul 31, 2013
Some `if`/`when` helpers. Don't need these often (and avoid them whenever possible), but they're occasionally handy when dealing with particularly hairy code.
View more-ifs.clj
(defmacro iff [test & {:keys [then else]}] `(if ~test ~then ~else))
(comment (iff false
:then (println "true")
:else (println "false")))
(defmacro iff-let [bindings & {:keys [then else]}] `(if-let ~bindings ~then ~else))
(comment (iff-let [x true] :else "false" :then x))
(defmacro if-lets
"Like `if-let` but binds multiple values iff all tests are true."
View singpool.clj
;;; First we'll define a new kind of (degenerate) connection pool to encapsulate the behavior you want:
(defrecord SingletonPool [conn] ; Keeps a single connection atom
(get-conn [_ spec]
(or (when-let [c @conn] (when (conn-alive? c) c)) ; Aliveness check may not be necessary
(println "making a new conn!")
(reset! conn (make-new-connection spec))))
(release-conn [_ _] nil)
(release-conn [this _ _] nil)
View externs_for_cljs.clj
(ns n01se.externs-for-cljs
(:require [ :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
You can’t perform that action at this time.