Skip to content

Instantly share code, notes, and snippets.

View chriskavanagh's full-sized avatar

Chris Kavanagh chriskavanagh

  • Home Office
  • Roanoke, VA - U.S.A.
View GitHub Profile
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
class EmailBackend(ModelBackend):
def authenticate(self, **credentials):
if 'username' in credentials:
return super(EmailBackend, self).authenticate(**credentials)
try:
@fohlin
fohlin / forms.py
Created January 8, 2011 18:50
A version of Django's UserCreationForm that uses email instead of username, with some nifty features. (Maybe not super robust yet, in terms of concurrency...)
import re
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class UniqueUserEmailField(forms.EmailField):
"""
An EmailField which only is valid if no User has that email.
"""
def validate(self, value):
/**
* SocketManager - Singleton to manage multi-channel socket 'routing', need a way to merge with socket.io so client sessions aren't stored twice in memory,
*
* Requires Socket.IO-node and Socket.IO client libraries.
*
* Usage:
* in your main app.js file (or whereever you create the server)
*
* var io = require('socket.io'),
* sm = require('socketmanager');
@gmarik
gmarik / curl.cmd
Created April 11, 2011 02:40 — forked from morhetz/curl.cmd
@rem Do not use "echo off" to not affect any child calls.
@setlocal
@rem Get the abolute path to the parent directory, which is assumed to be the
@rem Git installation root.
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%PATH%
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%
@brabadu
brabadu / gist:1259801
Created October 3, 2011 18:09
My ST2 config
{
"draw_white_space": "all",
"font": "monospace",
"font_size": 11,
"translate_tabs_to_spaces": true,
"vintage_start_in_command_mode": true,
"vintage_ctrl_keys": true,
"color_scheme": "Packages/Color Scheme - Default/Pastels on Dark.tmTheme"
}
@flavianmissi
flavianmissi / create_view_sample.py
Created October 9, 2011 20:41
Django CreateView sample
from django.views.generic import CreateView
from library.forms import BookForm
class CreateBook(CreateView):
template_name = 'create_form.html'
success_url = '/books/'
form_class = BookForm
@pylemon
pylemon / using_request_post_or_none.py
Created April 7, 2012 16:34
django: using(request.POST or None) hack in views | advanced forms usage
# simple form usage in view
def my_view(request, template_name='home.html'):
# sticks in a POST or renders an empty form
form = MyForm(request.POST or None)
if form.is_valid():
do_something()
return redirect('/')
return render_to_response(template_name, {'form':form})
# form with files
@schwuk
schwuk / forms.py
Created May 18, 2012 13:30
Including Email in the Django UserCreationForm
from django.forms import EmailField
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class UserCreationForm(UserCreationForm):
email = EmailField(label=_("Email address"), required=True,
@artofhuman
artofhuman / inclusion_tag.py
Created September 10, 2012 04:57
Django inclusion tag
# -*- coding: utf-8 -*-
from django import template
register = template.Library()
@register.inclusion_tag('template.html', takes_context = True)
def tag(context):
pass
@AvnerCohen
AvnerCohen / npm-cheat-sheet.md
Last active July 9, 2023 09:14
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

List of less common (however useful) NPM commands

Prepand ./bin to your $PATH

Make sure to export your local $PATH and prepand relative ./node_modules/.bin/: