Skip to content

Instantly share code, notes, and snippets.

View k-zehnder's full-sized avatar
😀

Kevin Zehnder k-zehnder

😀
View GitHub Profile
@kmhoran
kmhoran / consumer.py
Last active January 18, 2022 20:27
Flask Consumer of Kafka Video Stream
import datetime
from flask import Flask, Response
from kafka import KafkaConsumer
# Fire up the Kafka Consumer
topic = "distributed-video1"
consumer = KafkaConsumer(
topic,
bootstrap_servers=['localhost:9092'])
@bennadel
bennadel / .dockerignore-web
Last active March 23, 2024 16:24
From Noob To Docker On DigitalOcean With Nginx, Node.js, DataDog Logs, DogStatsD, And LetsEncrypt SSL Certificates
.*
Dockerfile
node_modules
@fomightez
fomightez / useful_pandas_snippets.py
Last active April 4, 2025 21:17 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
df['Column Name'].unique() # Note, `NaN` is included as a unique value. If you just want the number, use `nunique()` which stands
# for 'number of unique values'; By default, it excludes `NaN`. `.nunique(dropna=False)` will include `NaN` in the count of unique values.
# To extract a specific column (subset the dataframe), you can use [ ] (brackets) or attribute notation.
df.height
df['height']
# are same thing!!! (from http://www.stephaniehicks.com/learnPython/pages/pandas.html
# -or-
# http://www.datacarpentry.org/python-ecology-lesson/02-index-slice-subset/)
@redlotus
redlotus / docstrings.py
Created October 2, 2017 04:34
Google Style Python Docstrings
# -*- coding: utf-8 -*-
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
@kylehounslow
kylehounslow / client.py
Last active April 23, 2024 10:58
Send and receive images using Flask, Numpy and OpenCV
from __future__ import print_function
import requests
import json
import cv2
addr = 'http://localhost:5000'
test_url = addr + '/api/test'
# prepare headers for http request
content_type = 'image/jpeg'
@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);
}
@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 %}
@wojteklu
wojteklu / clean_code.md
Last active April 18, 2025 12:16
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

@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
@vasanthk
vasanthk / System Design.md
Last active April 18, 2025 07:54
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?