A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
from nltk.probability import DictionaryProbDist | |
from nltk import NaiveBayesClassifier | |
from nltk import FreqDist, ConditionalFreqDist | |
from nltk import BigramAssocMeasures | |
train_samples = { | |
'I hate you and you are a bad person': 'neg', | |
'I love you and you are a good person': 'pos', | |
'I fail at everything and I want to kill people' : 'neg', | |
'I win at everything and I want to love people' : 'pos', |
import HTMLParser | |
class IDParser(HTMLParser.HTMLParser): | |
"""Modified HTMLParser that isolates a tag with the specified id""" | |
def __init__(self, id): | |
self.id = id | |
self.result = None | |
self.started = False | |
self.depth = {} | |
self.html = None |
/** | |
* Plugin function to insert spans into text: | |
* usage | |
* $(document).ready(function() { | |
* $('p.charcount').charSpanCount(); }); | |
* or $(document).ready(function() { | |
* $('p.charcount').charSpanCount({'charcount' : 15}); | |
* }); | |
*/ | |
(function($) { |
import numpy as np | |
import pylab as pl | |
import pandas as pd | |
from sklearn import svm | |
from sklearn import linear_model | |
from sklearn import tree | |
from sklearn.metrics import confusion_matrix |
// this is the background code... | |
// listen for our browerAction to be clicked | |
chrome.browserAction.onClicked.addListener(function (tab) { | |
// for the current tab, inject the "inject.js" file & execute it | |
chrome.tabs.executeScript(tab.ib, { | |
file: 'inject.js' | |
}); | |
}); |
Custom social sharing buttons for Twitter, Facebook, Google Plus, LinkedIn, StumbleUpon, and Pinterest.
via http://siliconstation.com/how-develop-custom-google-plus-button/
<a class="icon-twitter" rel="nofollow"
href="http://twitter.com/"
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" /> | |
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script> | |
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script> | |
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' /> |
""" | |
Model of a Zombie outbreak in France, starting in Grenoble | |
This is a rewrite from this blog post by Max Berrgren: | |
http://maxberggren.github.io/2014/11/27/model-of-a-zombie-outbreak/ | |
with a different country, a slightly different model, and different | |
libraries. The map of population density is taken from Wikimedia Commons |