Skip to content

Instantly share code, notes, and snippets.

View arichiardi's full-sized avatar

Andrea Richiardi arichiardi

View GitHub Profile
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BACK UP YOUR LOGSEQ DIR BEFORE RUNNING THIS!
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright (C) Aug 4 2022, William R. Burdick Jr.
;;
;; LICENSE
;; This code is dual-licensed with MIT and GPL licenses.
@borkdude
borkdude / 01-README.md
Last active May 4, 2023 03:42
Shadow CLJS require ES Module in script

This shows how to require ES modules in a node script which is itself compiled as an ES module by shadow. I made this to verify if nbb's way of requiring ES modules aligns with other tools that accomplish the same using the CLJS compiler.

Build with npx shadow-cljs compile script. Run with node out/script.js. It will print something like:

#js {:columns 202, :rows 45}
[Function: Spinner]
(defonce ^Logger logger (doto (Logger/getLogger "clojure")
(.setUseParentHandlers false)
(.addHandler
(doto (ConsoleHandler.)
(.setLevel Level/ALL)
(.setFormatter
(proxy [SimpleFormatter] []
(format [^LogRecord record]
(let [sb (StringBuilder.)]
(.append sb "#:log{")
@baskeboler
baskeboler / clipboard.clj
Last active April 11, 2021 01:21 — forked from brake/clipboard.clj
Write pretty printed Clojure data structures to the clipboard
(ns clipboard.core
(:require [fipp.edn :as fipp])
(:import (java.awt.datatransfer DataFlavor Transferable StringSelection)
(java.awt Toolkit)
(java.io StringWriter))
(defn get-clipboard
"get system clipboard"
[]
(-> (Toolkit/getDefaultToolkit)
@Dangercoder
Dangercoder / auth.clj
Created November 21, 2020 18:42
Pedestal JWT authentication interceptor
(ns interceptors.auth
(:require [cheshire.core :as json]
[clojure.spec.alpha :as s]
[clojure.walk :refer [postwalk]]
[clojure.core.async :as a])
(:import (java.net URL)
(com.auth0.jwk GuavaCachedJwkProvider UrlJwkProvider)
(com.auth0.jwt.interfaces RSAKeyProvider ECDSAKeyProvider)
(com.auth0.jwt.algorithms Algorithm)
(com.auth0.jwt JWT)
@dvingo
dvingo / crux-pull.clj
Created May 5, 2020 16:22
pull api support for crux
(ns datascript-crux.pull-api
(:require
[crux.api :as crux]
[datascript.pull-parser :as dpp]
[my-app.crux-node :refer [crux-node]])
(:import [datascript.pull_parser PullSpec]))
;; lightly adapted from:
;; https://github.com/tonsky/datascript/blob/master/src/datascript/pull_api.cljc
;; https://github.com/tonsky/datascript/blob/master/src/datascript/pull_parser.cljc
@pesterhazy
pesterhazy / indexeddb-multiple-tabs.md
Created February 26, 2019 08:37
Offline-first browser apps and multiple tabs

Offline-first browser apps and multiple tabs

For offline-first operation, browser apps cache data in an IndexedDb database. When the user makes a change while offline, they persist the change optimistically. When connectivity is restored, changes are synced to the server.

This pattern is well established today. However, given the possibility of opening the app in multiple tabs at the same time, we seem to be faced with a dilemma:

  • We allow users to use the app and to make changes in multiple tabs at the same time. But then two "threads" are writing to the same shared resource at the same time. Co-ordinating writes seems to be difficult.

    To make things worse, while the localStorage API allows you to register a callback that fires whenever an item is changed outside the current tab, the IndexedDb API doesn't, at least not in a widely-available way.

@bhauman
bhauman / figwheel-simple.cljc
Last active July 4, 2019 14:14
simple figwheel
(ns figwheel.simple
(:require
[clojure.string :as string]
#?@(:cljs [[goog.object :as gobj]])
#?@(:clj [[clojure.walk :as walk]
[cljs.repl.browser :as brow]
[cljs.repl :as repl]
[cljs.env :as env]
[cljs.analyzer :as ana]
[cljs.build.api :as bapi]
@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization

Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs, and so that is what I favor. In paricular, shadow-cljs lets you install npm modules using npm or yarn and uses the resulting package.json to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.

Packaging and Delivering Code

@yannvanhalewyn
yannvanhalewyn / build.boot
Last active December 13, 2017 17:37
Boot node cljs repl
(set-env!
:target-path "target"
:source-paths #{"src"}
:dependencies '[[org.clojure/clojure "1.9.0-RC1"]
[org.clojure/clojurescript "1.9.946"]
[figwheel-sidecar "0.5.14"]])
(require '[figwheel-sidecar.repl-api :as ra])
(deftask cljs-repl []