Skip to content

Instantly share code, notes, and snippets.

View albsen's full-sized avatar

A. Sebastian Dietzel albsen

View GitHub Profile
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 / 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
#
@albsen
albsen / watch_log.py
Created October 17, 2012 06:04
python log file watcher
#!/usr/bin/env python
"""
Real time log files watcher supporting log rotation.
Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
License: MIT
"""
import os
@albsen
albsen / redisdns.py
Created November 12, 2012 10:05 — forked from wheresalice/redisdns.py
Python DNS server with Redis backend
# A naive dns server with a Redis backend
# Set keys in Redis you want to be authoritative for (set google.com. 127.0.0.1)
# Tip: Use Redis's ttl functions to have temporary names
# Currently only does A records, feel free to fix that
#
# Licensed under the PSF License
# Thanks to: http://code.activestate.com/recipes/491264-mini-fake-dns-server/
# Author: @Kaerast <alice@kaerast.info>
import socket
#!/usr/bin/python
import subprocess
# PyObjC-related imports
from AppKit import NSApplication, NSSystemDefined
from PyObjCTools import AppHelper
KEY_UP = 11