Skip to content

Instantly share code, notes, and snippets.

View dmarx's full-sized avatar

David Marx dmarx

View GitHub Profile
@dmarx
dmarx / IndexAndCompress.py
Created September 9, 2012 15:51
A variation on /u/StonedEmu's text compression program to introduce him to a few slightly advanced python concepts.
_text = 'raw.txt'
_index = 'index.txt'
def readFile(F):
'''Pretty generic 'read' operation'''
data = []
with open(F, 'r') as f:
for line in f:
data.append(line.strip())
return data
@dmarx
dmarx / dl_reddit_saved_images.py
Created December 6, 2012 15:42
Downloads images from a user's saved links on reddit. Requires manual entry of username and password
"""
This script was written to illustrate libraries that could be used to improve upon
the efficiency of a script posted to /r/learnprogramming:
Original script:
https://github.com/aesptux/download-reddit-saved-images/blob/master/script.py
Reddit post
http://www.reddit.com/r/learnprogramming/comments/14dojd
/pythoncode_review_script_to_download_saved_images/
"""
from urllib2 import Request, urlopen
@dmarx
dmarx / popular_reddit_video_domains.py
Last active December 12, 2015 06:58
Identifying popular video domains submitted to reddit
@dmarx
dmarx / alien_v2.py
Created February 13, 2013 20:23
Significantly refactored https://github.com/jawerty/alienfeed . My refactoring is an 86% rewrite (per git commit message), so since this rewrite was for pedagogical purposes anyway, I've opted to post a gist and let the author try to figure out how this code is different from theirs instead of just submitting a pull request.
#!/usr/bin/env python
import sys
import random
import argparse
import praw
import webbrowser
r = praw.Reddit(user_agent='AlienFeed v0.1.0 by u/jw989 as seen on Github http://github.com/jawerty/AlienFeed')
@dmarx
dmarx / RAoA contest research.py
Last active December 14, 2015 02:39
Users were invited to state the next number in a sequence. I was interested in seeing which numbers were skipped or repeated. Resultant graph from scrape at 2013-2-22 13:34 EST: http://i.imgur.com/yOFOfIX.png
import praw
from collections import Counter
import pandas as pd
import matplotlib.pyplot as plt
useragent='investigating a RAOA post'
r = praw.Reddit(useragent)
def get_comments(subm_id='190wmg'):
subm=r.get_submission(submission_id=subm_id)
import time # just to time the preprocessing step
index = {}
WORDS = set()
map=[' ' #0
,' ' #1
,('a','b','c') #2
,('d','e','f') #3
,('g','h','i') #4
@dmarx
dmarx / LinkFixerClone.py
Last active January 19, 2021 02:20
A simple LinkFixerBot clone developed as a demonstration for anyone who is curious how a simple reddit bot might be coded. To kill this code, spam "Ctrl+C" until it catches the exception.
import praw # simple interface to the reddit API, also handles rate limiting of requests
import re
from collections import deque
from time import sleep
USERNAME = "Your username here"
PASSWORD = "Your password here"
USERAGENT = "Your useragent string here. It should include your /u/username as a courtesy to reddit"
r = praw.Reddit(USERAGENT)
@dmarx
dmarx / Monte Carlo integration.r
Created May 16, 2013 21:52
Demo monte carlo integration technique in R.
boundingRange <- function(x){
max(x) - min(x)
}
runif_box <-function(n,x){
b = boundingRange(x)
u = runif(n)
u*b+min(x)
}
@dmarx
dmarx / scraper.py
Last active December 17, 2015 23:09
Generic tool for investigating the activity of redditors. Produces an activity profile by time of day (hour UTC) and the user's active subreddits.
import praw
import time
import pandas as pd
import matplotlib.pyplot as plt
from collections import Counter
class UserScraper(object):
'''Generic utility for investigating redditors'''
def __init__(self
, username
@dmarx
dmarx / scrape_mods.py
Created July 5, 2013 18:13
Analysis of "super moderators" on reddit.com. Requires praw library and a "subreddits.txt" file populated with the names of subreddits the user wants to investigate moderators from.
import praw, csv
from collections import defaultdict, Counter
# your userlogin information here. If you don't provide, the script will prompt
# you for it at the terminal, so no big deal either way. Just a convenience.
USERNAME = ''
PASSWORD= ''
useragent='getting moderators graph by /u/shaggorama'
r=praw.Reddit(useragent)