Skip to content

Instantly share code, notes, and snippets.

View deltamualpha's full-sized avatar
🥔

David Ashby deltamualpha

🥔
View GitHub Profile
@deltamualpha
deltamualpha / gist:5971827
Created July 11, 2013 01:37
There has got to be a better way.
(defn get-attributes [html]
(map #(into {} %)
(map #(remove nil? %)
(map #(if (dom/attributes? %) [(:name (dom/attributes %)) (:value (dom/attributes %))])
(map dom/node-seq
(xpath/lookup-nodeset "//form[@class=\"download\"]" html))))))
@deltamualpha
deltamualpha / gist:5639611
Last active December 17, 2015 16:30
A way to run a number of different tag queries in wordpress and then sort the results, putting the queries that match the most tags at the top.
$queries_array = {$query_1, $query_2, $query_n};
$merged_array = array_reduce($queries_array, array_merge);
$uniques = array();
$counter = array();
foreach ( $merged_array as $current ) {
$counter[current->id] += $counter[current->id];
$uniques[current->id] = $current; // pulls out unique only
}
@deltamualpha
deltamualpha / gist:5218827
Created March 22, 2013 03:49
I suck at clojure.
(defn magic [row]
(if (map? (first row)) (for [x row] (into [] (flatten (seq x)))) (into [] x)))
(defn collapser [incoming]
(reduce (fn [a b] (conj a (magic b))) [["header" "information"]] (remove nil? incoming)))
;for an input like
;([:a a :b b] nil nil [{:c c, :d d} {:e e, :f f}] nil [:a g :b h]) =>
;[["test" "two"] [:a "a" :b "b"] ([:c "c" :d "d"] [:e "e" :f "f"]) [:a "g" :b "h"]]
;but what I want is