Skip to content

Instantly share code, notes, and snippets.

View albsen's full-sized avatar

A. Sebastian Dietzel albsen

View GitHub Profile

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@albsen
albsen / Enhance.js
Last active August 29, 2015 14:21 — forked from sebmarkbage/Enhance.js
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
def login_using_email(request, email):
'''DONT EVER USE this method for normal purposes. This is only there, for debugging specific problems related to users'''
from django.contrib.auth import get_backends
from django.contrib.auth import login as django_login
from django.contrib.auth.models import User
@albsen
albsen / haproxy-ssl.cfg
Last active September 9, 2015 15:28 — forked from christiannelson/haproxy-ssl.cfg
HAProxy Configurations
# References:
# http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/
# http://blog.exceliance.fr/2012/09/10/how-to-get-ssl-with-haproxy-getting-rid-of-stunnel-stud-nginx-or-pound/
#
global
nbproc 2
maxconn 16384
defaults
@albsen
albsen / git_gbin_gbout.sh
Created October 3, 2011 03:27
gbin gbout bash functions I couldn't work without
#
# I didn't write those, ;) all props go to http://stackoverflow.com/users/110735/clint-modien
#
# The following bash functions show you the difference in commits between the branch you are on
# and another branch that you either want to commit too or merge from.
#
# USAGE:
# gbout branch_i_want_to_push_too [-p, --raw]
# gbin branch_i_want_to_pull_from [-p, --raw]
#
@albsen
albsen / redis_sessions.py
Created October 23, 2011 13:22 — forked from ericflo/redis_sessions.py
A Redis-based Django secure session store.
from django.core.exceptions import SuspiciousOperation
from django.utils.encoding import force_unicode
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
import redis
class SessionStore(SessionBase):
"""
A Redis-based session store.
"""
'analysis': {
'filter': {
'filter_edge_ngram': {
'side': 'back',
'max_gram': 20,
'min_gram': 2,
'type': 'edgeNGram',
},
'filter_ngram': {
'max_gram': 20,
@albsen
albsen / pbc_pool_transport.py
Created February 4, 2012 13:46 — forked from jdmaturen/pbc_pool_transport.py
Riak python client PBC connection pooling
import logging
log = logging.getLogger('socrates')
from Queue import Empty, Full, Queue
from riak.transports import RiakPbcTransport
from riak.transports.transport import RiakTransport
class PbcPoolTransport(RiakTransport):
@albsen
albsen / gist:2006165
Created March 9, 2012 11:33
custom analyzer question
curl -XDELETE 'http://localhost:9200/twitter/'
curl -XPUT 'http://localhost:9200/twitter/' -d '{
"settings" : {
"analysis":
{
"filter": {
"synonym_filter" : {
"type" : "synonym",
"synonyms": [
"i-phone 4, i phone 4, iphone 4 => iphone4"
@albsen
albsen / hack.sh
Created April 5, 2012 03:27 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#