Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
mjumbewu / gunicorn.conf.py
Created June 9, 2016 21:13
Patching psycopg2 for nonblocking use with gunicorn's gevent workers using psycogreen
from psycogreen.gevent import patch_psycopg
def post_fork(server, worker):
patch_psycopg()
@mrkn
mrkn / rgb2lab.py
Last active March 19, 2018 20:03
color space conversion from RGB to CIELAB in PIL/Pillow (Japanese article) ref: http://qiita.com/mrkn/items/670e1622d41d2dcd26b4
from PIL import Image, ImageCms
im = Image.open(image_path)
if im.mode != "RGB":
im = im.convert("RGB")
srgb_profile = ImageCms.createProfile("sRGB")
lab_profile = ImageCms.createProfile("LAB")
rgb2lab_transform = ImageCms.buildTransformFromOpenProfiles(srgb_profile, lab_profile, "RGB", "LAB")
@shreddd
shreddd / redirect.py
Created September 30, 2015 21:14
Simple Redirect Server in python to redirect requests to a specified URL
#!/usr/bin/env python
"""
Simple HTTP URL redirector
Shreyas Cholia 10/01/2015
usage: redirect.py [-h] [--port PORT] [--ip IP] redirect_url
HTTP redirect server
positional arguments:
@ashishtajane
ashishtajane / django urlpattern list .py
Last active May 13, 2024 02:08
Get all URL patterns in django
# Open django shell and do following.
import urls
def show_urls(urllist, depth=0):
for entry in urllist:
print(" " * depth, entry.regex.pattern)
if hasattr(entry, 'url_patterns'):
show_urls(entry.url_patterns, depth + 1)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, division
import os
import sys
# based on https://gist.github.com/magopian/7543724
#
# refactored for manual control over permissions created.
projectname = input("Enter project name (for settings import): ")
@mjumbewu
mjumbewu / basic_auth.py
Last active March 20, 2019 15:10
WSGI middleware
from __future__ import unicode_literals
import base64
import binascii
import os
import re
import logging
log = logging.getLogger(__name__)
@plentz
plentz / nginx.conf
Last active November 14, 2024 08:35
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@gaspanik
gaspanik / capture.js
Last active November 6, 2018 06:19
Take screenshot at single viewport size using CasperJS
var screenshotUrl = 'http://example.com/'
var casper = require("casper").create({
viewportSize: {
width: 1024,
height: 768
}
});
if (casper.cli.args.length < 1) {
anonymous
anonymous / pysubl
Created December 5, 2012 21:44
Open any python module in sublime, ie: pysubl django.contrib.auth
#!/usr/bin/env python
import sys, os, os.path
sys.path.append('.')
# Weird hack, __import__("a.b.c") returns module a unless fromlist is non-empty, then it returns module c
filename = __import__(sys.argv[1], fromlist=["whatever"]).__file__
os.system('subl ' + os.path.dirname(filename))
@nhoizey
nhoizey / screenshots.js
Created November 12, 2012 17:07
Take screenshots at different viewport sizes using CasperJS
/*
* Takes provided URL passed as argument and make screenshots of this page with several viewport sizes.
* These viewport sizes are arbitrary, taken from iPhone & iPad specs, modify the array as needed
*
* Usage:
* $ casperjs screenshots.js http://example.com
*/
var casper = require("casper").create();