Skip to content

Instantly share code, notes, and snippets.

@philjackson
philjackson / compojure.clj
Last active July 27, 2023 13:17
Sensible compojure/ring defaults for an API
(ns my-api.handler
(:require [compojure.core :refer :all]
[ring.util.response :refer [response status content-type]]
[ring.middleware.params :refer [wrap-params]]
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.json :refer [wrap-json-response wrap-json-body]]))
(defroutes app-routes
(context "/v1" []
(GET "/" req

Derivatives

A note on terminology: There are a lot of things with similar meanings/use-cases around: subscriptions, reactions, derived atoms, view models. I'll introduce another to make things even worse: derivative. A derivative implements IWatchable and it's value is the result of applying a function to the value of other things (sources) implementing IWatchable. Whenever any of the sources change the value if the derivative is updated.

Why this library

Let's assume you're hooked about the idea of storing all your application state in a single atom (db). (Why this is a great idea is covered elsewhere.)

Most of your components don't need the entirety of this state and instead receive a small selection of it that is enough to allow the components to do their job. Now that data is not always a subtree (i.e. (get-in db ...)) but might be a combination of various parts of your state. To transform the data in a way that it becomes useful for components you can use a function: `(f @

@ohanhi
ohanhi / joy-of-composition.md
Last active May 6, 2024 05:21
The Joy of Composition - Why stateless rendering is pure bliss

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star ⭐ the Gist - the amount of stars decides whether it makes the cut!

The Joy of Composition

Why stateless rendering is pure bliss

React just got stateless components, meaning that they are in essence pure functions for rendering. Pure functions make it dead simple - even fun - to refactor your views

@martinklepsch
martinklepsch / client.clj
Last active November 26, 2023 20:36
A minimal Clojure client for Airtable.com's HTTP API.
(ns oxygen.client
"A minimal Clojure client for Airtable.com's HTTP API.
Supports retrieval of whole tables as well as individual records.
Dependencies: [org.clojure/data.json \"0.2.6\"] [clj-http \"2.0.0\"]"
(:require [clojure.data.json :as json]
[clojure.string :as string]
[clojure.set :as set]
[clj-http.client :as client]))
(def api-base "https://api.airtable.com/v0")
@jraines
jraines / quiz.cljs
Created August 4, 2015 19:50
Attempt to do a kinda sorta redux like app in ClojureScript
(ns ^:figwheel-always ramquiz.core
(:require [quiescent.core :as q]
[quiescent.dom :as d]))
(enable-console-print!)
(declare render-app)
;; the data
@mhuebert
mhuebert / cljs-js-analysis-cache-usage.md
Last active September 9, 2020 11:59
Using existing namespaces from cljs.js

Let's say you want to use cljs.js to eval code using functions declared in your project.

Expressions that only use core functions are simple to evaluate:

(ns foo.try-eval
  (:require [cljs.js :as cljs]))

(def compiler-state (cljs/empty-state))
@jstaffans
jstaffans / clojured_2015.md
Last active August 29, 2015 14:14
ClojureD notes

Notes from ClojureD 24.1.2015

Albrecht Schmidt: "Start your engine: My Clojure Bot in the Hello World Open 2014"

  • Hello World Open: programming contest organised by Reaktor and Supercell with ~2500 teams, worldwide distribution
    • Client-server car race, cards driven with some parameters such as decelerate/accelerate, change lanes
    • Organisers provided test server with simple testing UI
  • Parameters for car are quite simple: current angle, position etc
  • Clojure works well for processing simple data structures like this - analysis, storing, examining
  • Used Incanter to plot bot data during test (throttles vs. angles)
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@gtebbutt
gtebbutt / gist:5e21f2e49592559f5043
Created December 19, 2014 14:17
Linear animation generator for Om & React
(defn animate-value
[start-val end-val duration]
(let [decrement? (< end-val start-val)
transmit-chan (chan)
cancel-chan (chan)
animation-interval 40 ;40 ms interval - 25fps
steps (/ duration animation-interval)
full-range (- start-val end-val)
per-step (util/abs (/ full-range steps))
state (atom start-val)
@tkafka
tkafka / LICENSE.txt
Last active May 17, 2024 02:08
Drop-in replacement for ReactCSSTransitionGroup that uses velocity.js instead of CSS transforms. Add your own transitions to `transitions` hash.
The MIT License (MIT)
Copyright (c) 2014 Tomas Kafka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: