Skip to content

Instantly share code, notes, and snippets.

@mw3i
mw3i / django-database-standalone.py
Last active April 23, 2024 11:48
Truly Standalone Django-ORM Wrapper
'''
Proof of Concept:
Django devs built an ORM that seems way more straightforward than many existing tools. This class lets you leverage the django-orm without any project settings or other aspects of a django setup.
There are probably weak points and functionality missing, but it seems like a relatively intuitive proof of concept
'''
import os
import django
from django.conf import settings
@boxrick
boxrick / image-cleanup.sh
Created October 29, 2018 17:59
Script to cleanup Google Cloud - GCP - virtual machine images based on project and number of desired images
#!/bin/bash
# Script to cleanup GCP virtual machine images
# How many images of this family do we wish to retain
desired_images=8
image_project="PROJECTHERE"
clean_images()
{
# Function to clean up images, set the default family to megatron base

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@otov4its
otov4its / null_char_field.py
Last active January 16, 2017 15:48
Django NullCharField subclass of the CharField that allows empty strings to be stored as NULL in database
from django.db.models import CharField
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
class NullCharField(CharField):
"""
Subclass of the CharField that allows
empty strings to be stored as NULL in database
"""
@tomysmile
tomysmile / mac-setup-redis.md
Last active March 18, 2024 22:12
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
Benchmark results:
Date: 2016/03/20
Version: asgi_redis 0.8.3 / daphne master / channels master / cpython 2.7.11
Environment: AWS, 3x m3.large (1 daphne, 1 worker, 1 redis)
Source: 1x m3.medium, different AZ, ab for HTTP, channels benchmarker for WS
HTTP GET, Django View (concurrency 10, 10,000 total)
Failures: 0.0%
Rate: 160 req/s
@AnthonySheetz
AnthonySheetz / cronitor.sh
Last active October 21, 2019 10:25 — forked from erchn/cronitor.sh
Cronitor wrapper script for start/stop notifications, now with proper encoding of stderror and optional dumping of stdout
#!/bin/bash
#
# This script surrounds the command passed in with start and finish notifications
# to the cronitor monitoring application.
#
# === SETUP
#
# * Make sure the cronitor script is executable.
#
# chmod +x cronitor
@oleq
oleq / _README.md
Last active January 7, 2024 10:38
A2DP audio streaming using Raspberry PI (Raspbian Jessie)

What is this all about?

This tutorial will turn your Raspberry PI into a simple Bluetooth audio receiver, which plays music through connected speakers. It's like a regular car audio system, but it can be used anywhere and it's a good value.

   Audio source (i.e. smartphone) 
                |
                v
 (((  Wireless Bluetooth Channel  )))
 |