Skip to content

Instantly share code, notes, and snippets.

View ikitommi's full-sized avatar
💭

Tommi Reiman ikitommi

💭
View GitHub Profile
@lokori
lokori / ring-request-wrapper
Created November 27, 2013 11:29
Example of logging a Ring request with Ring. (I'm aware there are some existing alternatives for doing this.)
(ns aitu.infra.print-wrapper
(:require [clojure.tools.logging :as log]))
(def ^:private requestid (atom 1))
(defn http-method->str [keyword-or-str]
(clojure.string/upper-case (name keyword-or-str)))
(defn log-request-wrapper [ring-handler]
"Logging wrapper. Basic info + duration and additional unique id per request to enable performance analysis"
@Deraen
Deraen / knockout-selectize.js
Last active August 29, 2015 13:57
Knockout + Selectize.js
// Use
// ko.bindingHandlers.fooSearch = createAutocomplete({load: ...});
// viewModel.idHere = "123";
// viewModel.objHere = {_id: "123", name: "foo"};
// viewModel.objHere.subscribe(function(val) { ... selected obj! ... });
//
// <input type="text" data-bind="value: idHere, fooSearch: objHere"/>
function createAutocomplete(override) {
return {
(require '[schema.core :as s])
(require '[schema.coerce :as coerce])
(require '[schema.utils :as utils])
(defn filter-schema-keys
[m schema-keys extra-keys-walker]
(reduce-kv (fn [m k v]
(if (or (contains? schema-keys k)
(and extra-keys-walker
(not (utils/error? (extra-keys-walker k)))))
@Deraen
Deraen / components.clj
Last active December 15, 2019 08:03
Compojure-api with Component
(ns foobar.components
(:require [com.stuartsierra.component :as component]
[compojure.api.sweet :refer :all]))
(defmethod compojure.api.meta/restructure-param :components
[_ components acc]
(update-in acc [:letks] into [components `(::components ~'+compojure-api-request+)]))
(defn wrap-components [handler components]
(fn [req]
@bhauman
bhauman / core.cljs
Last active August 16, 2022 12:08
Helpful patterns when developing with ClojureScript Figwheel and Express js
(ns todo-server.core
(:require
[cljs.nodejs :as nodejs]
[figwheel.client :as fw]))
(nodejs/enable-util-print!)
(defonce express (nodejs/require "express"))
(defonce serve-static (nodejs/require "serve-static"))
(defonce http (nodejs/require "http"))
@Deraen
Deraen / silk-data.cljs
Last active August 29, 2015 14:27
Additional data to Silk routes
(deftype AdditionalData [data]
silk/Pattern
(-match [_ _]
data)
(-unmatch [_ _]
nil)
(-match-validator [_]
(constantly true))
(-unmatch-validators [_]
{}))
@Deraen
Deraen / rekekkonen.cljs
Created August 18, 2016 10:58
Kekkonen + Re-frame
(reg-event-fx :get-current-party
(fn [{:keys [db]} _]
{:db (assoc db :loading? true)
:kekkonen {:query :api.party/get-current-party
;; called with the body
:on-success [:set-current-party]
;; or simple assoc-in?
:on-success [:assoc-in [:current-party]]
}}))
@swannodette
swannodette / inference.md
Last active August 7, 2023 16:13
Externs Inference

Externs Inference

Integrating third party JavaScript libraries not written with Google Closure Compiler in mind continues to both be a source of error for users when going to production, and significant vigilance and effort for the the broader community (CLJSJS libraries must provide up-to-date and accurate externs).

In truth writing externs is far simpler than most users imagine. You only need externs for the parts of the library you actually intend to use from ClojureScript. However this isn't so easy to determine from Closure's own documentation. Still in the process of writing your code it's easy to miss a case. In production you will see the much dreaded error that some mangled name does not exist. Fortunately it's possible to enable some compiler flags :pretty-print true :pseudo-names true to generate an advanced build with human readable names. However debugging missing externs means compiling your production build for each missed case. So much time wasted for such simple mistakes damages our sen

@gfredericks
gfredericks / bijections.clj
Created March 19, 2018 17:07
Half a draft of bijections in clojure
(ns user.bijections
(:refer-clojure :exclude [-> comp update])
(:require [clojure.core :as core]
[clojure.set :as set])
(:import (java.util UUID)))
;;
;; Motivation:
;;
;; - avoid the edge cases inherent in allowing multiple

State of Clojure Survey 2018 - Open comment question

This is a selection of the most articulated critique found in the open comments section Q25 at the bottom of the survey. Recurring themes are:

  1. Elitism, ivory tower, "not smart enough to get it" attitude of frequent speaker or early adopters.
  2. Poor basic documentation, error messages, beginner friendly resources.
  3. Fear of contribution (with reasons like a. community-built tools open to attack and replacement by core team b. hostile contribution environment c. closed development process)
  • The community has to grow to create more opportunities. Many organizations don't want to even consider using it because they fear not being able to find Clojure developers. Unless you have a mentor or are extremely motivated, Clojure scares away most imperative developers. My suggestions is to team up with a university and get a Clojure course on Coursera or a similar platform. This is the only way I got in