Skip to content

Instantly share code, notes, and snippets.

@pjullah
pjullah / clojurescript_notes.cljs
Last active September 16, 2021 07:26
Notes on Clojurescript
; Clojure strings are Javascript strings
(def s "This is a string")
; Can access Javascript functions, using dot-prefixed notation
(.toUpperCase s)
; To retrieve an object property
(.-length s)
; Javascript supports method-chaining. To accomplish the same in Clojurescript we would nest the function calls, or better still
@pjullah
pjullah / mysql.clj
Last active September 6, 2017 14:50
Working with MySQL in boot
(boot.core/merge-env! :dependencies '[[org.clojure/java.jdbc "x.y.z"][mysql/mysql-connector-java "x.y.z"]])
(require '[clojure.java.jdbc :as sql])
(def db-host "127.0.0.1")
(def db-port 3306)
(def db-name "cmdb")
(def db-user "root")
(def db-password "my-secret-pw")
@pjullah
pjullah / tmux.sh
Created September 5, 2017 15:23
tmux
ctrl-b
d - detach
@pjullah
pjullah / ring.clj
Created July 13, 2017 16:13
Example of ring middleware
(defn one
[handler]
(println "handler one")
(fn [request]
(println "request one")
(handler request)))
(defn two
[handler]
(println "handler two")
shift P # paste before cursor position
v # select range of text
# comment a visual selection
ctrl-v
select lines
shift-i
type character
esc - wait a second
@pjullah
pjullah / clojure_notes.clj
Last active July 4, 2017 12:00
Notes about Clojure
;; Lots of Clojure - http://matthiasnehlsen.com/
; best explanation of apply vs map - http://stackoverflow.com/questions/2311528/clojure-apply-vs-map
(apply F [1 2 3 4 5])
;translates to
(F 1 2 3 4 5)
(map F [1 2 3 4 5])
;translates to
[(F 1) (F 2) (F 3) (F 4) (F 5)]
@pjullah
pjullah / n.clj
Last active June 20, 2017 10:08
Notes of Clojure function usage
; construct a map, using the keys from one vector, and the values from another
(zipmap keys vals)
@pjullah
pjullah / generate_csv.bash
Created June 12, 2017 16:12
Generate some CSV data for testing
for i in {1..999}; do printf '%s\n' "row ${i}" "2011-03-11" ${i} true | paste -sd "," - ; done > data.csv
@pjullah
pjullah / vim_fireplace_cheat_sheet.md
Created June 8, 2017 09:56
Cheat sheet for vim fireplace

fireplace

  • cpr => (require ... :reload)
  • cpR => (require ... :reload-all)

Evaluation

  • :Eval (clojure code) => runs (clojure code) in repl
  • cpp => evaluate inn-most expessions under cursor
  • cp<movement> => evaluate text described by <movement>
  • cqp => opens quasi-repl
  • cqc => quasi-repl command line window
@pjullah
pjullah / chapter_3.clj
Created May 23, 2017 13:57
The Little Schemer
(ns the-little-schema.core)
;;; Chapter 3 - Cons the magnificent
;; 1. Always ask null? as the first question in expressing any function
;; 2. Use cons to build lists
;; 3. When building a list, describe the first typical
;; element, and then cons in onto the natural recursion