Skip to content

Instantly share code, notes, and snippets.

@payoung
payoung / inheritance.py
Last active December 18, 2015 23:49 — forked from eleddy/inheritance.py
#!/usr/bin/python
class Toy(object):
inventory = 0
def __init__(self, price, name, quantity):
self.price = price
self.name = name
self.quantity = quantity
@payoung
payoung / tsp_plot.py
Created July 26, 2013 07:51
Python function that plots the data from a traveling salesman problem that I am working on for a discrete optimization class on Coursera. It can take multiple iterations of the path between nodes and plot out the current path as well as the old paths. Helps with troubleshooting and improving the algorithms that I am working on.
import matplotlib.pyplot as plt
def plotTSP(path, points, num_iters=1):
"""
path: List of lists with the different orders in which the nodes are visited
points: coordinates for the different nodes
num_iters: number of paths that are in the path list
"""
@payoung
payoung / kdtree_evaluation.py
Created August 6, 2013 03:08
This script compares the performance of three different methods for finding the nearest neighbors from a list of coordinates. The first method is a simple 'for loop'. The second method uses the KDTree object from the scipy.spatial library. The third method uses cKDTree from the scipy.spatial library. Both the KDTree and cKDTree methods are signi…
import numpy as np
import scipy.spatial as ss
from itertools import combinations
from itertools import permutations
import math
import random
from time import clock
def length(point1, point2):
@payoung
payoung / .vimrc
Last active December 24, 2015 06:38
Personal config file for gVim
colorscheme slate
set expandtab
set tabstop=4
set shiftwidth=4
map <F2> :retab
set guifont=Monospace\ 8
" To enable the saving and restoring of screen positions.
let g:screen_size_restore_pos = 1
@payoung
payoung / AwsConnect.py
Created October 3, 2013 06:27
This is a python class wrapped around a number of common boto methods that I use to access AWS. Makes the code a little cleaner and abstracts away the details of making the connection to aws. At the moment it only contains methods to push and pull data to S3. WIll most likely add a method to retrieve a list files in a S3 bucket, and possibly add…
import boto
import boto.s3.connection
# credentials.py should contain the access_key and secret_key which are needed for
# the boto S3 connection
import credentials as cr
class AwsConnect(object):
def __init__(self, bucket):
self.bucket = bucket
@payoung
payoung / SurfCheck.py
Created September 24, 2014 20:36
One of the first python programs I wrote. For some reason, I chose to download the html and save to text files. I think I was having trouble working with the raw html with bs4. Anyway, I am leaving it 'as is' mostly for the sake of having a reference point in regards to how my python programming improve (or doesn't) over time.
#-----------------------------------------------------------------------------#
# Parses the converted html files to find the swell heights and conditions
# and then prints these out into formatted tables
#-----------------------------------------------------------------------------#
import urllib2
from bs4 import BeautifulSoup
# Scarpe the site and convert html to text
@payoung
payoung / ChrootSetup
Last active November 28, 2015 03:05
Crouton/Chromebook Setup Instructions and Preferences
# Setup guide for chromebook
# Crouton chroot comes with
# stripped down versions of the OS, so need to add a lot
# of applications
# Due to issues with the anaconda distribution
# and virtualenv, I am running two trusty/unity chroots
# one for data analysis work and one for development work
# I'll call the data chroot 'datatrusty' and the dev chroot