Skip to content

Instantly share code, notes, and snippets.

from math import sqrt
class WelfordRunningVariance(object):
"""
Python implentation of Welford's running variance algorithm
http://www.johndcook.com/standard_deviation.html
"""
def __init__(self):
self._count = 0
self._mean = None
@monkut
monkut / nginx_uwsgi_application_setup.md
Created November 22, 2015 06:44
(ubuntu 14.04) uwsgi アプリとnginxの基本設定

uwsgi アプリとnginxの基本設定

長い間、pythonでウエブアプリを使う場合、apache+mod_wsgiを使ってきました。 この数年でnginxが早いと評判となってきて、apacheとの設定違いはきになっていました。

去年、自分が作ったウエブアプリのrequests/秒が上げたくて、apache用のmod_wsgiの代わりに、インストールしやすいpython用のウエブサーバ探したら、 uwsgiを見つけました。uwsgiで同じアプリ試したところ、apache+mod_wsgiより早い結果が出ました。

次は、virturalenv/venvを使った開発のながれです。 これも、数年前から動きは、聞きましたが、なかなかその必要なユースケースがなく、virutalenvの使い方を勉強しなかったんですが、

Anaconda(ウインドウズ)のインストールでパッケージを更新する方法

  1. プロクシーを設定

> ウインドウズ用のプロクシーを通すため、https://github.com/heupel/ntlmaps を使っています

# ポートは、NTLMAPS内で設定
Tool Creation Guidelines for High Performance Teams
The objective of these guidelines are to clearly identify what is desired of a tool for use in fast moving teams with clear objectives.
- Minimize necessary user actions/input
@monkut
monkut / python3 build on RHEL72
Created December 1, 2016 04:50
python3 build on RHEL72
python3 install
------------------------
1. install dependencies::
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel li
2. Configure/build make::
@monkut
monkut / merge_pdfs.py
Last active August 7, 2017 02:24
Merge Multiple PDFs into 1 with PyPDF2
from PyPDF2 import PdfFileReader, PdfFileMerger
pdfs_to_merge = [
# Page numbers are 0 start
# (FILEPATH, (START_PAGE, UNTIL_PAGE)) -- If None, all pages output
(None, (0, 5),
]
# Creating an object where pdf pages are appended to
@monkut
monkut / aws_and_dask-gettingstarted.md
Last active September 11, 2017 04:10
Getting Started with AWS and Dask

Prereqs

NOTE: this assumes python >= 3.6

On ubuntu make sure that you have the python3.6-dev package installed in order to build the necessary packages

  • python3.6
  • jq

Preparation

@monkut
monkut / sample.ipynb
Last active December 8, 2017 05:06 — forked from egradman/sample.ipynb
Simple Google Spreadsheets to Pandas DataFrame in IPython Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@monkut
monkut / python_welfords_class.py
Last active February 6, 2018 00:42
Sample implementation and sample usage of Welford's method for calculating running variance (and standard aggregations)
"""
A class for managing running calculations for:
- min
- average
- max
- stddev
- var
- count
Example Usage:
@monkut
monkut / backends.py
Last active March 12, 2018 13:30
django (1.8) python3 LDAP (via ldap3) Authentication backend
"""
django (1.8) python3 LDAP (via ldap3) Authentication backend
Assumes 'AUTH_INFORMATION' is defined in settings.py in the form:
AUTH_INFORMATION = { 'LDAP'{
'USERNAME_SEARCH_FILTER': <ldap search filter, for example, '(uid={})'>,
'HOST': <ldap server host>,
'PORT': <ldap server port (integer)>,
'BASE_DN': <ldap base DN>,