Skip to content

Instantly share code, notes, and snippets.

View matthewcornell's full-sized avatar
🎸

Matthew Cornell matthewcornell

🎸
View GitHub Profile
@matthewcornell
matthewcornell / example1.py
Last active September 16, 2015 14:44 — forked from onyxfish/example1.py
Basic example of using NLTK for name entity extraction.
# forked for my own reference
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup as bs
import nltk
def extract_named_ents_from_url(url):
url_bytes = get_bytes_for_url(url)
soup = bs(url_bytes, "lxml")
@matthewcornell
matthewcornell / gist:6107508
Created July 29, 2013 20:27
how to hang mysql from python
import mysql.connector
conn1 = mysql.connector.connect(database='test', user='test', password='test')
curs1 = conn1.cursor()
curs1.execute("create table foo(id text)")
curs1.execute("select * from foo where random()")
# -> mysql.connector.errors.ProgrammingError: 1305 (42000): FUNCTION test.random does not exist
conn2 = mysql.connector.connect(database='test', user='test', password='test')
curs2 = conn2.cursor()
@matthewcornell
matthewcornell / gist:4118588
Created November 20, 2012 15:26
python list cycle alternatives
# current:
def __init__(self, listVals):
self.listVals = listVals
self.currentIndex = -1
def sample(self, ignoredValue):
self.currentIndex = self.currentIndex + 1 if self.currentIndex < len(self.listVals) - 1 else 0
return self.listVals[self.currentIndex]
# % variation: