This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
from bs4 import BeautifulSoup | |
# What year? | |
year = 2011 | |
# Create/open a file called wunder.txt | |
f = open('wunder-data-' + str(year) + '.txt', 'w') | |
f.write('datestamp,tmean,tmax,tmin,precip,dewpoint\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nashville's hottest days in 2011 | |
weather2011 <- read.csv('wunder-data-2011.txt', sep=',', header=TRUE) | |
fill_colors <- c() | |
for (i in 1:length(weather2011$tmax)) { | |
if (weather2011$tmax[i] > 80) { | |
fill_colors <- c(fill_colors, '#CC0000') | |
} else { | |
fill_colors <- c(fill_colors, '#CCCCCC') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#via http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python | |
import fnmatch | |
import os | |
matches = [] | |
for root, dirnames, filenames in os.walk('src'): | |
for filename in fnmatch.filter(filenames, '*.c'): | |
matches.append(os.path.join(root, filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to generate a secret key with Python | |
# via http://flask.pocoo.org/docs/quickstart/ | |
import os | |
os.urandom(24) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Follow instructions here: http://flask.pocoo.org/snippets/65/ | |
# You'll need to make sure you have the right Python version and any packages installed: http://docs.webfaction.com/software/python.html | |
# This tweak to index.py is what made it actually work: http://stackoverflow.com/questions/3696606/how-to-solve-import-errors-while-trying-to-deploy-flask-using-wsgi-on-apache2 | |
import sys | |
yourappname = "/home/username/webapps/yourappname/htdocs" | |
if not yourappname in sys.path: | |
sys.path.insert(0, yourappname) | |
from yourappname import app as application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/edit/<int:page_id>', methods=['GET']) | |
def edit(page_id): | |
context = "Edit" | |
page = Page.query.get(page_id) | |
title = page.title | |
text = page.text | |
return render_template('edit.html', title=title, text=text, context=context) | |
@app.route('/edit/<int:page_id>', methods=['POST']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sentiment_analysis' | |
def get_sentiment(text) | |
sa = SentimentAnalysis::Client.new(:api_key => 'YOUR_API_KEY') | |
sentiment = sa.review(:text => text, :format => :json) | |
# The limit on the text is 360 characters. | |
return sentiment | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def twitter_link(handle) | |
avatars_path = 'public/img/avatars/' | |
avatar = handle + '.jpg' | |
avatar_path = avatars_path + avatar | |
img_tag = "<img src='#{avatar_path.sub(/^public/, '')}' />" | |
# Check and see if there's already an avatar. | |
unless File.exists?(avatar_path) | |
# We don't have it. Let's try to get it from Twitter. | |
begin |
NewerOlder