Slack:
Installing leiningen
- get java installed first - http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html
- then download lein -
wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
lein
Running Tests
in the REPL
(use 'clojure.test)
(use 'foo.core-test)
(run-tests 'foo.core-test)
http://stackoverflow.com/questions/21294294/run-tests-from-clojure-repl-and-leiningen
It may be more proper to say:
(require '[clojure.test :refer [run-tests]])
...but that's annoyingly long.
GOAL
Collect tips on using Clojure more effectively.
The main practical reason I'm going to study Clojure is so that I can implement the ground
forum system.
That means I need to really understand Datomic.
My secondary goal is to get paid work using Clojure.
lein-try
https://github.com/rkneufeld/lein-try
lein try seesaw
lein try seesaw 1.4.5
lein try clj-time
then
(require '[clj-time.core :as t])
~/.lein/profiles.clj
{:user
{:plugins [[lein-try "0.4.3"]
[jonase/eastwood "0.2.1"]
[refactor-nrepl "1.1.0"]
[cider/cider-nrepl "0.9.1"]]
:dependencies [[org.clojure/tools.nrepl "0.2.7"]]}}
- refactor-nrepl doesn't seem to work with yogthos/pulsar-example
I want to use a different version of Clojure in the REPL
The authors of leiningen suggest creating a project and changing the :dependencies
so that the desired version of Clojure is pulled in.
Then lein repl
in the context of the project.
Emacs Tips
C-c C-k
This compiles your current file within the CIDER session, saving the file first if necessary.
C-c M-n
Switch to the namespace of the current buffer.
C-c M-j
Same as M-x cider-jack-in
q
This closes the error window.
C-M-space
Create a region out of a sexp (or any balanced pair of chars)
C-w
Delete (or kill) region
M-w
Copy region to kill ring
C-y
Paste (or yank)
M-y
This lets you interactively select something from the kill ring to paste.
C-0 C-k
Delete to beginning of line.
M-%
Search and Replace from point to end of file (or the currently selected region). After the first search and replace is finished, you can hit !
to search and replace to the end.
M-x term
This was the terminal emulator I was looking for. Not shell, not eshell, but term
.
C-x k
Kill buffer
C-u M-! shell-command
Insert output of shell command.
ParEdit Mode
C-right
Slurp
C-left
Barf
M-(
Wrap with parentheses.
C-M-f
expression forward
C-M-b
expression backward
clj-refactor
https://github.com/clojure-emacs/clj-refactor.el/wiki
In Emacs, a lot of automagic refactoring is provided through elisp functions provided above.
Emacs Live has them by default.
Customizing Emacs Live
http://overtone.github.io/emacs-live/doc-customisation.html
Files
~/.emacs-live.el
(live-append-packs '(~/.live-packs/your-name-pack))
~/.live-packs/beppu-pack
cp -R ~/.emacs.d/packs/template/user-template-pack ~/.live-packs/beppu-pack
Then, customize!
Org Mode
Tab
Toggle visibility
C-c .
Insert date
M-ret
Insert heading
M-left, M-right
Raise or lower heading level.
M-up, M-down
Move heading up or down.
Cheatsheets
Clojure
ParEdit
http://emacswiki.org/emacs/PareditCheatsheet
Hot CIDER Commands
http://ccann.github.io/2015/11/05/cider-workflow/
Destructuring
Inferior Lisp Mode
I find this useful for running the Datomic REPL from within Emacs.
M-x run-lisp RET
; let it fail
M-x set-variable RET
inferior-lisp-program RET
"/Users/beppu/opt/datomic-pro-0.9.5206/bin/repl"
M-x run-lisp RET
I can't seem to set-variable until I run run-lisp
once and let it fail.
ClojureScript - Big Problem
dnolen [6:08 AM]
NPM allows loading 50 versions of the same dep (edited)
dnolen [6:08 AM]
Google Closure uses a global namespace
dnolen [6:08 AM]
these are incompatible.
https://github.com/clojure/clojurescript/wiki/Enhanced-JavaScript-Module-Support
JavaScript Interop
Specifically, I want to know how to use 3rd party React components together with Reagent.
The road to a cljs npm package
Track official clojurescript releases
https://github.com/clojure/clojurescript/releases.atom
Automatically create a new cljs package for npm when a new release happens.
Use the following as a base:
https://www.npmjs.com/package/cljs-repl
https://github.com/swannodette/cljs-bootstrap
https://github.com/kanaka/cljs-bootstrap
...
PROFIT!
Libraries
clj-commons-exec
https://github.com/hozumi/clj-commons-exec
Useful for handling subprocesses.
popen
https://github.com/tebeka/popen
Another library for subprocesses. This might be nice for relatively short-lived processes. Maybe.
conch *
https://github.com/Raynes/conch
This seems to be the best library for dealing with subprocesses in Clojure. I still like the elegant simplicity of popen though.
no.disassemble
https://github.com/gtrak/no.disassemble
A Clojure library designed to let you inspect bytecode of functions and things.
hara.event
http://docs.caudate.me/hara/hara-event.html
Conditions and Restarts for Clojure
hydrox
http://helpshift.github.io/hydrox/
This is a magical documentation generator from @zcaudate.
cats
https://github.com/funcool/cats
Category Theory and Algebraic abstractions for Clojure and ClojureScript. http://funcool.github.io/cats/latest/
I'll learn this stuff some day.
core.match
https://github.com/clojure/core.match
Pattern matching for Clojure. I may investigate this later, but it's not a high priority.
clara-rules
Forward matching rules for Clojure
https://github.com/rbrush/clara-rules
spectre
overcome your fear of nested Clojure data
https://github.com/nathanmarz/specter
instar
spectre's rival
https://github.com/boxed/instar
cuerdas
String manipulation for Clojure(Script)
https://github.com/funcool/cuerdas
pretty
Pretty-print all the things (especially exceptions)
https://github.com/AvisoNovate/pretty
mount
Managing app state -- an alternative to component
https://github.com/tolitius/mount
rigui
Hierarchical Timing Wheels for Clojure and ClojureScript (timers)
https://github.com/sunng87/rigui
fn-fx
A declarative wrapper around JavaFX for building GUIs
https://github.com/halgari/fn-fx
seesaw
A declarative wrapper around Swing for building GUIs
https://github.com/daveray/seesaw
lasync
An executor service (a.k.a. smart pool of threads) that is backed by a ArrayLimitedQueue or LinkedLimitedQueue.
Explanations
Namespaces
Concurrency and Parallelism
http://clojure-doc.org/articles/language/concurrency_and_parallelism.html
Writing Friendlier Clojure
Refactoring hard to read code.
http://adambard.com/blog/write-friendlier-clojure/
Rich Hickey on Becoming a Better Developer
https://gist.github.com/prakhar1989/1b0a2c9849b2e1e912fb
REPL Slowness
3rd Party JARs
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Although rarely, but sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don't exist in any public repository like Maven Central.
Finding the Schema of a Datomic Database
http://www.learndatalogtoday.org/chapter/4 problem 2
[:find ?attr ?type ?card
:where
[_ :db.install/attribute ?a]
[?a :db/valueType ?t]
[?a :db/cardinality ?c]
[?a :db/ident ?attr]
[?t :db/ident ?type]
[?c :db/ident ?card]]
Datomic
Design a Forum Schema
http://docs.datomic.com/schema.html
Also, look at existing schema examples for inspiration and techniques.
How do I use Datomic from Clojure?
Where do I put the jar?
How do I require it?
Best Practices
Learn Datalog Today
http://www.learndatalogtoday.org/
mindfuck
http://www.learndatalogtoday.org/chapter/8 problem 1 (recursion???)
Also problem 2 has a recursive solution although I wrote a non-recursive (and dumber) solution that worked within the generous constraints they set.
ACHIEVEMENT
I read the whole site and worked through all the problems on September 17, 2015.
Thoughts on Datomic so far...
- It's really easy to join.
- Rules are nice, but recursive rules are a trip.
- Now that I have a feel for querying the data, I think I can come up with a schema for a blog or a forum.
- I just need to learn the mechanics of schema creation, but I have a rough high level understanding of the data model now.
Datomic Blog Posts
http://pelle.github.io/archive.html
Deploying Datomic at/on Heroku
http://blog.opengrail.com/jekyll/update/2015/11/19/datomic-heroku-spaces.html
New? syntax for cljs <-> js attribute access
https://www.reddit.com/r/Clojure/comments/5jtlvn/is_this_line_achievable_in_cljs/
(def audio-context
(or js/window.AudioContext
js/window.webkitAudioContext))
Animations
https://medium.com/tech-quizlet/smooth-game-animations-in-react-df43ece916c8#.6tl9t9mk1
(nothing to do w/ clojurescript, but interesting)