Skip to content

Instantly share code, notes, and snippets.

Benefits

  • Configuration is not in code
  • Easily deploy of crud apps
  • Easy scaling
  • Easily addons
  • Enforces scalable architecture

Drawbacks

###########################
# 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
@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
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 / _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 = {
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
# 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
@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
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']