Skip to content

Instantly share code, notes, and snippets.

View epicserve's full-sized avatar

Brent O'Connor epicserve

View GitHub Profile
@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()
@jefftriplett
jefftriplett / python-django-postgres-ci.yml
Last active March 27, 2024 04:27
This is a good starting point for getting Python, Django, Postgres running as a service, pytest, black, and pip caching rolling with GitHub Actions.
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2024 18:30
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@epicserve
epicserve / ubuntu-server-django-guide.rst
Last active June 9, 2023 00:38
Ubuntu Server Setup Guide for Django Websites
@jefftriplett
jefftriplett / .dockerignore
Last active November 20, 2022 21:44
How I use Docker and Compose
.*
!.coveragerc
!.env
!.pylintrc
@apollo13
apollo13 / chromelogger.py
Last active May 12, 2022 01:09
Django logging to Firefox/Chrome devtools
"""
License: MIT - https://opensource.org/licenses/MIT
ChromeLogger is a protocol which allows sending logging messages to the Browser.
This module implements simple support for Django. It consists of two components:
* `LoggingMiddleware` which is responsible for sending all log messages
associated with the request to the browser.
* `ChromeLoggerHandler` a python logging handler which collects all messages.
@epicserve
epicserve / README.md
Last active May 8, 2021 06:20
Django SSL Setup Guide

Django SSL Setup Guide

Assumptions:

  • You use Django with [Django-Storages][storages] for saving your STATIC and MEDIA files to S3
  • You use Nginx to reverse proxy to Django
  • You want to protect any URLs that start with /admin or /subscribe
@epicserve
epicserve / db-stacktrace.html
Last active March 23, 2021 11:23
A python context manager and decorator for debugging and optimizing queries for Django management commands.
<!DOCTYPE html>
<html>
<head>
<title>DB Stacktrace</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="http://getbootstrap.com/docs-assets/css/pygments-manni.css" rel="stylesheet" media="screen">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
@epicserve
epicserve / checkpid_test.py
Created February 23, 2012 09:00
Pidcheck is a python decorator to check and see if a process with the same PID is still running.
#!/usr/bin/env python
from checkpid import pidcheck
from time import sleep
import logging
log = logging.getLogger("checkpid")
log.setLevel(logging.INFO)
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@epicserve
epicserve / README.rst
Last active December 22, 2015 10:09
List the top pages for a website using Google Analytics

README

List the top pages for a website using Google Analytics. This is a base example that you could build off of to create lists on your website like, "Top Articles this Week", etc.

Installation