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 parse-number | |
"Reads a number from a string. Returns nil if not a number." | |
[s] | |
(if (re-find #"^-?\d+\.?\d*$" s) | |
(read-string s))) |
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
;;Helper function | |
(defn node-text | |
[node] | |
(first (xpath/$x:text* "." node))) |
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
/* | |
* call-seq: | |
* str.capitalize! -> str or nil | |
* | |
* Modifies <i>str</i> by converting the first character to uppercase and the | |
* remainder to lowercase. Returns <code>nil</code> if no changes are made. | |
* Note: case conversion is effective only in ASCII region. | |
* | |
* a = "hello" | |
* a.capitalize! #=> "Hello" |
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 ^String capitalize | |
"Converts first character of the string to upper-case, all other | |
characters to lower-case." | |
{:added "1.2"} | |
[^CharSequence s] | |
(let [s (.toString s)] | |
(if (< (count s) 2) | |
(.toUpperCase s) | |
(str (.toUpperCase (subs s 0 1)) | |
(.toLowerCase (subs s 1)))))) |
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
<product> | |
<new_products_id></new_products_id> | |
<products_id>98956</products_id> | |
<barcode>5060220225916</barcode> | |
<ebay_id>68297</ebay_id> | |
<oldmodel></oldmodel> | |
<supply_via_dropship>0</supply_via_dropship> | |
<uk_products_only>0</uk_products_only> | |
<model>z92sospar</model> | |
<allowUntracked>0</allowUntracked> |
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 location [] | |
[(rand-int 255) (rand-int 255)]) | |
(defn init-locations | |
[] | |
(for [i (range 5)] (location))) | |
(defn dist-vector | |
[[x1 y1] [x2 y2]] | |
[(- x1 x2) (- y1 y2)]) |
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 linkedin-profile | |
"linkedin API call for the current authenticated users repository list." | |
[access-token] | |
(let [url (str "https://api.linkedin.com/v1/people/~?format=json?access_token=" access-token) | |
response (client/get url {:accept :json}) | |
profile (json/read-str (:body response) :key-fn keyword)] | |
profile)) |
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 ga-exp.core | |
(:import | |
(com.google.api.client.googleapis.auth.oauth2 GoogleCredential$Builder) | |
(com.google.api.client.googleapis.javanet GoogleNetHttpTransport) | |
(com.google.api.client.json.jackson2 JacksonFactory) | |
(com.google.api.services.analytics Analytics$Builder AnalyticsScopes))) | |
(def HTTP_TRANSPORT (GoogleNetHttpTransport/newTrustedTransport)) | |
(def JSON_FACTORY (JacksonFactory.)) |
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 value [hand] | |
(let [checkers #{[high-card? 0] [pair? 1] | |
[two-pairs? 2] [three-of-a-kind? 3] | |
[straight? 4] [flush? 5] | |
[full-house? 6] [four-of-a-kind? 7] | |
[straight-flush? 8]} | |
ita (fn [coll] (if ((first coll) hand) (second coll)))] | |
(apply max (filter (complement nil?) (map ita checkers))))) |
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 straight? [hand] | |
(let [sorted-hand | |
(fn[hand] (sort (keys (frequencies (map rank hand))))) | |
range-helper | |
(fn [hand] (= hand (range (apply min hand) (inc (apply max hand))))) | |
low-ace | |
(fn [hand] (range-helper (sort (replace {14 1} (sorted-hand hand)))))] | |
(and |
NewerOlder