Skip to content

Instantly share code, notes, and snippets.

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

Peter Taoussanis ptaoussanis

👋
Hey! Hope you're having an awesome day :-)
View GitHub Profile
@field-theory
field-theory / TUTORIAL.md
Created Oct 6, 2020
Tutorial for ptaoussanis/tempura
View TUTORIAL.md

Tutorial

This is a tutorial for https://github.com/ptaoussanis/tempura, a Clojurescript library for i18n.

Add the necessary dependency to your project:

[com.taoensso/tempura "1.2.1"]

The following walk-through assumes that you are using a REPL and have required tempura as follows:

@wavejumper
wavejumper / sente-ring-jetty9-adapter-example.clj
Last active Sep 20, 2020 — forked from ptaoussanis/sente-ring-jetty9-adapter-example.clj
Example of how to use Sente and Jetty 9 via `ring-jetty9-adapter`
View sente-ring-jetty9-adapter-example.clj
;; Example courtesy of @wavejumper
(ns sente-ring-jetty9-adapter-example
(:require [compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :as ring.defaults :refer [wrap-defaults]]
[ring.middleware.session.memory :as mem]
[ring.adapter.jetty9 :as jetty]
[taoensso.sente :as sente]
[taoensso.sente.server-adapters.jetty9 :as adapters.jetty9]))
View oget.cljs
(defn oget
"Like `aget` for JS objects, Ref. https://goo.gl/eze8hY. 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
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. **
;; ** **
@laurentpetit
laurentpetit / mutabots.clj
Last active Aug 29, 2015 — forked from cgrand/mutabots.clj
Reimplementation of transducers, in terms of processing functions instead of reducing functions. WIP.
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
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).
View murmur3.cljs
(ns murmur3
"Implementation of clojure.lang.Murmur3 in clojurescript (assuming javascript numerics).
by Francis Avila 2014-02-24")
(def imul
"32-bit signed integer multiply with overflow; alias of js/Math.imul.
Does not follow unchecked-multiply-int semantics! Only two args accepted; if
args are missing returns 0."
(if (exists? (aget js/Math "imul"))
(aget js/Math "imul")
@cemerick
cemerick / defonce.clj
Created Aug 25, 2013
`defonce` for ClojureScript
View defonce.clj
(ns whatever.cljs
(:require [cljs.compiler :refer (munge)])
(:refer-clojure :exclude (munge defonce)))
(defmacro defonce
[vname expr]
(let [ns (-> &env :ns :name name munge)
mname (munge (str vname))]
`(when-not (.hasOwnProperty ~(symbol "js" ns) ~mname)
(def ~vname ~expr))))
@ptaoussanis
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 throttle.cljs
(ns async-test.throttle.core
(:require [cljs.core.async :refer [chan close!o sliding-buffer]]
[clojure.string :as string])
(:require-macros
[cljs.core.async.macros :as m :refer [go alts!]]))
(def c (chan (sliding-buffer 1)))
(def loc-div (.getElementById js/document "location"))
(.addEventListener js/window "mousemove"
You can’t perform that action at this time.