Skip to content

Instantly share code, notes, and snippets.

@zed
zed / dp.py
Last active January 19, 2022 00:24
Find height, width of the largest rectangle containing all 0's in the matrix
#!/usr/bin/env python
"""Find height, width of the largest rectangle containing all 0's in the matrix.
The algorithm for `max_size()` is suggested by @j_random_hacker [1].
The algorithm for `max_rectangle_size()` is from [2].
The Python implementation [3] is dual licensed under CC BY-SA 3.0
and ISC license.
[1]: http://stackoverflow.com/questions/2478447/find-largest-rectangle-containing-only-zeros-in-an-nn-binary-matrix#comment5169734_4671342
@trey
trey / happy_git_on_osx.md
Last active February 18, 2024 10:46
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "you@example.com"

@ajmendez
ajmendez / age.py
Last active October 16, 2022 18:45
Here is a nice little wikipedia parser for grabbing an date of birth and date of death for a individual with an infobox template. This template is found generally on famous people. Works with people who are still alive by returning None for death_date.
import urllib2, json, pprint, re, datetime
import mwparserfromhell
def _parseDate(wikiDate):
''' Parse a mediawiki date template -- assumes years, month, day
Input:
a mwparser object containing just the date to be parsed
Returns:
datetime.date object of the date
'''
@iamatypeofwalrus
iamatypeofwalrus / roll_ipython_in_aws.md
Last active January 22, 2024 11:18
Create an iPython HTML Notebook on Amazon's AWS Free Tier from scratch.

What

Roll your own iPython Notebook server with Amazon Web Services (EC2) using their Free Tier.

What are we using? What do you need?

  • An active AWS account. First time sign-ups are eligible for the free tier for a year
  • One Micro Tier EC2 Instance
  • With AWS we will use the stock Ubuntu Server AMI and customize it.
  • Anaconda for Python.
  • Coffee/Beer/Time
@ijy
ijy / sublime-text-3-setup.md
Last active January 15, 2024 14:21
My Sublime Text 3 setup.

Sublime Text 3 Setup

Install Package Control

Install Package Control for easy package management.

  1. Open the console with Ctrl+`
  2. Paste in the following:
@jakevdp
jakevdp / discrete_cmap.py
Last active March 8, 2024 14:54
Small utility to create a discrete matplotlib colormap
# By Jake VanderPlas
# License: BSD-style
import matplotlib.pyplot as plt
import numpy as np
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
@nbremer
nbremer / .block
Last active July 25, 2023 13:20
Storytelling with Chord Diagram
height: 750
anonymous
anonymous / model_selection.ipynb
Created August 27, 2015 12:42
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# calculate and visualize silhouette score from k-means clustering.
# plots first two features in 2D and first three features in 3D.
# from: http://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score, silhouette_samples
from mpl_toolkits.mplot3d import Axes3D
##### cluster data into K=1..K_MAX clusters #####
K_MAX = 10
@cfperez
cfperez / log_transformer.py
Created September 10, 2015 23:52
LogTransformer to log scale features in sklearn Pipelines
from sklearn.base import BaseEstimator,TransformerMixin
class LogTransformer(BaseEstimator,TransformerMixin):
def __init__(self, constant=1, base='e'):
from numpy import log,log10
if base == 'e' or base == np.e:
self.log = log
elif base == '10' or base == 10:
self.log = log10
else: