Skip to content

Instantly share code, notes, and snippets.

@bencharb
bencharb / jsonmap2jsonobject.js
Last active September 29, 2021 07:04
JSON map to JSON object
/*
Credit: Tomalak on Stack Overflow
http://stackoverflow.com/a/11153997
Why?
Easier to pull data when the mapping is unknown or arbitrary.
Example:
the function nestedMapping() turns your data structure:
@copitux
copitux / Doc.rst
Created September 24, 2012 22:20
Django, Django forms and Django rest framework: Payload validation

Django request flow

-------------------------------                         ------------------ Django --------------------
| Browser: GET /udo/contact/2 |    === wsgi/fcgi ===>   | 1. Asks OS for DJANGO_SETTINGS_MODULE      |
-------------------------------                         | 2. Build Request (from wsgi/fcgi callback) |
                                                        | 3. Get settings.ROOT_URLCONF module        |
                                                        | 4. Resolve URL/view from request.path      | # url(r'^udo/contact/(?P<id>\w+)', view, name='url-identifier')
                                                        | 5. Apply request middlewares               | # settings.MIDDLEWARE_CLASSES
@ibarovic
ibarovic / forms.py
Created July 11, 2012 20:00
django crispy forms and django inline forms example (inlineformset_factory)
class AuthorForm(ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Field('name'),
)
super(AuthorForm, self).__init__(*args, **kwargs)
class Meta:
model = Author
@hughsaunders
hughsaunders / LDAPRemoteUserBackend.py
Created June 23, 2011 15:12
Django RemoteUserBackend for REMOTE_USER authentication and LDAP authorisation
# LDAP Remote User Backend for Django 1.3
# Hugh Saunders - [email protected]
# Written for the Surgical Materials Testing Laboratory - http://smtl.co.uk
# 2011
from django.contrib.auth.backends import RemoteUserBackend
import settings as s
import ldap
class LDAPRemoteUserBackend(RemoteUserBackend):
@chandlerprall
chandlerprall / threaded_download.py
Created June 9, 2011 17:41
Small Python multi-threaded file downloader
import urllib2
import threading
from Queue import Queue
import sys, os, re
class ThreadedDownload(object):
REGEX = {
'hostname_strip':re.compile('.*\..*?/', re.I)
}
@samuraisam
samuraisam / deep_eq.py
Last active October 10, 2024 15:52
Deep Equality Test for Nested Python Structures
#Copyright (c) 2010-2013 Samuel Sutch [[email protected]]
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in