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 Hashli | |
attr_accessor :store, :depth | |
def initialize() | |
self.depth = 3 | |
init_store | |
end | |
def hash k | |
k.hash.to_s.chars.take(@depth).map(&:to_i) |
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 how-to.content | |
(:require [interlope.core :as i])) | |
(defn format-for | |
" Returns a function for easy access to I18N content. | |
Take this closure and pass it around, puff puff pass | |
example: | |
(let [f (format-for alerts :en)] | |
(f [:title] {:state-name \"MN\"}))" | |
[content-map lang state-abbrev] |
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 state-specific-content | |
"Some states require just a little... extra." | |
{:en { | |
;; Alaska | |
:ak {:disclaimer "<p>Alaska will have an option to transmit absentee ballot applications electronically in 2020. You can request an absentee ballot application by electronic transmission until Monday, November 2, 2020. For more information, please visit <a href=\"http://www.elections.alaska.gov/Core/votingbyonline.php\">http://www.elections.alaska.gov/Core/votingbyonline.php</a></p>"} | |
;; California | |
:ca {:disclaimer " Conditional voter registration is a safety net for Californians who miss the deadline to register to vote or update their voter registration information. Voters can use the conditional voter registration process from the day after the deadline all the way through Election Day. Eligible citizens can go to their county election office or a designated satellite location to register and vote conditionally. These ballots will be processed once the county elections office |
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
(defn message-stream | |
([c] | |
(message-stream c ())) | |
([c a] | |
(lazy-seq | |
(cons a | |
(message-stream c (seq (poll! c))))))) | |
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
state (atom :continue) | |
;; state event new state | |
state-machine {:continue {:pause :paused | |
:halt :halting} | |
:paused {:resume :resuming | |
:halt :halting} | |
:resuming {:continue :continue} | |
:halting {:halt :halted}} | |
step-state (fn [transition] |
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 sql) | |
(defn sub-qmark [i form] | |
(if (keyword? form) | |
['? form] ;;todo need a stateful transducer | |
form)) | |
(defn params [body] | |
(map-indexed sub-qmark body)) |
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
(defn accumulate | |
"If an input satisfies ACC-PRED, accumulate it with ACC-FN (defaults to merge) | |
All inputs will be passed on normally. | |
All accumulated inputs will be merged (using ACC-FN) to following inputs until RESET-PRED. | |
The input that satisfies RESET-PRED will receive the accumulated values and the input following it will receive none. | |
The default ACC-FN, `merge`, assumes a stream of maps" | |
([acc-pred reset-pred] | |
(accumulate acc-pred reset-pred merge)) |
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
(defmethod hugsql.parameters/apply-hugsql-param :in-many | |
[param data options] | |
(let [in-clause-split-by (get options :in-clause-split-by 1000) ;; 1000 is Oracle's max | |
singl-map (get options :singularize-map);; override singularize | |
values (get-in data (hugsql.parameters/deep-get-vec (:name param))) | |
singularize (fn [s] (string/replace s #"s$" "")) | |
column (get singl-map (:name param) (singularize (name (:name param)))) | |
prefix (str column " in ") | |
join-or (str " or " column " in " ) |
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
(defn date? | |
"Ensure a date string is a date and after a cutoff date. This protects against technically valid but corrupt dates like from a century ago or in the future." | |
([s] | |
;; store the year 10 years from now so we don't have to compute it every call | |
(date? s 2010 `~(+ 10 (clj-time.core/year (clj-time.core/now))))) | |
([s past-cutoff future-cutoff] | |
(try | |
(if-let [d | |
(clj-time.format/parse |
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
(defn collate | |
"This is a transducer for collecting things that are connected in series. It | |
will store one previous input. The previous input can then be compared to it's | |
successor using COMPARES-FN and optionally integrated into a single output | |
using COLLATE-FN. | |
COMPARES-FN must accept 2 arguments, being 2 inputs (which are in order) | |
COLLATE-FN must accept 2 arguments, being an accumulator and an input | |
COLLATE-FN is a reducing function. A third arg can be given as the starting |
NewerOlder