Skip to content

Instantly share code, notes, and snippets.

View mkwatson's full-sized avatar

Mark Watson mkwatson

View GitHub Profile
@mkwatson
mkwatson / while-macro.clj
Last active July 6, 2019 20:27
while->
(defmacro while->
"Takes a predicate, expression, and forms. Threads expr
through each form for which applying pred to the returned
value is true. Threading short circuits after the first
false expression."
[pred expr & forms]
`(if (~pred ~expr)
~(if (not-empty forms)
(let [next-expr `(-> ~expr ~(first forms))]
`(if (~pred ~next-expr)
@mkwatson
mkwatson / thread-macro-compare.clj
Last active August 29, 2015 14:08
while-> comparison
;; cond->
;; Takes an expression and a set of test/form pairs. Threads expr (via ->)
;; through each form for which the corresponding test
;; expression is true. Note that, unlike cond branching, cond-> threading does
;; not short circuit after the first true test expression.
(cond-> 5
true inc
false (+ 100)
(= 2 2) (/ 2))
@mkwatson
mkwatson / fizzbuzz.clj
Last active August 29, 2015 14:09
FizzBuzz no conditionals
#(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % % "Buzz" % "Fizz" % % "FizzBuzz"]) %) %)
-- DEVELOP ( in staging )
-- Doesn't join with beacon table
SELECT
COALESCE (SUM(results.sightings),
0) AS sightings
FROM
( SELECT
COUNT( raw_events_final.event_type = 'beacon_sighting'
OR NULL ) AS sightings
@mkwatson
mkwatson / gist:8d835b9dfa5cb5f37b73
Last active August 29, 2015 14:15
reducers string/join
(defn str-join
([] nil)
(^String [^String x ^String y]
(if (and x y) (.. (new StringBuilder x)
(append "\n")
(append y)
toString)
(if x x
(if y y)))))
(defn flatten-keys* [a ks m]
(cond
(map? m) (reduce into (map (fn [[k v]] (flatten-keys* a (if-not (empty? ks)
(str ks "." (name k))
(name k)) v)) (seq m)))
(and (sequential? m)
(not (instance? clojure.lang.MapEntry m))) (reduce into (map-indexed (fn [idx itm] (flatten-keys* a (str ks "[" idx "]") itm)) (seq m)))
:else (assoc a ks m)))
(defn flatten-keys [m] (flatten-keys* {} "" m))
REVEAL_ARCHIVE_IN_FINDER=true
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
- (void)receivedBackgroundNotification:(NSDictionary *)notification fetchCompletionHandler:(void ( ^ ) ( UIBackgroundFetchResult result ))completionHandler {
// Recieved a pushed message, do we display to this user?
if ([self displayPushedMessage]){
// Display message and record event
[self didRecieveNotification:notification displayedMessage:true];
completionHandler()
}
else {
// Don't display message and record event
[self didRecieveNotification:notification displayedMessage:false];
# Get all beacons for org = 3Pd9Ql1jJ7yttGQ9PQ5NFw
curl -X GET \
-H "Authorization: Basic <<YOUR AUTH STRING HERE>>" \
-H "Content-type: application/json" \
-v \
"https://entities.datasnap.io/v1.0/beacon?organization_id=3Pd9Ql1jJ7yttGQ9PQ5NFw"
# Get beacon with identifier = 1234-5679
curl -X GET \
-H "Authorization: Basic <<YOUR AUTH STRING HERE>>" \
@mkwatson
mkwatson / dog.js
Last active January 11, 2016 19:29
// *************************************
// FP
// *************************************
var Dog = function() {
var weight = 15;
var age = 1;
return {
feed : function(amount){
weight += amount;
},