Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created November 23, 2013 21:23
Show Gist options
  • Save jbrechtel/7620127 to your computer and use it in GitHub Desktop.
Save jbrechtel/7620127 to your computer and use it in GitHub Desktop.
Generate and search for available twitter usernames

What?

This helps you search for available twitter usernames.

Why?

I really want a twitter username that matches my nickname instead of my realname. Most of the good formulations of my nickname are taken so I wanted to find something with an _ or 1 placed in a non-annoying spot. There are a lot of permutations so I decided to generate them and then search automatically.

Using

Just populate the names vector with the 'base' names you're interested in. If you want to search those specifically then (search names)

I did this in LightTable with an InstaRepl window, so I'd recommend that. If you're going to just run the .clj file then just pass the (search) calls to (println).

Bugs

If it gets a non-200 response from https://twitter.com/USERNAME then it thinks the name is available. This isn't always true. Suspended account pages get non-200 responses.

I'm using seqs of promises synchronously.

The insert function is atrocious. I'm sure there's a better way to do this than I am. Comments or PRs welcome.

(defproject hellox "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.5.1"]
[http-kit "2.1.12"]] )
(require '[org.httpkit.client :as http])
(defn exists [username] (= 200 (:status @(http/get (str "https://twitter.com/" username)))))
(defn search [usernames] (filter (fn [[u e]] (= false e)) (map (fn [n] [n (exists n)]) usernames)))
(defn insert [s pos c] (let [svec (vec (seq s))
lhs (reduce str (subvec svec 0 pos))
rhs (reduce str (subvec svec pos (count svec)))]
(str lhs c rhs)))
(defn sprinkle [topping cake]
(for [index (range 0 (count cake))] (insert cake index topping)))
(def names [])
(def sprinkled (apply concat (map (partial sprinkle "_") names)))
(search sprinkled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment