Skip to content

Instantly share code, notes, and snippets.

View mosdevly's full-sized avatar

Mosdev mosdevly

  • San Francisco, CA
View GitHub Profile
@mosdevly
mosdevly / App.jsx
Last active August 7, 2020 19:29
React component examples.
import React, {Component} from 'react';
import './App.css';
import CounterList from "./CounterList";
class App extends Component {
constructor(props) {
super(props);
this.state = {
counters: []
}
@Test
void createDriver() throws Exception {
String driverJson = "{\"nickname\": \"Speed Racer\", \"firstName\": \"Tester\", \"lastName\": \"McTesty\", \"birthday\": \"1990-04-18\"}";
MockHttpServletRequestBuilder request = post("/api/drivers/new")
.contentType(MediaType.APPLICATION_JSON)
.content(driverJson);
mvc.perform(request)
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").exists());
@mosdevly
mosdevly / example.html
Created March 13, 2020 17:55
Flask with jQuery API Request Demo
{% extends 'base.html' %}
{% block content %}
<script src="{{ url_for('static', filename='js/example.js') }}"></script>
<div id="users">
</div>
{% endblock %}
@mosdevly
mosdevly / solid_bad.py
Last active July 18, 2019 14:22
Examples for the SOLID principles
"""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
# 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
@mosdevly
mosdevly / spotty.py
Last active November 8, 2018 01:26
Spotify Auth Snippet
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}"
@mosdevly
mosdevly / models.py
Last active September 24, 2021 15:54
Flask Snippets -- Common architecture patterns when building Flask applications. For learners.
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'
"""
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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) '