Skip to content

Instantly share code, notes, and snippets.

Avatar

Petrus Theron theronic

View GitHub Profile
@theronic
theronic / Dockerfile
Created May 30, 2022
Deploy Clojure to Fly.io: Efficient Multi-stage Docker build to Deploy Clojure Application to Fly.io
View Dockerfile
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 Dec 27, 2021
Teaching Basic Clojure
View leandro.clj
(ns luandro)
(even? 3)
(apply + (filter even? (range 20)))
(->> (range 20)
(filter even?)
View left-pad.cljs
(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 Jun 18, 2020
Binary Search in Clojure
View binary_search.clj
(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 Dec 22, 2019 — forked from antoinevg/xtensa-rust.md
How to compile a version of Rust for the Xtensa to compile for ESP32
View xtensa-rust.md

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 Oct 11, 2018
Start ClojureScript nREPL
View cljs-repl.sh
# 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 Mar 1, 2018
How to start an nREPL using Clojure CLI tools using clj
View clj-nrepl.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 Feb 28, 2018
Convert Clojure project.clj :dependencies to deps.edn style
View deps.clj
; 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
View advanced.js
#!/usr/bin/env node
if(typeof Math.imul == "undefined" || (Math.imul(0xffffffff,5) == 0)) {
Math.imul = function (a, b) {
var ah = (a >>> 16) & 0xffff;
var al = a & 0xffff;
var bh = (b >>> 16) & 0xffff;
var bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
@theronic
theronic / osx_install.sh
Last active Jul 24, 2017 — forked from t-io/osx_install.sh
Install most of my Apps with homebrew & cask
View osx_install.sh
#!/bin/sh
echo Install all AppStore Apps at first!
# no solution to automate AppStore installs
read -p "Press any key to continue... " -n1 -s
echo '\n'
echo Install and Set San Francisco as System Font
ruby -e "$(curl -fsSL https://raw.github.com/wellsriley/YosemiteSanFranciscoFont/master/install)"
echo Install Homebrew, Postgres, wget and cask
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"