Skip to content

Instantly share code, notes, and snippets.

@Deraen
Deraen / README.md
Last active July 10, 2017 22:04
WIP: Cljs foreign-lib requires brain dump

Problem

Currently libraries need to write some logic to load JS libraries from various places. For example Reagent supports:

  1. (Default) Cljsjs packages which export js/React, js/ReactDOM, js/ReactDOMServer and js/createReactClass
  2. Npm packages, with require when using Node target

Because the default is Cljsjs, Reagent namespaces depend on cljsjs namespaces like cljsjs.react. This means that to use Reagent with option 2. requires creating empty stub namespaces that provides these.

@Deraen
Deraen / README.md
Last active July 5, 2017 19:12
cljs-oss CI setup
  1. One process for building Cljs and pushing resulting jar somewhere
  2. Process for each OS project for running tests against the jar
  3. One repo to save the build results

Builds can be triggered (in addition to commits to the repo), by Travis cron daily, or with HTTP endpoint called by other builds, in other projects: https://docs.travis-ci.com/user/triggering-builds/

clojure/clojurescript would trigger process (cljs-oss/clojurescript) to build the new jar file.

@Deraen
Deraen / readme.md
Last active July 5, 2017 12:31
CLJS-2143

Option 1.

https://github.com/Deraen/clojurescript/commit/bb94e566a8827d0356740491e2506fba02faa109

  • Load all js_transform.clj files in classpath
  • Problems:
    • files are not real namespaces (no ns)
    • load-reader will eval the code in file each time load-js-transforms! is called, which is each time cljs.closure/build is called
    • a js_transform.clj file is loaded even if js-transforms method from it is not needed
  • for example, if any lib in classpath has dep on cljsjs/babel-standalone
@Deraen
Deraen / build.clj
Created April 26, 2017 17:05
boot_static.clj
(ns site.build
(:require [boot.core :as boot]
[boot.pod :as pod]
[boot.util :as util]
[clojure.string :as string]
[clojure.java.io :as io]
[clojure.tools.namespace.dir :as dir]
[clojure.tools.namespace.track :as track]
[clojure.tools.namespace.reload :as reload]))
@Deraen
Deraen / test.clj
Created January 27, 2017 22:41
Proof of Concept, catch test output
(defonce ^:private log-buffer (atom nil))
(defn get-log-message []
(let [message (first @log-buffer)]
(swap! log-buffer #(vec (rest %)))
message))
(defn catch-logging [f]
(reset! log-buffer nil)
@Deraen
Deraen / closure_import_script.cljs
Created December 20, 2016 21:43
Queue without Core.async
(defonce reloader (atom {:deferred nil
:queue []}))
(declare maybe-load-next)
(defn ready [state next]
(next (assoc state :deferred nil)))
(defn load-next [state]
(let [[file & queue] (:queue state)
@Deraen
Deraen / example.clj
Last active October 27, 2016 16:28
Finding Clojure functions doing slow IO
(defn slow1 [] (Thread/sleep 500))
(defn slow2 [] (slow1) (slow1))
(defn example [] (slow1) (slow2))
(profile-calls {:vars [#'slow1 #'slow2]} default-profile example)
;; Calling backend.main/slow1 took 500
;; Calling backend.main/slow1 took 500
;; Calling backend.main/slow1 took 500
(defn humanize-duration [ms]
(let [seconds (/ ms 1000)
minutes (/ seconds 60)
hours (/ minutes 60)
days (/ hours 24)
;; From Moment, 400 years = 146097 days = 4800 months
months (/ (* days 4800) 146097)
years (/ months 12)]
(cond
(< seconds 45) [:ss seconds]
@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]]
}}))
@Deraen
Deraen / README.md
Last active August 10, 2016 10:44
Use project-name to generate IP's for vagrant boxes

Why

  • Static IPs with Vagrant clash easily with other projects
  • Dynamic IPs require using port forwards -> port forwards clash with local apps and other projects
  • Solution: Provide static IP which are calculated from project name, and then use vagrant-hostupdater to add name -> IP to hosts files for easy use
  • Uses 20 first bits from MD5 hash of the name to build IPv4 in Class B private network (smaller addres space than Class A, but rarely used)