Skip to content

Instantly share code, notes, and snippets.

View okomestudio's full-sized avatar

Taro Sato okomestudio

View GitHub Profile
@okomestudio
okomestudio / pca_kmeans_biplot.py
Last active August 29, 2015 14:00
This is an example of using PCA and biplot. The observations are colored by k-means clustering.
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
"""Biplot example using pcasvd from statsmodels and matplotlib.
This is an example of how a biplot (like that in R) can be produced
using pcasvd and matplotlib. Additionally, this example does k-means
clustering and color observations by which cluster they belong to.
"""
import matplotlib.pyplot as plt
@okomestudio
okomestudio / chisq_distribution.py
Created May 12, 2014 18:26
Chi-squared distribution
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import chi2
def main():
colors = 'bgrcmyk'
n = 40000
@okomestudio
okomestudio / findstr.sh
Last active August 29, 2015 14:04
Search for files containing a specified string.
#!/bin/bash
##############################################################################
# findstr
#
# Search for files containing a specified string. Show the file path,
# line number, and the line itself containing a specified string.
#
# EXAMPLE:
#
# To search for all the files with the file extension .html containing
#!/usr/bin/bash
#
# For configuring EC2 Debian/Jessie instance.
#
sudo apt-get update
sudo apt-get -y upgrade
################
# general system
@okomestudio
okomestudio / decorators.py
Created April 3, 2015 23:50
check_value decorator -- catches and logs an exception happening within a decorated function or method
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import functools
import inspect
from itertools import izip_longest
import json
import logging
import os
import sys
from traceback import format_tb
"""
A Python Singleton mixin class that makes use of some of the ideas
found at http://c2.com/cgi/wiki?PythonSingleton. Just inherit
from it and you have a singleton. No code is required in
subclasses to create singleton behavior -- inheritance from
Singleton is all that is needed.
Singleton creation is threadsafe.
USAGE:
@okomestudio
okomestudio / ab_test.py
Created May 12, 2014 19:19
An example of A/B test using the chi-squared test for independence.
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
"""An example of A/B test using the chi-squared test for independence."""
import numpy as np
import pandas as pd
from scipy.stats import chi2_contingency
def main():
data = pd.io.parsers.read_csv('n10000.csv')
@okomestudio
okomestudio / delete_s3_bucket.py
Last active January 14, 2016 20:39
Script to delete S3 bucket with contents.
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
"""Delete a S3 bucket with contents.
"""
from __future__ import absolute_import
from gevent import monkey ; monkey.patch_all()
from argparse import ArgumentParser
import boto3
@okomestudio
okomestudio / arc_setup.sh
Created February 9, 2016 21:10 — forked from thomas-barthelemy/arc_setup.sh
W.E. Bridge Phabricator Arcanist (arc) Setup script for Ubuntu
#!/bin/bash
if [ -z "$1" ]; then
echo -e "Missing 1 parameter: Phabricator URL."
echo -e "ex: arc_setup.sh https://phabricator.mycompany.com"
fi
if ! hash git &> /dev/null || ! hash php &> /dev/null; then
echo -e " *****\n ***** INSTALLING GIT AND PHP\n *****"
sudo apt-get install git-core php5-cli php5-curl
fi
@okomestudio
okomestudio / google_style_docstrings.py
Created August 4, 2017 23:53
Google-style docstrings example
# -*- coding: utf-8 -*-
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including