- Serving private content with signed URLs and signed cookies
- Create a key pair for a trusted key group
from django.db import models | |
from django.utils.text import slugify | |
class Content(models.Model): | |
title = models.CharField(max_length=100) | |
slug = models.SlugField(max_length=100) | |
def save(self, *args, **kwargs): | |
# simple-stupid way to guarantee slug uniqueness | |
n = 1 |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<form action="" method="post"> | |
<input type="hidden" name="csrfmiddlewaretoken" |
class Jarad: | |
def __init__(self, **kwargs): | |
for k,v in kwargs.items(): | |
setattr(self, k, v) |
""" | |
@author: Claudio Bellei | |
Site: http://www.claudiobellei.com/2016/11/15/changepoint-frequentist/ | |
""" | |
import numpy as np | |
import pandas as pd | |
import csv | |
import matplotlib | |
import matplotlib.pyplot as plt |
import difflib | |
""" | |
This simple piece of code can help detect similar strings using SequenceMatcher | |
""" | |
data = ['temporary tatoos', 'temporary tatto', 'tempoary tatoo', 'tempoary tattoo', 'temporary tattoos'] | |
for line in data: | |
for word in line.split(): | |
i = difflib.SequenceMatcher(None, word, 'tattoo').ratio() |
import pandas as pd | |
import numpy as np | |
from nltk.stem import PorterStemmer, WordNetLemmatizer | |
from nltk.corpus import stopwords | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn import cluster | |
stemmer = PorterStemmer() |
def fit_model(X, y, **kwargs): | |
print(kwargs) | |
print(kwargs['max_iter']) | |
pipeline = Pipeline([ | |
('decode', FunctionTransformer(func=lambda x: x.apply( | |
lambda url: parse.unquote(parse.unquote(url))), validate=False)), | |
('cvect', CountVectorizer(binary=True, max_features=1000, stop_words='english', | |
token_pattern=r'\b\w[\w\.\-\,]+\b')), | |
('clf', MLPClassifier(verbose=1, solver='sgd', max_iter=kwargs['max_iter'] or 1000, | |
tol=0.00001, learning_rate='adaptive', learning_rate_init=0.05)), |
def scale_between(series, min_amt, max_amt): | |
series_min = series.min() | |
series_max = series.max() | |
return (((max_amt - min_amt)*(series - series_min)) / (series_max - series_min)) + min_amt |
def ma_subplots(df, window, title=None): | |
fig, ax = plt.subplots(df.shape[1], 1, figsize=(12, 7)) | |
ax = ax.ravel() | |
for i,col in enumerate(df): | |
mean = df[col].mean() | |
ma = df[col].rolling(window).mean() | |
mstd = df[col].rolling(window).std() | |
ax[i].plot(df.index, df[col], color='k', label=col) | |
ax[i].plot(ma.index, ma, 'b', label='Moving Avg.') | |
ax[i].fill_between(mstd.index, ma - 2*mstd, ma + 2*mstd, color='b', alpha=0.2) |