Skip to content

Instantly share code, notes, and snippets.

""" Prints the probability of a successful shot given argv[1] attempts where
each has an argv[2] probability of success.
"""
from __future__ import division
import random
import sys
from __future__ import division
import itertools
import math
import pprint
import random
import sys
INF = float('inf')
"""Readability
[Wiki](http://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_test)
The Flesch Reading Ease Score (FRES) is
206.835 - 1.015 * (#words / #sentences) - 84.6 * (#syllables / #words)
Example:
"The Australian platypus is seemingly a hybrid of a mammal and reptilian
creature."
@colinpollock
colinpollock / gist:5763710
Created June 12, 2013 08:33
ES demo of document fields only working w/ indexed field.
#
# http://www.elasticsearch.org/guide/reference/modules/scripting/
#
# Create the index
curl -XPOST 'http://localhost:9200/people/' -d '{
"settings" : {
},
"mappings" : {
"person" : {
@colinpollock
colinpollock / gist:5871423
Created June 26, 2013 20:38
JestClient search authentication
public static ClientConfig getClientConfig(String connectionUrl) {
ClientConfig clientConfig = new ClientConfig();
LinkedHashSet<String> servers = new LinkedHashSet<String>();
servers.add(connectionUrl);
clientConfig.getServerProperties().put(ClientConstants.SERVER_LIST, servers);
return clientConfig;
}
public static JestClient getClient(String connectionUrl) {
JestClientFactory factory = new JestClientFactory();
IT'S GO TIME
GIDDYUP "Hello, Newman"
YADA YADA YADA
IT'S GO TIME
YO YO MA isLessThan20
IT'S IN THE VAULT @IT'S NOT A LIE IF YOU BELIEVE IT
YO YO MA n
IT'S IN THE VAULT 0
YO YO MA multiple
IT'S IN THE VAULT @IT'S NOT A LIE IF YOU BELIEVE IT
CRY CRY AGAIN isLessThan20
from collections import defaultdict
import random
restaurants = [
'za', 'jake', 'spoon', 'hacienda', 'bridgetender', 'river grill', 'rosie', 'sunnyside'
]
people = ['megan', 'jan', 'todd', 'colin', 'michelle']
random.shuffle(people)
"""Make initial clusters of categories to bootstrap top-level categories."""
from collections import defaultdict
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans, MiniBatchKMeans
from j_util import get_rows
import spacy
from spacy.pipeline import EntityRuler
nlp = spacy.load("en_core_web_sm")
ruler = EntityRuler(nlp, validate=True)
ruler.add_patterns[
{
"label": "PHRASE",
"pattern": [