Skip to content

Instantly share code, notes, and snippets.

@sonwh98
sonwh98 / dns.clj
Last active May 23, 2021 08:26
parses ip address from ipconfig and generates url to update google hosted dynamic dns
(require '[clojure.java.shell :refer [sh]]
'[clojure.string :as string])
(let [out (:out (sh "ifconfig"))
wifi-device "wlp0s20f3"
@sonwh98
sonwh98 / init.el
Last active July 13, 2018 17:14
emacs init.el for clojure development
(require 'package) ;; You might already have this line
;;instructions at setting up a clojure/clojurescript development environment at http://lambdakids.stigmergy.systems/2018/6/6/hello-world.blog
(add-to-list 'package-archives (cons "melpa-stable" "https://stable.melpa.org/packages/") t)
(add-to-list 'load-path "~/.emacs.d/lisp")
;;download doremi at https://www.emacswiki.org/emacs/DoReMi
(load "doremi.el")
(load "doremi-cmd.el")
@sonwh98
sonwh98 / cube.cljs
Created December 27, 2017 21:16
clojurescript rotating cube with three.js
(ns red.cube
(:require [cljsjs.three]))
(defn draw-cube []
(let [scene (js/THREE.Scene.)
camera (js/THREE.PerspectiveCamera. 75 (/ js/window.innerWidth js/window.innerHeight) 0.1 1000)
renderer (js/THREE.WebGLRenderer. #js{:antialias true})
geometry (js/THREE.BoxGeometry. 1 1 1)
material (js/THREE.MeshBasicMaterial. #js{:color "#433F81"})
cube (js/THREE.Mesh. geometry material)
@sonwh98
sonwh98 / core-async-bug.cljs
Created September 24, 2015 16:09
sub pub blocks subscriber from recieving messages when there is more than one subscriber to a topic
(require-macros '[cljs.core.async.macros :refer [go go-loop]])
(require '[cljs.core.async :refer [put! <! >! chan pub sub unsub]])
(defonce message-bus (chan))
(defonce message-publication (pub message-bus (fn [msg]
(if (vector? msg)
(first msg)
:no-topic))))
(def s1 (chan))
@sonwh98
sonwh98 / wrapper.cljs
Last active August 29, 2015 14:27
the clojure datomic/datascript api functions require passing in the db as a value. this gets tedious. Wrap these functions to use the current db
(defn q [& params]
"wrapper around d/q so that you don't have to pass in the database everytime"
(let [query (first params)
query+conn (conj [query]
@db)
variable-bindings (rest params)
params2 (vec (concat query+conn variable-bindings))]
(apply d/q params2)))
(defn transact! [datoms]
@sonwh98
sonwh98 / gist:980e7798ccfc0f1e84ad
Created January 4, 2015 00:45
implicit conversion of Scala String and Symbol to transit com.cognitect.transit.Keyword
import com.cognitect.transit.Keyword
import com.cognitect.transit.impl.KeywordImpl
implicit class ClojureKeyword(val sc:StringContext) extends AnyVal{
def k(args: Any*):KeywordImpl = {
val s = sc.raw(args.toSeq : _*)
new KeywordImpl(s)
}
}
@sonwh98
sonwh98 / with-db-id
Last active August 29, 2015 14:11
inserting :db/id key recursively into a map to be transacted to datomic
(defn with-db-id [m]
(let [m-with-db-id (into m {:db/id (temp-id)})
result (for [[k v] m-with-db-id :let [type-v (type v)]]
(if (or (= type-v clojure.lang.PersistentArrayMap)
(= type-v clojure.lang.PersistentHashMap))
(let [v-with-db-id (into v {:db/id (temp-id)})]
{k (with-db-id v-with-db-id)})
(if (or (= type-v clojure.lang.IteratorSeq)
(= type-v clojure.lang.PersistentHashSet))
{k (map #(with-db-id %) v)}