Skip to content

Instantly share code, notes, and snippets.

@jpotts18
jpotts18 / machine_learning_setup.md
Last active October 30, 2016 14:05
Setup Jupyter

Python Machine Learning Setup (Python 2.7)

Install Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code. The language provides constructs intended to enable clear programs on both a small and large scale.

Install Python on Windows

import uuid, random, json
# json.dumps(x, indent=4)
product_range = range(100000,110000)
num_recs_per_type = 20
num_users = 500000
user_ids = [ str(uuid.uuid1()) for _ in range(num_users) ]
rec_types = ['by_x','by_y','by_z']
@jpotts18
jpotts18 / web_scraper.rb
Last active September 17, 2015 05:05
Explaining the Template Method design pattern with a WebScraper
class WebScraper
def execute
create_folders
download_data
parse_data
write_output
end
def create_folder
# This gist is a continuation of a previous gist which defines the MorningAlgorithm class
# https://gist.github.com/jpotts18/1f4269c9e1f22c963a0d
class LateMorningAlgorith < MorningAlgorithm
def work_out
puts "Nope..."
end
def eat_breakfast
class MorningAlgorithm
# This method is used to encapsulate the algorithm's general process.
# Notice this method is not concerned how the methods are accomplished
def execute
wake_up
workout
eat_breakfast
drive_to_work
end
@jpotts18
jpotts18 / _parser.py
Last active September 19, 2015 04:28
import json, urllib2, re, csv
import xml.etree.ElementTree as ET
patterns = {
'YEAR': re.compile('(19|20)\d{2}'),
'ZIP': re.compile('(\d{5})'),
'MILES': re.compile('\d+,?(\d|X|k)+\smiles')
}
occurrences = {
package com.verdad.core;
import android.content.Context;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.HashMap;
import java.util.Map;
@jpotts18
jpotts18 / PizzaFactory.rb
Last active September 1, 2015 15:55
Ruby Factory Pattern
class PizzaFactory
def self.create_pizza(type)
if type == 'Pepperoni'
return PepperoniPizza.new
if type == 'Greek'
return GreekPizza.new
end
end
###########################
# Identify the question
###########################
Identify the question you are trying to solve
# Which car is the most undervalued?
# Are we trying to maximize or minimize a variable?
###########################
# Understand the data