Skip to content

Instantly share code, notes, and snippets.

# -*- 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): ")
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))
@jatorre
jatorre / readshp.py
Created April 24, 2011 19:53
A python script to detect encoding and SRID of a shapefile GUESSING its best
from chardet.universaldetector import UniversalDetector
import os.path
import sys
import dbfUtils
import sys
from osgeo import osr
from urllib import urlencode
from urllib2 import urlopen
import json
@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")
@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()
@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) {
@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__)
@dsamarin
dsamarin / Complex.js
Created October 3, 2011 03:11
Complex numbers in JavaScript
var Complex = function(real, imag) {
if (!(this instanceof Complex)) {
return new Complex (real, imag);
}
if (typeof real === "string" && imag == null) {
return Complex.parse (real);
}
this.real = Number(real) || 0;
@nimbupani
nimbupani / index.html
Created December 2, 2011 05:00
Showing latest post on home page with Jekyll
---
layout: default
---
<div class="blog-index">
{% assign post = site.posts.first %}
{% assign content = post.content %}
{% include post_detail.html %}
</div>
@io41
io41 / paginated_collection.js
Created February 22, 2011 10:10 — forked from zerowidth/paginated_collection.js
Pagination with Backbone.js
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
typeof(options) != 'undefined' || (options = {});
this.page = 1;
typeof(this.perPage) != 'undefined' || (this.perPage = 10);
},
fetch: function(options) {