start new:
tmux
start new with session name:
tmux new -s myname
import os | |
import string | |
def random_password(length=10): | |
chars = string.ascii_uppercase + string.digits + string.ascii_lowercase | |
password = '' | |
for i in range(length): | |
password += chars[ord(os.urandom(1)) % len(chars)] | |
return password |
from django.db.models.fields.related import ManyToManyField | |
def to_dict(instance): | |
opts = instance._meta | |
data = {} | |
for f in opts.concrete_fields + opts.many_to_many: | |
if isinstance(f, ManyToManyField): | |
if instance.pk is None: | |
data[f.name] = [] | |
else: |
from django.views.generic.base import View | |
from django.views.decorators.csrf import csrf_exempt | |
from django.utils.decorators import method_decorator | |
class ExampleView(View): | |
@method_decorator(csrf_exempt) | |
def dispatch(self, request, *args, **kwargs): | |
return super(ExampleView, self).dispatch(request, *args, **kwargs) |
from django.conf.urls.static import static | |
from django.conf import settings | |
if settings.DEBUG: | |
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
class CORSResource(object): | |
""" | |
Adds CORS headers to resources that subclass this. | |
""" | |
def create_response(self, *args, **kwargs): | |
response = super(CORSResource, self).create_response(*args, **kwargs) | |
response['Access-Control-Allow-Origin'] = '*' | |
response['Access-Control-Allow-Headers'] = 'Content-Type' | |
return response |
// | |
// Regular Expression for URL validation | |
// | |
// Author: Diego Perini | |
// Updated: 2010/12/05 | |
// License: MIT | |
// | |
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it) | |
// | |
// Permission is hereby granted, free of charge, to any person |
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () { | |
var Storage = function (type) { | |
function createCookie(name, value, days) { | |
var date, expires; | |
if (days) { | |
date = new Date(); | |
date.setTime(date.getTime()+(days*24*60*60*1000)); | |
expires = "; expires="+date.toGMTString(); |
class FilterMixin(object): | |
""" | |
View mixin which provides filtering for ListView. | |
""" | |
filter_url_kwarg = 'filter' | |
default_filter_param = None | |
def get_default_filter_param(self): | |
if self.default_filter_param is None: | |
raise ImproperlyConfigured( |