Skip to content

Instantly share code, notes, and snippets.

@bsolomon1124
bsolomon1124 / ratemgr.py
Last active August 23, 2018 01:03
Rate limit manager via Redis/Python
#!/usr/bin/env python3
# NOTE: No Python 2 compat. Redis
"""Mixin class for managing rate limiting of API keys via Redis."""
__all__ = ['RateLimitManagerMixin']
import datetime
import redis
@bsolomon1124
bsolomon1124 / counter.go
Last active September 3, 2018 23:29
Mimic Python's collection.Counter in Go
package counter
import "container/heap"
// Implement the maxheap used in ic.MostCommon()
// KeyValueHeap is a nested slice that implements the heap interface
// It roughly resembles an ordered mapping where each element is a
// length-2 slice with keys as the 0th element and values as the 1st
// See https://golang.org/pkg/container/heap/ IntHeap example
package variadic
// Platform-dependent largest and smallest values that int may take on
const (
LargestInt = int(^uint(0) >> 1)
SmallestInt = -1 * int(^uint(0) >> 1) - 1
)
func Min(a ...int) int {
min := LargestInt
@bsolomon1124
bsolomon1124 / counter.go
Created September 4, 2018 02:41
Mimic Python's collection.Counter in Go - attempt 2
package counter
import (
"fmt"
"sort"
)
type kv struct {
Key int
Value int
@bsolomon1124
bsolomon1124 / ratemgr.py
Created September 25, 2018 14:13
Exponential backoff
def backoff(
url: str,
waitfor: Optional[datetime.timedelta] = None,
waituntil: Optional[datetime.datetime] = None,
base: int = 2,
method: str = 'GET',
bad_status_codes: Optional[Sequence] = None,
session: Optional[requests.Session] = None,
begin_timeout: int = 10,
_now=datetime.datetime.now,
import asyncio
async def foo():
await asyncio.sleep(1)
return 2
async def bar():
f1 = await foo()
f2 = await foo()
return f1, f2
This file has been truncated, but you can view the full file.
https://www.kitchenertoday.com/world-news/trumps-ag-nominee-defends-memo-criticizing-mueller-probe-1194852
http://www.bomboradyo.com/coa-resident-auditor-nasita-sa-kamara-dahil-sa-flood-control-scam/
https://www.derbytelegraph.co.uk/news/local-news/live-a6-flood-traffic-delays-2430621
http://showbizplus.com/index.php/blog/49735/home-insurance-five-ways-to-less/
https://autoblog.com.ar/2019/01/15/proyecto-cyclone-ya-es-oficial-las-ford-ranger-y-vw-amarok-compartiran-plataforma-a-partir-de-2022/
https://www.ft.com/content/7990545e-18c7-11e9-b93e-f4351a53f1c3?FTCamp=engage/CAPI/webapp/Channel_Moreover//B2B
http://blog.geogarage.com/2019/01/ocean-warming-is-accelerating-faster.html
https://liberal.com.br/cidades/nova-odessa/oab-de-nova-odessa-pede-intervencao-em-cobranca-da-taxa-de-lixo-943237/
https://theopenview.in/2019/01/15/pongal-celebrated-in-tn-with-traditional-fervour/
https://www.huffingtonpost.co.uk/entry/canada-issues-high-caution-travel-warning-for-china-amid-citizens-death-sentence_uk_5c3d9bd2e4b0922
print(0xc0ffee)
@bsolomon1124
bsolomon1124 / quickup.sh
Created March 7, 2019 00:02
Redis quick setup on Mac OSX + Linux
#!/usr/bin/env sh
#
# Miniature version of redis/utils/install_server.sh
# compatible across OS X + Linux
if [ "$(id -u)" -ne 0 ]; then
echo "Must run as root"
exit 1
fi