Skip to content

Instantly share code, notes, and snippets.

@s3thi
s3thi / gist:1317298
Created October 26, 2011 18:32
reddit's favorite books
Douglas Adams - The Hitchhiker's Guide to the Galaxy -- 394 upvotes, 87 downvotes
George Orwell - 1984 -- 372 upvotes, 66 downvotes
Kurt Vonnegut - Slaughterhouse-Five -- 330 upvotes, 50 downvotes
Orson Scott Card - Ender's Game -- 273 upvotes, 62 downvotes
Aldous Huxley - Brave New World -- 268 upvotes, 39 downvotes
George R R Martin - A Game of thrones -- 265 upvotes, 48 downvotes
JRR Tolkien - The Hobbit -- 255 upvotes, 47 downvotes
Joseph Heller - Catch 22 -- 210 upvotes, 38 downvotes
George Orwell - Animal Farm -- 200 upvotes, 44 downvotes
Frank Herbert - Dune -- 189 upvotes, 33 downvotes
@s3thi
s3thi / gist:1317304
Created October 26, 2011 18:33
script to scrape reddit's favorite books
import urllib2
import json
# grab data
raw_data = urllib2.urlopen('http://www.reddit.com/r/books/comments/lol8l/time_for_a_new_reddits_favorite_books_thread/.json').read()
thread_data = json.loads(raw_data)[1]
toplevel_comments = thread_data['data']['children']
# extract books, upvotes and downvotes
votes = dict()
@s3thi
s3thi / gist:1441776
Created December 7, 2011 06:54
/r/Python QOTW #1
import sys
def can_make(word, letters):
""" Return True if <word> can be generated using only the letters in the
list <letters>. """
if len(word) > len(letters): return False
l = letters[:]
@s3thi
s3thi / gist:1446422
Created December 8, 2011 08:01
Caesar Cipher #1
from string import whitespace, punctuation
def shift(c, shift_by = 2):
if c in whitespace + punctuation: return c
upper_ord, lower_ord, c_ord = ord('A'), ord('a'), ord(c)
c_rel = (c_ord - lower_ord) if c_ord >= lower_ord else (c_ord - upper_ord)
offset = lower_ord if c_ord >= lower_ord else upper_ord
return chr(offset + (c_rel + shift_by) % 26)
@s3thi
s3thi / gist:1446664
Created December 8, 2011 10:30
Caesar Cipher #2
import string
from collections import deque
alphabet = string.ascii_lowercase
alphabet_deque = deque(alphabet)
alphabet_deque.rotate(-2)
rotated_alphabet = ''.join(alphabet_deque)
tbl = string.maketrans(alphabet, rotated_alphabet)
msg = 'a quick brown fox jumped over the lazy dog'
@s3thi
s3thi / gist:1450643
Created December 9, 2011 07:41
Python QOTW #1 in C++
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
bool can_make(string word, vector<char> letters);
int get_max_len(vector<string> words);
@s3thi
s3thi / gist:3369950
Created August 16, 2012 13:01
Scrape Premchand
"use strict;";
// You need htmlparser, soupselect and ent to run this.
// Install them from npm.
var http = require("http");
var fs = require("fs");
var path = require("path");
var htmlparser = require("htmlparser");
var select = require("soupselect").select;
var ent = require("ent");
@s3thi
s3thi / gist:5159269
Created March 14, 2013 06:28
Small Facebook chat example using xmpppy.
import xmpp, time
FB_ID = '[email protected]'
PASS = 'password'
jid = xmpp.protocol.JID(FB_ID)
client = xmpp.Client(jid.getDomain(), debug=[])
if not client.connect(('chat.facebook.com', 5222)):
raise IOError('could not connect to Facebook')
extern mod std;
use std::list::*;
pub fn last_box<T>(l: @List<T>) -> T {
match *l {
Nil => fail!(),
Cons(hd, @Nil) => hd,
Cons(_, tl) => last_box(tl)
}
}
@s3thi
s3thi / answer.py
Last active August 29, 2015 13:56
def answer():
return 42