Skip to content

Instantly share code, notes, and snippets.

View jarohen's full-sized avatar
⚒️

James Henderson jarohen

⚒️
View GitHub Profile
@jarohen
jarohen / shares-counts.clj
Created October 22, 2014 17:04
How to get shares counts of a given URL on selected social networks
(defn shares-counts [url]
{:twitter (-> (clj-http.client/get "http://urls.api.twitter.com/1/urls/count.json"
{:query-params {:url url}
:as :json})
:body
:count)
:facebook (-> (clj-http.client/get "http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls="
{:query-params {:method "links.getStats"
:format "json"
@jarohen
jarohen / emacs-24.4-upgrade.org
Created October 21, 2014 12:03
Emacs 24.4 + package-filter upgrade

Upgrading Emacs 24.3 -> 24.4 - problems with ‘package-filter’

I upgraded Emacs this morning to 24.4 and then had trouble starting it with my Emacs setup:

  • I have some packages from MELPA
  • I want to restrict CIDER to the version from MELPA stable (because the cider-middleware version in my profiles.clj needs to be kept in lockstep)

‘package-filter’ breaks under 24.4 because of a missing ‘package-desc-vers’ function. Having said this, package-filter is no longer required under 24.4 because the functionality has been incorporated into the ‘package.el’ package (included with Emacs by default, I think).

To pin packages to a specific repository, add an entry into the ‘package-pinned-packages’ variable, as follows:

@jarohen
jarohen / analyzer-result.edn
Created August 11, 2014 19:14
Playing with clojure.tools.analyzer
{:ret
{:branch? true,
:children [:test :then :else],
:else
{:path? true,
:o-tag java.lang.Object,
:tag java.lang.Object,
:op :do,
:env
{:file "/tmp/form-init2066773735875162764.clj",
@jarohen
jarohen / init.el
Created August 8, 2014 09:24
My init.el
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa-stable" . "http://melpa-stable.milkbox.net/packages/") t)
(add-to-list 'package-archives
(-> (split-with odd? [1 3 5 7 4 3 9 8 3])
(update-in [1] first))
;; => [(1 3 5 7) 4]
@jarohen
jarohen / mu.clj
Created July 28, 2014 09:43
Luke's nerd-sniped me with the Mu problem, here's some helpful code
(require '[clojure.string :as s])
(defn i->iu [s]
(assert (= (last s) \I))
(str s "U"))
(defn doubler [s]
(str (first s) (s/join (rest s)) (s/join (rest s))))
(defn uu->blank [s idx]

Keybase proof

I hereby claim:

  • I am james-henderson on github.
  • I am jarohen (https://keybase.io/jarohen) on keybase.
  • I have a public key whose fingerprint is 091B 87FA 0F5D AE6F 0331 D013 956F 20CA 2105 F582

To claim this, I am signing this object:

@jarohen
jarohen / workaround.clj
Created May 26, 2014 13:13
A workaround for CLJX's middleware specifying an old version of Piggieback
(defproject project "..."
:dependencies [[com.cemerick/piggieback "0.1.3"]
[com.keminglabs/cljx "0.3.2" :exclusions [com.cemerick/piggieback]]]
:plugins [[com.keminglabs/cljx "0.3.2" :middleware false]]
;; ...
)
@jarohen
jarohen / scan.clj
Last active August 29, 2015 14:01
Scanning in ElasticSearch
(defn initial-scroll-id []
(-> (http/get "http://localhost:9200/facebook-objects/facebook-page/_search"
{:query-params {:fields "id, likes"
:search_type "scan"
:scroll "1m"
:size 10000}
:body (json/encode {:query
{:filtered
{:query {:match_all {}}
@jarohen
jarohen / cljs_vary_meta.cljs
Created April 30, 2014 08:31
Vary-meta + lazy seq + CLJS
(defn test-meta []
(let [!eval-count (atom 0)
s (for [n (range 4)]
(do
(swap! !eval-count inc)
(inc n)))
s-with-meta (vary-meta s assoc :a 1 :b 2)]
[(doall s) (doall s-with-meta) @!eval-count]))