Skip to content

Instantly share code, notes, and snippets.

Proto Protosac

  • San Francisco, CA
Block or report user

Report or block Protosac

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Protosac
Protosac / solid_bad.py
Last active Jul 18, 2019
Examples for the SOLID principles
View solid_bad.py
"""Open/Closed Principle
Example inspired by this wonderful piece here: http://joelabrahamsson.com/a-simple-example-of-the-openclosed-principle/
"""
# Area calculator: calculate area of a rectangle
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
View doubly_linked_list.py
# LinkedList
class Node:
def __init__(self, value):
self.value = value
self.next = None
self.previous = None
def set_next(self, node):
self.next = node
node.previous = self
@Protosac
Protosac / spotty.py
Last active Nov 8, 2018
Spotify Auth Snippet
View spotty.py
import requests
import base64
# STEP 1: Get authorization token
SPOTIFY_AUTH_URL = 'https://accounts.spotify.com/api/token'
SPOTIFY_CLIENT_ID = 'your_client_id'
SPOTIFY_CLIENT_SECRET = 'your_client_secret'
client_string = f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_CLIENT_SECRET}"
@Protosac
Protosac / models.py
Last active Nov 6, 2018
Flask Snippets -- Common architecture patterns when building Flask applications. For learners.
View models.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def connect_to_db(app):
"""Helper function to configure the database with the flask app."""
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///blog'
View banker.py
"""
Class Review
Study the classes below. Run this script to see how the program works.
- take note of questions you have
- try changing small pieces of code to experiment with how classes work
Practice:
Create a subclass of Customer named Executive. This is a person who's a customer that owns a business.
- Executives who own an account must deposit at least $10,000 into their account on creation.
View markov_chain.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View flask_request.py
request = {'environ': {'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.9,ca;q=0.8',
'HTTP_CACHE_CONTROL': 'max-age=0',
'HTTP_CONNECTION': 'keep-alive',
'HTTP_DNT': '1',
'HTTP_HOST': 'localhost:5000',
'HTTP_UPGRADE_INSECURE_REQUESTS': '1',
'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
View swap.py
if random_choice_index != index_we_are_choosing_for:
# This is a multi-line expression
the_list[index_we_are_choosing_for], the_list[random_choice_index] = \
the_list[random_choice_index], the_list[index_we_are_choosing_for]
# is equivalent to:
the_list[index_we_are_choosing_for], the_list[random_choice_index] = the_list[random_choice_index], the_list[index_we_are_choosing_for]
View git_workflow.sh
# ALWAYS FORK A REPOSITORY IF YOU'RE WORKING ON THAT PROJECT
# 1. Never work from the main project repo. All devs work from their own forks!
# You should have at least 2 remotes: upstream and origin
# - upstream: the main project repository
# - origin: your fork
# Add a remote
git remote add name_for_your_remote https://github.com/to_your/repository.git
# Example:
@Protosac
Protosac / big_o.py
Last active Nov 28, 2018
Practice adding any of the missing algorithms. Also beware that there may be logical errors below, but use the comments to help you correct them.
View big_o.py
class BigO(object):
"""
Big O Notation by example
Each method below illustrates what algorithms of increasing complexity look like.
"""
from copy import deepcopy
def __init__(self, data_collection):
"""
You can’t perform that action at this time.