Skip to content

Instantly share code, notes, and snippets.

View geoffalday's full-sized avatar

Geoff Alday geoffalday

View GitHub Profile
@geoffalday
geoffalday / weather.r
Created June 15, 2012 15:58
Displays hottest days using R
# 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')
@geoffalday
geoffalday / files.py
Created May 3, 2012 10:28
Get files from directory
#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))
@geoffalday
geoffalday / secretkey.py
Created March 12, 2012 12:28
How to generate a secret key with Python
# How to generate a secret key with Python
# via http://flask.pocoo.org/docs/quickstart/
import os
os.urandom(24)
@geoffalday
geoffalday / index.py
Created March 6, 2012 13:19
Getting a Python/Flask app running on Webfaction
# 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
@geoffalday
geoffalday / admin.py
Created January 29, 2012 05:04
Two Methods per Alex
@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'])
@geoffalday
geoffalday / get_sentiment.rb
Created November 1, 2011 14:09
Ruby function for accessing the Viralheat sentiment API
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
@geoffalday
geoffalday / gist:1322089
Created October 28, 2011 11:22 — forked from trvsdnn/gist:1321710
twitter_link
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