This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.datasets import fetch_20newsgroups | |
from sklearn.feature_extraction.text import CountVectorizer | |
def get_vectors(vocab_size=5000): | |
newsgroups_train = fetch_20newsgroups(subset='train') | |
vectorizer = CountVectorizer(max_df=.9, max_features=vocab_size) | |
vecs = vectorizer.fit_transform(newsgroups_train.data) | |
vocabulary = vectorizer.vocabulary | |
terms = np.array(vocabulary.keys()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Google Apps Script is clunky. You have to make a spreadsheet in Google Docs, then Tools->Script Editor. Then you can paste this code in a new project. Try running it once to make sure it works, then under Triggers select moveRandomSnoozes, time-based, and whatever frequency you want. (I had it going daily, but just changed the probabilities and set it to hourly; we'll see how I like that.) | |
This was partly based on the Gmail Snooze script that was making the rounds a few months ago. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dirichlet process Gaussian mixture model | |
import numpy as np | |
from scipy.special import gammaln | |
from scipy.linalg import cholesky | |
from sliceSample import sliceSample | |
def multinomialDraw(dist): | |
"""Returns a single draw from the given multinomial distribution.""" | |
return np.random.multinomial(1, dist).argmax() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% All based on Rasmussen and Williams. | |
N = 1000; | |
lo=0; hi=5; | |
x = linspace(lo, hi, N); | |
%xn = [2, 2.5, 3]'; | |
%yn = [-1.9, -2, -1.9]'; | |
xn = ([-4, -3, -1, 0, 2]'+5)/2; | |
yn = [-2, 0, 1, 2, -1]'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Event = (function() { | |
function Event(name) { | |
this.name = name; | |
this.listeners = []; | |
} | |
Event.prototype.when = function(context, callback) { | |
if (arguments.length === 1) { | |
callback = context; | |
context = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logBrowserStats() { | |
function getAsObject(objectLike) { | |
var obj = {}, key; | |
for (key in objectLike) { | |
var val = objectLike[key]; | |
if (typeof val === 'number' || typeof val === 'string') { | |
obj[key] = val; | |
} | |
} | |
return obj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
tr = [ | |
(u'\u2018', "`"), | |
(u'\u2019',"'"), | |
(u'\u201c', "``"), | |
(u'\u201d', "''") | |
] | |
s = sys.stdin.read().decode('utf8') | |
for a, b in tr: | |
s = s.replace(a, b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lxml.html | |
import sys | |
doc = lxml.html.fromstring(sys.stdin.read()) | |
for elt in doc.cssselect('a, div, style, title'): | |
elt.getparent().remove(elt) | |
s = u'\n'.join((elt.text_content() for elt in doc.cssselect('p, h1, h2, h3, h4, h5, h6'))) # add other nodes if I forgot any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.bash_profile: executed by bash(1) for login shells. | |
source .bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# don't put duplicate lines in the history. See bash(1) for more options | |
HISTCONTROL=ignoredups:ignorespace | |
HISTIGNORE=ls:fg | |
# append to the history file, don't overwrite it | |
shopt -s histappend | |
# for setting history length, see HISTSIZE and HISTFILESIZE in bash(1) | |
HISTSIZE=10000 | |
HISTFILESIZE=20000 |
OlderNewer