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
(def data | |
{:name "Adam Trepanier" | |
:date-of-birth "1981-04-30" | |
:gender "male" | |
:patient-key "test-adam" | |
:status "active" | |
:phone "555-555-5555" | |
:shipping-address {:street "123 Foo Bar Way" | |
:city "Somwhere" | |
:state "CA" |
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
;; Destructor a map with another map -> patient has a shipping address | |
;; We use the :keys directive to to assign the shipping address info inside of data | |
;; Notice we also use the :keys directive to also get the name and date of birth | |
(let [{:keys [name date-of-birth orders] | |
{:keys [street city state postal-code]} :shipping-address | |
:as patient} data] | |
(println name \- date-of-birth) | |
(println street ", " city ", " state " " postal-code) | |
(println orders) | |
(println "------- Full Patient Deatils -----") |
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
;; In Clojure 1.6 we can now prefix the name of a key if its the same | |
;; A litte more context with the prefix, but still very clean | |
(let [{:keys [name date-of-birth orders | |
shipping-address/street shipping-address/city | |
shipping-address/state shipping-address/postal-code] | |
:as patient} data] | |
(println name \- date-of-birth) | |
(println street ", " city ", " state " " postal-code) | |
(println orders) | |
(println "------- Full Patient Deatils -----") |
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
;; In Clojure 1.6 we can now also auto resolve keyword forms in the :keys directive | |
;; I think you lose some context with auto-resolve, but its the shortest code | |
(let [{:keys [name date-of-birth orders | |
::street ::city ::state ::postal-code] | |
:as patient} data] | |
(println name \- date-of-birth) | |
(println street ", " city ", " state " " postal-code) | |
(println orders) | |
(println "------- Full Patient Deatils -----") | |
(println patient)) |
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
class Foo | |
def initialize | |
@logger ||= APP::LOGGER | |
@agent = Agent.new(name, action, args) | |
end | |
end | |
describe Foo do | |
it "should initialize an integration logger" do | |
foo = Foo.new |
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 functions.apply) | |
;; We can use apply with print because print takes the (& more) | |
;; parameter. So we can pass any number of args to messenger | |
;; and then apply will explode the sequence generated by (& who) in | |
;; the argument list into the print method | |
(defn messenger "Fooling with apply function" [greeting & who] | |
(println who) | |
(apply print greeting who)) |
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 clojure-programming.concurrency.futures | |
(:import (java.util Date))) | |
;; Futures | |
;; Simple concept. Take some code and evaluate it in another thread. Thats it. | |
;; Futures return immediately, which allows the current thread of execution | |
;; to continue on doing its own thing. The results of the future can be | |
;; obtained by dereferencing the future. Note that if you try and dereference | |
;; the future prior to it being complete, it will block |
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
development: | |
adapter: postgresql | |
database: mydatbase.development | |
username: myusername | |
password: mypassword | |
pool: 5 | |
timeout: 5000 |
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
<div class="account_info"> | |
<%= @account.name %><br /> | |
Account #: <%= @account.number %> | |
</div> |
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
def show | |
@account = Account.find(params[:id]) | |
end | |
OlderNewer