Skip to content

Instantly share code, notes, and snippets.

View k-zehnder's full-sized avatar
😀

Kevin Zehnder k-zehnder

😀
View GitHub Profile
@ronreiter
ronreiter / sqlalchemy_example.py
Created August 10, 2015 06:21
SQLAlchemy Example
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker, joinedload
# For this example we will use an in-memory sqlite DB.
# Let's also configure it to echo everything it does to the screen.
engine = create_engine('sqlite:///:memory:', echo=True)
# The base class which our objects will be defined on.
Base = declarative_base()
@livoras
livoras / finite-state-machine.js
Last active April 27, 2023 19:54
Simplest JavaScript Finite State Machine
/**
* @param {Object} settings
* - {String} current
* - {Object} states
* - {Object} actions
* @constructor
*/
function StateMachine(settings) {
this._current = settings.initState
this.actions = settings.actions
@meganspeir
meganspeir / app.py
Created October 29, 2015 18:29
The Martian
import requests
from flask import Flask
from flask import request, send_from_directory
from twilio import twiml
from martianify import martianify
UPLOAD_FOLDER = '/path/to/your/project/'
# App declaration and configuration
@kphretiq
kphretiq / Flask-SqlAlchemy-Many-to-Many.py
Last active March 16, 2024 17:18
A (hopefully) simple demo of how to do many-to-many relationships using Flask-SQLAlchemy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from flask import Flask, url_for
from flask_sqlalchemy import SQLAlchemy
"""
Flask-SQLAlchemy many-to-many relationship using helper table
http://flask-sqlalchemy.pocoo.org/2.1/models/
Hippies love their dogs.
@tasdikrahman
tasdikrahman / python_tests_dir_structure.md
Last active February 10, 2025 22:15
Typical Directory structure for python tests

A Typical directory structure for running tests using unittest

Ref : stackoverflow

The best solution in my opinion is to use the unittest [command line interface][1] which will add the directory to the sys.path so you don't have to (done in the TestLoader class).

For example for a directory structure like this:

new_project

├── antigravity.py

@vasanthk
vasanthk / System Design.md
Last active April 12, 2025 20:07
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@mcxiaoke
mcxiaoke / gist:b7dcbfdc800b06a5439bb7eb2cd223dd
Created August 12, 2016 06:34 — forked from AJRenold/gist:4171988
Returning MySQL query data in a csv file with Flask
## I'm working on a project using Flask to access a database and then
## pass on query data to a client where the data will be graphed
## in the browser.
## I wanted to enable users to retrieve the graph data
## in a csv file after clicking a button on the client.
## This is a generalized version of how I did it:
# imports other than Flask
import csv
from sqlalchemy import create_engine
@wojteklu
wojteklu / clean_code.md
Last active April 12, 2025 23:57
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@greyli
greyli / index.html
Last active May 16, 2022 12:58
Photo upload demo with Flask-Uploads and Flask-WTF.
<!-- create a folder named templates, put this file into it -->
<!DOCTYPE html>
<title>Upload File</title>
<h1>Photo Upload</h1>
<form method="POST" enctype="multipart/form-data">
{{ form.hidden_tag() }}
{{ form.photo }}
{% for error in form.photo.errors %}
<span style="color: red;">{{ error }}</span>
{% endfor %}
@ralekna
ralekna / gist:c92be925967703b489a685c8b6c4b4f1
Created March 21, 2017 09:17
Sinon Mongoose mock example
import * as sinon from 'sinon';
import * as Mongoose from 'mongoose';
import { expect } from 'chai';
// test utility
function areObjectIdsEqual(id1: Mongoose.Types.ObjectId | string, id2: Mongoose.Types.ObjectId | string) {
let normalizedId1: Mongoose.Types.ObjectId = new Mongoose.Types.ObjectId(id1.toString());
let normalizedId2: Mongoose.Types.ObjectId = new Mongoose.Types.ObjectId(id2.toString());
return normalizedId1.equals(normalizedId2);
}