Skip to content

Instantly share code, notes, and snippets.

@ryankask
ryankask / client.py
Created November 9, 2018 21:23
Async Starlette test client
import http
import io
import typing
from urllib.parse import unquote, urljoin, urlparse
import requests
class _HeaderDict(requests.packages.urllib3._collections.HTTPHeaderDict):
def get_all(self, key, default):
@voluntas
voluntas / sysctl.conf
Created October 14, 2017 13:07 — forked from techgaun/sysctl.conf
Sysctl configuration for high performance
### KERNEL TUNING ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
vm.dirty_background_ratio = 2
@tushortz
tushortz / UNICODE to ASCII python replace
Created April 6, 2016 22:14
Function to replace some annoying characters
def unicodetoascii(text):
TEXT = (text.
replace('\\xe2\\x80\\x99', "'").
replace('\\xc3\\xa9', 'e').
replace('\\xe2\\x80\\x90', '-').
replace('\\xe2\\x80\\x91', '-').
replace('\\xe2\\x80\\x92', '-').
replace('\\xe2\\x80\\x93', '-').
replace('\\xe2\\x80\\x94', '-').
@m3nu
m3nu / md2pdf.py
Last active November 21, 2016 18:34
md2pdf - Command line Markdown to PDF converter with support for CSS stylesheets and custom fonts
#!/usr/bin/env python
import os
import sys
from markdown2 import markdown
from xhtml2pdf import pisa
"""
## Inspired by
@dropwhile
dropwhile / py27.txt
Last active June 3, 2019 13:51
python-2.7.14 and python-3.7.0 -- for centos7 (rpm fpm recipes)
##### Configurable options
BUILD_VER=2.7.14
# strip symbols to slightly reduce runtime memory footprint
STRIP="yes"
# use altinstall to NOT symlink python and python2 to the python2.7 executable
ALTINSTALL="yes"
# build as user, requires configured sudo (for yum and fpm gem install).
# if not "yes", then build should be done as root
USE_SUDO="yes"
@josegonzalez
josegonzalez / access.lua
Created December 3, 2012 18:26
Simple lua file enabling oauth support for nginx via nginx-lua and access_by_lua.
- certain endpoints are always blocked
if nginx_uri == "/_access_token" or nginx_uri == "/_me" then
ngx.exit(403)
end
-- import requirements
local cjson = require "cjson"
-- setup some app-level vars
local app_id = "APP_ID"
@danielatdattrixdotcom
danielatdattrixdotcom / source_generators.py
Created October 3, 2012 23:20
Source Generator for Django app easy-thumbnails that uses Wand (ImageMagick)
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from PIL import Image as PILImage
from wand.image import Image
# Source Generator for the easy-thumbnails Django application
# https://github.com/SmileyChris/easy-thumbnails
@marktheunissen
marktheunissen / pedantically_commented_playbook.yml
Last active June 5, 2024 22:16 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.
@dcramer
dcramer / track_data.py
Created December 6, 2010 19:15
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')