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 / 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
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,
View oget.cljs
(defn oget
"Like `aget` for JS objects, Ref. Unlike `aget`,
returns nil for missing keys instead of throwing."
([o k] (when o (gobj/get o k nil)))
([o k1 k2] (when-let [o (oget o k1)] (gobj/get o k2 nil))) ; Optimized common case
([o k1 k2 & ks] (when-let [o (oget o k1 k2)] (apply oget o ks)))) ; Can also lean on optimized 2-case
ptaoussanis / clj-1.8.0-alpha2-tuple-perf.clj
Last active Aug 29, 2015
Clojure 1.8.0-alpha2 tuple performance
View clj-1.8.0-alpha2-tuple-perf.clj
;; LATEST UPDATE: 25 July 2015
;; ****************************************************************
;; ** NB false alarm! My original benchmarks showing large perf **
;; ** improvements with tuples turned out to be noise, **
;; ** unfortunately. Current (+more reliable) numbers seem[1] to **
;; ** show no consistent significant advantage using currently **
;; ** available tuple implementations against real-world code. **
;; ** **

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:

View mutabots.clj
(ns mutabots
"Reimplementation of transducers, in terms of processing functions instead
of reducing functions.
tl;dr: reducing-fn based transducers are a special case, influenced by reducers,
of processing-fn based transducers.
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing
concept of reducing functions.
To sum it up, a transducer has currently the signature :
ptaoussanis / CLJS-866.clj
Last active Aug 29, 2015
Faulty ns macro desugaring
View CLJS-866.clj
;; Bug report for CLJS-721 (support :include-macros true modifier in :require),
;; Ref.,
;; (GitHub commit de6ee41b3)
;; desugar-ns-specs from clojurescript/src/clj/cljs/analyzer.clj
;; (`cljs.analyzer` ns)
(desugar-ns-specs '[(:require [ :as bar :include-macros true])])
;; =>
ptaoussanis / transducers.clj
Last active Nov 18, 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 / loc-tree.clj
Created May 4, 2014
Alternative `loc-tree` strategy
View loc-tree.clj
(def ^:private loc-tree
(let [loc-tree*
(fn [loc & [unpadded?]]
(let [loc-parts (str/split (-> loc locale-key name) #"[-_]")
loc-tree (mapv #(keyword (str/join "-" %))
(take-while identity (iterate butlast loc-parts)))
loc-tree-padded (into (vec (repeat (- 3 (count loc-tree)) nil))
(if unpadded? loc-tree loc-tree-padded))))]
View reagent-component.cljs
(defn component
"Experimental! A Reagent 'component' is a (fn [& [props children this]]) that:
* May have special metadata for React lifecycle methods.
* Returns either Hiccup data, or a nested (usu. post-setup) component[1].
This util makes writing Reagent components a little more convenient:
:render (fn [node_ & cmpt-args]) -> Hiccup data, or nested component[1].
;; Additional methods optional:
:did-mount (fn [node])