Skip to content

Instantly share code, notes, and snippets.

@carld
carld / deploy.sh
Last active April 20, 2017 06:15
Deploying a clojure ring app to an EC2 machine with Nginx in front
scp -v -r resources/public/* dirnet:/var/www/static/
lein ring uberjar
rsync --verbose --progress -t target/*.jar dirnet:/var/www
ssh host "sudo service my-app restart"
@carld
carld / example.clj
Last active April 17, 2017 04:04
example of lazy-seq in Clojure
user> (defn page-search
[search-term & {:keys [page page-size] :or {page 0 page-size 100}}]
(case page
0 {:items ["page zero"]}
1 {:items ["page one"]}
2 {:items ["page two"]}
nil))
#'user/page-search
user> (defn lazy-page-search
[search-term & {:keys [page page-size] :or {page 0 page-size 100}}]
@carld
carld / note.txt
Created April 7, 2017 01:04
The Clojure Cider Emacs Lein Profiles Fiasco
When there is a profiles.clj file in the project directory,
and it has entries like: {:profiles {:dev {:special-password "secret"}}}
M-x set-variable cider-lein-parameters "with-profile +my-special-snowflake repl :headless"
@carld
carld / heroku-clojure-graphenedb.txt
Created April 6, 2017 11:33
Heroku Clojure Ring GrapheneDB app deployment
The Heroku/Clojure/GrapheneDB Setup
# To enable custom build task. default is `lein uberjar` this changes it to `lein ring uberjar`
heroku config:add LEIN_BUILD_TASK="ring uberjar"
# To run a ring server uberjar, in the Procfile
web: java $JVM_OPTS -jar target/my-app.jar
# Because the GRAPHENEDB_URL does not end with `/db/data`
(def db-url
@carld
carld / ubuntu-ec2.sh
Last active April 6, 2017 09:45
Server setup
sudo apt-get update
sudo apt-get install nginx
sudo update-rc.d nginx defaults
wget -O - https://debian.neo4j.org/neotechnology.gpg.key | sudo apt-key add -
echo 'deb https://debian.neo4j.org/repo stable/' | sudo tee /etc/apt/sources.list.d/neo4j.list
sudo apt-get update
sudo apt-get install neo4j
@carld
carld / 00_destructuring.md
Created April 5, 2017 05:09 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@carld
carld / clojure_app.conf
Created April 5, 2017 04:22
Example upstart script for a clojure app
description "Run clojure app"
start on runlevel startup
stop on runlevel shutdown
respawn
env PORT=5000
exec java -cp /var/www/app.jar clojure.main -m app.handler
@carld
carld / deploy.sh
Created April 4, 2017 05:32 — forked from memphys/deploy.sh
Easy deployment with git and ssh
git archive --format=tar origin/master | gzip -9c | ssh [email protected] "cd /var/www; tar xvzf -"
@carld
carld / emacs-rename.txt
Created April 4, 2017 02:00
Emacs wgrep renaming in many files
http://stackoverflow.com/questions/37654293/replace-text-in-all-files-within-a-directory-subdirectories-in-emacs/37685982#37685982
I generally do this the way @lawlist suggests. Here it is step-by-step:
Install wgrep from Melpa or some other way. I recommend also wgrep-ag and ag if you use The Silver Searcher.
Use M-x rgrep (or M-x ag) to search the files and get a list of lines to potentially change.
In the *grep* buffer, run M-x wgrep-change-to-wgrep-mode. I bind this to C-x C-q in grep-mode-map.
Use query-replace-regexp (C-M-%), or do any other editing in the *grep* buffer.
Save the *grep* buffer with C-x C-s. Use C-c C-k to abort. The changes exist only in the *grep* buffer until you save it. You can re-enable wgrep mode any number of times.
@carld
carld / column_count_csv.sh
Created March 19, 2017 22:24
Count number of columns in a CSV file
head -1 returns.csv | sed 's/[^,]//g' | wc -c