Skip to content

Instantly share code, notes, and snippets.

@kennethreitz
kennethreitz / 0_urllib2.py
Created May 16, 2011 00:17
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@stantonk
stantonk / django_orm_query_stacktrace.py
Created May 4, 2013 00:49
Django logging config to dump a stack trace for every ORM query, so you can find the code that is producing queries that are icky.
DEBUG=True
LOG_FILE_SIZE=1024*1000
LOGGING = {
'version' : 1,
'disable_existing_loggers':True,
'formatters' : {
'simple' : {
'format' : '%(levelname)s %(name)s %(message)s'
},
@sloria
sloria / bobp-python.md
Last active July 21, 2024 04:44
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@gonz
gonz / gist:10044002
Created April 7, 2014 20:16
MultiSerializerViewSetMixin
class MultiSerializerViewSetMixin(object):
def get_serializer_class(self):
"""
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
class MyViewSet(ViewSet):
serializer_class = MyDefaultSerializer
serializer_action_classes = {
@umidjons
umidjons / youtube-dl-download-audio-only-on-best-quality.md
Last active March 9, 2024 07:54
Download Audio from YouTube with youtube-dl

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

@dasgoll
dasgoll / wildcard-ssl-cert-for-testing-nginx-conf.md
Last active July 11, 2022 20:02 — forked from sr75/wildcard-ssl-cert-for-testing-nginx-conf.md
create a self signed wildcard ssl cert for testing with nginx.conf example
openssl genrsa 2048 > edgenode1.key

openssl req -new -x509 -nodes -sha1 -days 3650 -key edgenode1.key -subj "/C=JO/CN=*.goll.com"> edgenode1-wildcard.cert

Common Name (eg, your name or your server's hostname) []:*.goll.com

@dolang
dolang / kivy_asyncio_example.py
Created May 28, 2018 15:46
Kivy with an asyncio EventLoop example
"""
Kivy asyncio example app.
Kivy needs to run on the main thread and its graphical instructions have to be
called from there. But it's still possible to run an asyncio EventLoop, it
just has to happen on its own, separate thread.
Requires Python 3.5+.
"""
@dnlvgl
dnlvgl / 90-kensington-expert-trackball-remap.hwdb
Created January 25, 2020 23:03
Remapping Kensington Expert Trackball Buttons with wayland
# Button remap for Kensington Expert Trackball
# both upper buttons (90003 + 90004) act as BTN_LEFT (272)
# both lower buttons (90001 + 90002) act as BTN_RIGHT (273)
# save this file under '/etc/udev/hwdb.d/90-kensington-expert-trackball-remap.hwdb'
# run `sudo systemd-hwdb update` and reboot
#
# source: https://askubuntu.com/questions/1145057/remapping-mouse-buttons-to-keyboard-keys
# /sys/class/input/event20/device/id/bustype:0003
# /sys/class/input/event20/device/id/product:1020
# /sys/class/input/event20/device/id/vendor:047d
@filviu
filviu / 90-kensington-expert-trackball-remap.hwdb
Last active May 15, 2024 06:10 — forked from dnlvgl/90-kensington-expert-trackball-remap.hwdb
Remapping Kensington Expert Trackball Buttons with wayland
# Button remap for Kensington Expert Wireless Trackball to:
# BACK MIDDLE
# O
# LEFT RIGHT
# save this file under '/etc/udev/hwdb.d/90-kensington-expert-trackball-remap.hwdb'
# run `sudo systemd-hwdb update` and reboot
#
# source: https://askubuntu.com/questions/1145057/remapping-mouse-buttons-to-keyboard-keys
# and: https://gist.github.com/dnlvgl/d16fd822bc90dcdaaae262a76fad884e
#