Skip to content

Instantly share code, notes, and snippets.

@MattSegal
MattSegal / http.js
Created November 27, 2018 02:08
HTTP API Boilerplate for ES5 JavaScript + Django
import Cookies from 'universal-cookie'
// Get Django cross site request forgery cookie for API requests.
const getCSRF = () => new Cookies().get('csrftoken')
// HTTP helper functions.
const http = {
// POST a JSON to URL (create new resource)
post: (url, data) =>
fetch(url, {
@beders
beders / mini-promise.cljc
Last active January 26, 2022 22:18
Super minimal macro to simplify dealing with promise/async/await code in ClojureScript
(defn create-function-call [param expr]
"Create an sexp for calling expr with a first argument provided by a promise.
If expr is a list (already in form suitable for a function call), insert the first argument at second position,
otherwise turn expr into a function call expression, unless the function is an fn, which is simply returned.
println -> (fn [param] (println param))
(* 2) -> (fn [param] (* param 2))