Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / ex1.c
Created May 3, 2017 02:48
machine code in c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
typedef int (*factorial_func)(int);
#define X86_64_CALLING_CONVENTION 1
@carld
carld / omg.scm
Created June 3, 2017 01:27
LLVM literal float representation from Chez Scheme
(define (float->hex fl)
(string-append "0x"
(with-output-to-string
(lambda ()
(write-ieee-float32 fl
(make-output-port
(lambda (m . args)
(case m
((write-char)
(format #t "~X" (char->integer (car args)))))) (make-string 0))