Skip to content

Instantly share code, notes, and snippets.

@sujaymansingh
Created February 12, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujaymansingh/8953018 to your computer and use it in GitHub Desktop.
Save sujaymansingh/8953018 to your computer and use it in GitHub Desktop.
How many posts about lisp on reddit/r/programming?

What is this?

It seems that nearly every post on reddit.com/r/programming is about someone's lisp to X converter. Is this true? The key is to measure.

A simple count

$ python how_many_lisp_posts.py 'http://www.reddit.com/r/programming.json?limit=100'
1 out of 100 posts about lisp: 1.00%

Get the result in lisp

(to feed into your own converter...)

$ python how_many_lisp_posts.py 'http://www.reddit.com/r/programming.json?limit=100' --result-as-lisp
(format t "~D out of ~D posts about lisp: ~F%" 1 100 (* 100 (/ 1 100)))
import json
import sys
import urllib
def fetch_content(url):
response = urllib.urlopen(url)
return json.load(response)
def is_about_lisp(title):
title_lower = title.lower()
return "lisp" in title_lower and "to" in title_lower
if __name__ == "__main__":
result_as_lisp = "--result-as-lisp" in sys.argv
url = sys.argv[1]
response = fetch_content(url)
listings = response["data"]["children"]
titles = [listing["data"]["title"] for listing in listings]
lisp_titles = filter(is_about_lisp, titles)
if result_as_lisp:
print '(format t "~D out of ~D posts about lisp: ~F%" {0} {1} (* 100 (/ {0} {1})))'.format(len(lisp_titles), len(titles))
else:
percent = 100.0 * len(lisp_titles) / len(titles)
print "{0} out of {1} posts about lisp: {2:.2f}%".format(len(lisp_titles), len(titles), percent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment