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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.test :refer [is]]) | |
(defn pure-adder [x y] | |
(+ x y)) | |
(is (= 3 (pure-adder 1 2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker exec -it cwservice /bin/sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns batchreq.core | |
(:refer-clojure :exclude [map reduce into partition partition-by take merge]) | |
(:require [clojure.core.async :refer :all :as async] | |
[clj-http.client :as client]) | |
(:use taoensso.timbre | |
taoensso.timbre.profiling)) | |
(defnp http-get [id] | |
(client/get (format "http://fssnip.net/%d" id)) | |
id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns transform | |
(:require [clojure.xml :refer [parse]] | |
[clojure.zip :refer [xml-zip node up]] | |
[clojure.data.zip.xml :refer [xml-> xml1-> text attr attr=]] | |
[clojure.data.json :refer [write-str]])) | |
(defn- team-name [event alignment] | |
(xml1-> event :team :team-metadata (attr= :alignment alignment) :name (attr :first))) | |
(defn- sports-event [event] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ajk; | |
import clojure.lang.IFn; | |
import java.io.ByteArrayInputStream; | |
import java.io.IOException; | |
import static clojure.java.api.Clojure.read; | |
import static clojure.lang.RT.loadResourceScript; | |
import static clojure.lang.RT.var; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
students = [ | |
{ name: "Bob", cohort: "Nov"}, | |
{ name: "Barry", cohort: "Nov"}, | |
{ name: "Anna", cohort: "Dec"}, | |
{ name: "Igor", cohort: "Dec"}, | |
{ name: "Natalia", cohort: "Feb"} | |
] | |
my_hash = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Looping through an array to form a new array | |
# non functional (imperative) way | |
my_array = [1,2,3,4,5] | |
new_array = [] # requires us to create a structure then modify it using push | |
my_array.each { | element | | |
new_array.push("number " + element.to_s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
killall ssh-agent gpg-agent | |
unset GPG_AGENT_INFO SSH_AGENT_PID SSH_AUTH_SOCK | |
eval $(gpg-agent --daemon --enable-ssh-support) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Docker MySQL | |
docker run -p 3306:3306 --name local-mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci | |
mysql -h $(docker-machine ip) -uroot -ppassword |