Skip to content

Instantly share code, notes, and snippets.

@gmr
gmr / timespent_ranking.py
Created January 5, 2012 22:09
Reads in a minecraft server log ranking users by time spent
"""
Minecraft Server Log Time Spent Ranking
"""
__author__ = 'Gavin M. Roy'
__email__ = 'gavinmroy@gmail.com'
__since__ = '2012-01-05'
import datetime
import operator
@lavoiesl
lavoiesl / process-mysqldump.c
Last active January 16, 2024 10:35
Add newlines before parenthesis for a SQL mysqldump
// gcc -O2 -Wall -pedantic process-mysqldump.c -o process-mysqldump
// Usage: cat dump.sql | process-mysqldump
// Or : process-mysqldump dump.sql
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define BUFFER 100000
@perrygeo
perrygeo / base64_padding.md
Last active October 25, 2023 16:20
Avoiding TypeError: Incorrect padding with Python's base64 encoding

Avoiding padding errors with Python's base64 encoding

>>> import base64
>>> data = '{"u": "test"}'
>>> code = base64.b64encode(data)
>>> code
'eyJ1IjogInRlc3QifQ=='
@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  )))
 |
@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
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
@tomysmile
tomysmile / mac-setup-redis.md
Last active May 23, 2024 03:17
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
@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
"""

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?

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.