Skip to content

Instantly share code, notes, and snippets.

View duhaime's full-sized avatar

Douglas Duhaime duhaime

View GitHub Profile
# Import a dictionary of words with positive valence and another dictionary
# of words with negative valence. Get access to Twitter. Search Twitter for
# tweets that discuss 4 topics. Grab the text from those tweets. Combine
# tweets into database. Look for words with positive and negative valence
# in those tweets. Subtract words with negative valence from words with
# positive valence to get net subjective response to topic of interest.
# Create graphs. Code by Gaston Sanchez, edited by Douglas Duhaime
library(twitteR)
library(plyr)
import os
from os import makedirs
from subprocess import call
# It seems this script must be run from inside C:\mallet-2.0.7
# Set the path to your mallet package (make sure to change the mallet
# version number, if necessary)
# Create directory "inputdirectory" within this mallet directory. Load the
# files to be analyzed in "inputdirectory"
### Locating UI elements ###
# By ID
<div id="coolestWidgetEvah">...</div>
element = driver.find_element_by_id("coolestWidgetEvah")
or
from selenium.webdriver.common.by import By
element = driver.find_element(by=By.ID, value="coolestWidgetEvah")
# By class name:
This file has been truncated, but you can view the full file.
"Mikysco, Bartholdus." "The spanish-Austrian league:" 1.0 1
"Miller, John," "The evidence, (as taken down in court) in the trial wherein the Rt. Hon. John, Earl of Sandwich, was plaintiff, and J. Miller, defendant, before William, Lord Mansfield, And a Special Jury, in the Court of King's Bench, July 8, 1773." 1.0 1
"Whiston, Thomas." "A sermon preached at Wisbech, Sunday, March 11. 1743." 1.0 1
"Whiston, Thomas." "The important doctrines of original sin," 1.0 1
"Highmore, Joseph," "Observations on a pamphlet, entitled, \"christianity not founded on argument.\" By a Christian freethinker, Who apprehends that Infidels cannot be effectually answered, on any Principles less general, than those which he has adopted. The only apology he can make for publishing (at this distance of time) animadversions on a pamphlet printed so long since, is, that he has just now (and never before) perused it with that design." 1.0 1
@duhaime
duhaime / gist:9330473f9a4e288f00af
Created September 13, 2015 00:35
Cluster vectors with K-Means
from __future__ import division
from sklearn.cluster import KMeans
from numbers import Number
from pandas import DataFrame
import sys, codecs, numpy
class autovivify_list(dict):
'''Pickleable class to replicate the functionality of collections.defaultdict'''
def __missing__(self, key):
value = self[key] = []
@duhaime
duhaime / Gemfile
Created June 22, 2016 14:18 — forked from zackrw/Gemfile
Yale CAS and user info with Rails (after security "upgrade" on LDAP)
#
## Add the rubycas-client gem to your Gemfile and run bundle install
#
gem 'rubycas-client'
gem 'mechanize'
@duhaime
duhaime / DragTransform
Created July 3, 2016 10:48 — forked from fta2012/DragTransform
Slightly modified compiled coffeescript from this codepen: http://codepen.io/fta/pen/ifnqH. Paste into console on a page that has jQuery to load the two dependent libraries (jquery-ui and numericjs). Then call makeTransformable('#selector-name') to make that element WYSIWYG editable. Use inspector to get the CSS for the transforms.
var selector = 'img' // Replace this with the selector for the element you want to make transformable
jQuery.getScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', function() {
jQuery.getScript('//cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js', function() {
(function() {
var $, applyTransform, getTransform, makeTransformable;
$ = jQuery;
@duhaime
duhaime / Matrix Transform Gist
Created July 6, 2016 19:51
Matrix Transform Gist: calculates the X matrix for AX = B linear algebra equation
import numpy as np
"""
This script identifies a transform matrix X such that
one can determine how to perform a css matrix translation
to map one div's coordinates to those of another.
A fiddle demonstrating the input div, output div,
and a transformation that maps the input to the output
may be found here: https://jsfiddle.net/dduhaime/9444Lnjp/
@duhaime
duhaime / 2D Point Project via Transformation Matrix
Last active July 8, 2016 12:17
Project points from input 2d space to output 2d space
import numpy as np
"""
This script calculates a transform matrix X such that
one can project points in one 2d coordinate system
into another 2d coordinate system. Because the solution uses
a homogenous coordinate space to represent points,
the projection may involve rotation, translation, shearing,
and any number of other forces acting on the input matrix
space.
@duhaime
duhaime / Installing CouchDB 1.6.1 and Apache2 on Ubuntu 14.04
Last active February 2, 2019 09:38
Installing CouchDB 1.6.1 and Apache2 on Ubuntu 14.04
# Steps to install CouchDB 1.6.1 and Apache2 on Ubuntu 14.04
# On AWS, select the Ubuntu 14.04 standard box (ami-2d39803a)
# edit security groups to add the "HTTP" rule, which exposes port 80 to traffic from 0.0.0.0
# then add a "Custom TCP rule", exposing port 5984 to traffic from 0.0.0.0
# launch and ssh to the instance
# become root
sudo -s