Skip to content

Instantly share code, notes, and snippets.

View rockBreaker's full-sized avatar
coffee

Guy Barlow rockBreaker

coffee
View GitHub Profile
(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)))
;;Helper function
(defn node-text
[node]
(first (xpath/$x:text* "." node)))
/*
* 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"
(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))))))
<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>
@rockBreaker
rockBreaker / boids.clj
Last active April 3, 2016 19:33
Clojure dojo code for boids (quick and dirty with quil)
(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)])
(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))
@rockBreaker
rockBreaker / core.clj
Last active August 29, 2015 14:08 — forked from terjesb/core.clj
(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.))
@rockBreaker
rockBreaker / gist:6f3f439319bbf05b0477
Created July 10, 2014 15:32
funky clojure code, i am bad at naming at formatting
(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)))))
@rockBreaker
rockBreaker / gist:5f8e2efb060f68756dc0
Created July 10, 2014 14:48
horrible code mrk2 needs formatting, checks for a straight, inc low ace case
(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