Skip to content

Instantly share code, notes, and snippets.

View theronic's full-sized avatar

Petrus Theron theronic

View GitHub Profile
@theronic
theronic / map.cljs
Last active June 22, 2023 10:26
Struggling to port DrawControl React component to Reagent
(ns ui.map
#?(:cljs (:require-macros [ui.map :refer [with-reagent]]))
(:require [hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[reagent.core :as r]
#?(:cljs ["react" :as React])
#?(:cljs ["react-dom/client" :as ReactDom])
#?(:cljs ["react-map-gl" :as ReactMapGl])
#?(:cljs ["@mapbox/mapbox-gl-draw" :as MapboxDraw])))
@theronic
theronic / Map.tsx
Created June 6, 2023 11:39
Example to show why Google Maps React component does not work with Framer
// Welcome to Code in Framer
// Get Started: https://www.framer.com/docs/guides/
import Example from "https://framer.com/m/framer/Example.js@^1.0.0"
import { Map, InfoWindow, Marker, GoogleApiWrapper } from "google-maps-react"
const YOUR_GOOGLE_API_KEY_GOES_HERE = "<your API keys goes here>"
const MapContainer = (props) => {
@theronic
theronic / Dockerfile
Created May 30, 2022 16:23
Deploy Clojure to Fly.io: Efficient Multi-stage Docker build to Deploy Clojure Application to Fly.io
FROM clojure:openjdk-15-tools-deps AS builder
WORKDIR /opt
ADD deps.edn deps.edn
RUN clj -Sdeps '{:mvn/local-repo "./.m2/repository"}' -e "(prn \"Downloading deps\")"
RUN clj -e :ok
COPY . .
RUN clj -e :ok
@theronic
theronic / leandro.clj
Created December 27, 2021 07:40
Teaching Basic Clojure
(ns luandro)
(even? 3)
(apply + (filter even? (range 20)))
(->> (range 20)
(filter even?)
(defn left-pad
"Left-pads inputs with prefix up to length n (just in case String.padStart stops working one day)."
[n prefix input]
(let [s (str input)]
(str (string/join "" (repeat (- n (.-length s)) prefix)) s)))
@theronic
theronic / binary_search.clj
Last active June 18, 2020 10:47
Binary Search in Clojure
(defn binary-search
"Finds a value in a sorted seq in log(N) time."
[coll target]
(if (seq coll)
(let [half (int (/ (count coll) 2))
pivot (nth coll half nil)]
(if (= pivot target)
pivot
(if (< target pivot)
(binary-search (take half coll) target)
@theronic
theronic / xtensa-rust.md
Last active December 22, 2019 09:16 — forked from antoinevg/xtensa-rust.md
How to compile a version of Rust for the Xtensa to compile for ESP32

Like this:

# Use absolute paths, since relative paths like ~/Projects won't be expanded.

# - deps ------------------------------------------------------------------

sudo port install ninja  # or brew install ninja
cargo install xargo

- build llvm ------------------------------------------------------------

@theronic
theronic / cljs-repl.sh
Created October 11, 2018 10:53
Start ClojureScript nREPL
# I'm no longer smart enough to learn DSLs to start my favourite language REPL.
#
# If anyone from Cognitect is reading this, AFAIC this stuff is the biggest barrier to Clojure adoption.
#
# Edit your deps.edn file:
#
# {:deps {org.clojure/clojure {:mvn/version "1.9.0"}
# org.clojure/clojurescript {:mvn/version "1.10.339"}
# ;; ...other deps.
# }
@theronic
theronic / clj-nrepl.clj
Created March 1, 2018 10:01
How to start an nREPL using Clojure CLI tools using clj
$ clj -Sdeps '{:deps {org.clojure/tools.nrepl {:mvn/version "0.2.12"}}}'
Clojure 1.9.0
user=> (use '[clojure.tools.nrepl.server :only (start-server stop-server)])
nil
user=> (defonce server (start-server :port 7888))
#'user/server
;; now connect to port 7888. there's probably a way to do this in one line.
@theronic
theronic / deps.clj
Created February 28, 2018 08:00
Convert Clojure project.clj :dependencies to deps.edn style
; using Clojure 1.9
(require '[clojure.pprint :as pprint])
(defn xform-dep [[lib version & korks]]
(let [args (into {} (apply hash-map korks))]
[lib (merge {:mvn/version version} args)]))
(defn xform-deps
"deps.edn utility function by @theronic 2018-02-28
Transforms a collection of project.clj :dependencies to deps.edn style