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
// The props for the React component are initally set from the server side | |
const addressConfig = #{@address_config.to_json}; | |
// the component is rendered inside the form at a marker div embedded in the server generated HTML | |
const addressInstance = React.render( | |
React.createElement(Address, addressConfig), | |
document.getElementById("#billing_address") | |
); |
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
(s/validate | |
Data | |
{:a {:b "abc" | |
:c 123} | |
:d [{:e :bc | |
:f [12.2 13 100]} | |
{:e :bc | |
:f [-1]}]}) | |
;; Success! |
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 | |
"A schema for a nested data type" | |
{:a {:b s/Str | |
:c s/Int} | |
:d [{:e s/Keyword | |
:f [s/Num]}]}) |
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
[{:key :email-consent | |
:type :yes-no | |
:tags [#{:application/energy-offline}] | |
:schema (shared/map-has {:email-consent shared/Yes-No}) | |
:group groups/account | |
:label "Would you like E.ON to email you account management reminders?" | |
:help-text "E.ON may also use these details to write to you about your account once your switch is complete."}] |
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
#+clj (defn parse-date | |
[date-string] | |
(f/parse (f/formatter "dd/MM/yyyy") date-string)) | |
;; Javascript date uglyness: http://stackoverflow.com/questions/2587345/javascript-date-parse | |
#+cljs (defn parse-date | |
"Parses a UK date string such as 29/01/2014 and converts it into a JS date object or nil if invalid. | |
Handles bizarro javascript case such as new Date(2014, 1, 31) => Mon Mar 03 2014 00:00:00 GMT+0000 (GMT)" | |
[date-string] | |
(let [date-parts (clojure.string/split date-string #"/") |
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
(defmacro defquestions | |
"Macro to reduce the size of the generated javascript by omitting unused keys (and their values) in the questions. | |
It works by looping over the questions and only retaining the keys that are required on the client side. | |
To ensure it is applied on the client size code require the macro and then apply it using #+cljs. | |
For the server side just use the #+clj marker and a normal def." | |
[name questions] | |
{:pre [(symbol? name) (and (coll? questions) (every? map? questions))]} | |
(let [filtered-questions (mapv #(select-keys % [:key :tags :schema :ask-if]) questions)] | |
`(def ~name ~filtered-questions))) |
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
from json import load, JSONEncoder | |
from optparse import OptionParser | |
from re import compile | |
float_pat = compile(r'^-?\d+\.\d+(e-?\d+)?$') | |
charfloat_pat = compile(r'^[\[,\,]-?\d+\.\d+(e-?\d+)?$') | |
parser = OptionParser(usage="""%prog [options] | |
Group multiple GeoJSON files into one output file. |
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 Hash | |
def now | |
Rails.logger.warn "Stubbing now during upgrade" | |
{} | |
end | |
def keep | |
# stub keep for upgrade purposes | |
Rails.logger.warn "Stubbing keep during upgrade" |
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
# version of rename collection that drops the existing collection if present. | |
# the standard rename method on the collection object provided by the driver | |
# throws an exception if the target collection exists | |
# http://docs.mongodb.org/manual/reference/command/renameCollection/ | |
def self.rename_collection(db, old_name, new_name) | |
cmd = BSON::OrderedHash.new | |
database_name = db.name | |
cmd[:renameCollection] = "#{database_name}.#{old_name}" | |
cmd[:to] = "#{database_name}.#{new_name}" | |
cmd[:dropTarget] = true |
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 Hash | |
def get_in(*keys) | |
key = keys.first | |
value = self[key] | |
return value if keys.count == 1 | |
return nil if keys.count > 1 and !value.respond_to? :get_in | |
return value.get_in(*keys.drop(1)) if key?(key) | |
end | |
end |