Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View durcana's full-sized avatar

Amy Durcan durcana

View GitHub Profile
@durcana
durcana / feed.py
Last active August 31, 2016 06:40
The main script feed.py streams live filtered tweets that contain the words birth and conviction. It returns the tweets along with their sentiment value, evaluated from naive_bayes.py. I'm looking to add a script that will use all the collected tweets to return the average sentiment for the words birth and conviction.
from json import loads
from tweepy import OAuthHandler
import os
from tweepy import Stream
from tweepy.streaming import StreamListener
import naive_bayes
ckey = os.environ.get('CKEY')
csecret = os.environ.get('CSECRET')
@durcana
durcana / answers.txt
Created June 6, 2016 19:33
Wiki Crawler Answers
8a. 94.6%
8b. {9: 78, 10: 52, 12: 50, 11: 45, 13: 42, 17: 35, 16: 34, 15: 28, 18: 28,
14: 26, 8: 21, 19: 14, 20: 10, 6: 3, 21: 3, 22: 2, 23: 2}
8c. To reduce the number of http requests, we can check if the current page in the search has
already been searched in a previous path. The search path of the same page will always give
the same result, and thus does not need to be repeated. Once that page is in a new path,
we can just add the path length of the previous search to the length of the current search
up to that page.
@durcana
durcana / dfs.py
Created February 22, 2016 00:55
Trying to create generate random tree using Node objects. Code not working yet but here's my progress. Skips every other node in node_children, and dfs not working yet.
import random
class Node:
def __init__(self, name):
self.name = name
self.children = []
self.visited = False
def add_child(self, new_node):
@durcana
durcana / breadth_first_search.py
Created February 21, 2016 19:39
Both breadth first search and depth first search scripts after speaking with David from Recurse Center
import networkx as nx
"""
Since append() adds the node to the end of check_list, it will check all of the nodes at one level
before moving on to the next. To check this to be true without doing pdb, you can uncomment the
line in the code and see how check_list changes. Done this way, we do not change the actual graph,
but still do not need a 'visited' attribute.
"""
@durcana
durcana / breadth_first_search.py
Created February 21, 2016 17:39
Breadth first search code written before interview with David for Recurse Center. Will also change this as I change dfs
import networkx as nx
def bfs(node, graph):
roots = [n for n, d in graph.in_degree().items() if d == 0]
for root in roots:
if node in graph.successors(root):
return node
@durcana
durcana / depth_first_search.py
Created February 18, 2016 22:53
Depth first search code for pair programming with the Recurse Center
import networkx as nx
def dfs(node, graph, start):
leaves = [n for n, d in graph.out_degree().items() if d == 0]
root = [n for n, d in graph.in_degree().items() if d == 0]
if start == "":
start = root[0]
if start == node: