Skip to content

Instantly share code, notes, and snippets.

View adam-e-trepanier's full-sized avatar

Adam Trepanier adam-e-trepanier

View GitHub Profile
(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"
@adam-e-trepanier
adam-e-trepanier / gist:47866b5d0a8045d87561
Created October 20, 2014 21:48
Destructuring with :key directive
;; 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 -----")
@adam-e-trepanier
adam-e-trepanier / gist:cac11fa98ac4d1422735
Last active August 29, 2015 14:07
Restructuring with prefix
;; 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 -----")
@adam-e-trepanier
adam-e-trepanier / gist:2383227e043d93c68923
Created October 20, 2014 21:55
Restructuring with auto resolve
;; 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))
@adam-e-trepanier
adam-e-trepanier / no_instance_var_test
Created October 22, 2014 02:47
Don't test instance variables
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
@adam-e-trepanier
adam-e-trepanier / apply.clj
Last active August 29, 2015 14:08
Working with apply
(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))
(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
@adam-e-trepanier
adam-e-trepanier / database.yml
Created November 4, 2010 00:19
my first gist
development:
adapter: postgresql
database: mydatbase.development
username: myusername
password: mypassword
pool: 5
timeout: 5000
<div class="account_info">
<%= @account.name %><br />
Account #: <%= @account.number %>
</div>
def show
@account = Account.find(params[:id])
end