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.
;; example rails like console for compojure showing params, etc. for each request | |
(ns bus.core | |
(:use compojure.core | |
ring.adapter.jetty | |
... | |
... | |
(:use ring.middleware.params)) | |
// Simulate a call to Dropbox or other service that can | |
// return an image as an ArrayBuffer. | |
var xhr = new XMLHttpRequest(); | |
// Use JSFiddle logo as a sample image to avoid complicating | |
// this example with cross-domain issues. | |
xhr.open( "GET", "http://fiddle.jshell.net/img/logo.png", true ); | |
// Ask for the result as an ArrayBuffer. | |
xhr.responseType = "arraybuffer"; |
Foreword | |
======== | |
This is a very rough draft of the tutorial I'm going to put on | |
compojure.org. It's not complete, but it covers most of the basics. | |
There's a possibility some of the terminology (such as handlers and | |
routes) might change, but I'll let you know if it does. The technical | |
content, however, should be accurate and up to date. | |
Criticism is very welcome; I'd like to know if anything is unclear or |
If anyone is interested in setting up their system to automatically (or manually) sign their git commits with their GPG key, here are the steps:
- Generate and add your key to GitHub
$ git config --global commit.gpgsign true
([OPTIONAL] every commit will now be signed)$ git config --global user.signingkey ABCDEF01
(whereABCDEF01
is the fingerprint of the key to use)$ git config --global alias.logs "log --show-signature"
(now available as$ git logs
)$ git config --global alias.cis "commit -S"
(optional if global signing is false)$ echo "Some content" >> example.txt
$ git add example.txt
$ git cis -m "This commit is signed by a GPG key."
(regularcommit
will work if global signing is enabled)
(conj collection item)
adds item
to collection
. To do that, it needs to realize collection
. (I'll explain why below.) So the recursive call happens immediately, rather than being deferred.
(cons item collection)
creates a sequence which begins with item
, followed by everything in collection
. Significantly, it doesn't need to realize collection
. So the recursive call will be deferred (because of using lazy-seq
) until somebody tries to get the tail of the resulting sequence.
The following is how it works internally:
cons
actually returns a clojure.lang.Cons
object, which is what lazy sequences are made of. conj
returns the same type of collection which you pass it (whether that is a list, vector, or whatever else). conj
does this using a polymorphic Java method call on the collection itself. (See line 524 of clojure/src/jvm/clojure/lang/RT.java
.)
What happens w
Make sure there is at least one file in it (even just the README.md)
ssh-keygen -t rsa -C "[email protected]"
THREE.TrackballControls=function(e,t){var o=this,n={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.keys=[65,83,68],this.target=new THREE.Vector3;var s=new THREE.Vector3,c=n.NONE,a=n.NONE,i=new THREE.Vector3,r=new THREE.Vector2,p=new THREE.Vector2,h=new THREE.Vector3,d=0,u=new THREE.Vector2,E=new THREE.Vector2,m=0,l=0,g=new THREE.Vector2,y=new THREE.Vector2;this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.up0=this.object.up.clone();var v={type:"change"},w={type:"start"},T={type:"end"};this.handleResize=function(){if(this.domElement===document)this.screen.left=0,this.screen.top=0,this.screen.width=window.innerWidth,this.screen.height=window.innerHeight;else{var |
;; For supporting more PG types, see https://github.com/remodoy/clj-postgresql | |
(ns pg-test.types | |
(:require [cheshire.core :as json] | |
[clojure.java.jdbc :as jdbc]) | |
(:import [org.postgresql.util PGobject] | |
[java.sql PreparedStatement])) | |
;; Writing | |
(defn- to-pg-json [data json-type] |