Create a gist now

Instantly share code, notes, and snippets.

@yurrriq /README.org
Last active Aug 29, 2015

What would you like to do?
GitHub Languages

GitHub Languages

Prints a JSON map of the languages used in your repos, sorted by frequency in descending order.

Usage

lein run -m gh-languages # | hicat
(ns gh-languages
(:require [cheshire.core :as json]
[clojure.pprint :refer [pprint]]
[environ.core :refer [env]]
[org.httpkit.client :as http]))
(def my-repos (str "https://api.github.com/users/" (env :gh-user) "/repos"))
(def options {:basic-auth [(env :gh-access-token) "x-oauth-basic"]})
(defn sort-by-val [m]
(let [>val #(compare ((juxt m identity) %2) ((juxt m identity) %1))]
(into (sorted-map-by >val) m)))
(defn -main [& args]
(-> (:body @(http/get my-repos options))
(json/parse-string true)
(->> (remove (comp #{"https://github.com/yurrriq/homebrew"} :html_url))
(map :languages_url)
(map #(json/parse-string (:body @(http/get % options))))
(apply merge-with +))
sort-by-val
(json/generate-string {:pretty true})
println))
{:user {:dependencies [[cheshire "5.4.0"]
[environ "1.0.0"]
[http-kit "2.1.19"]]
:plugins [[lein-environ "1.0.0"]]
:env {:gh-user "YOUR-GITHUB-USERNAME"
:gh-access-token "YOUR-ACCESS-TOKEN"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment