Skip to content

Instantly share code, notes, and snippets.

View etianen's full-sized avatar

Dave Hall etianen

View GitHub Profile
""" ldap_auth.py (custom methods for django_python3_ldap)
Create three additional groups in LDAP directory (e.g w/ prefix "django_"):
* cn=django_my_django_project,ou=groups,dc=example.com,dc=com
* cn=django_my_django_project_staff,ou=groups,dc=example.com,dc=com
* cn=django_my_django_project_superuser,ou=groups,dc=example.com,dc=com
1) "django_my_django_project"
Add all users to this group that should be able to use the Django APP.
The users will then be able to authenticate and their attributes will be synched.
@etianen
etianen / gist:8595035
Last active January 4, 2016 08:19
Optimizing LESS stylesheets with RequireJS
/**
* LESS stylesheet loader.
*
* Load a LESS stylesheet using style!main.less . This will load
* a stylesheet on the path ../css/main.less, compile it to CSS,
* and inject it in the page.
*
* During the optimization step with r.js, the stylesheet will be
* inlined with the javascript file.
*
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave Hall 20/01/2014
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iQEcBAEBAgAGBQJS3YYEAAoJEIayWs+cr8YFXD8H/j/K0yjIW/gOalmT5sW8twk6
AfL9cJ4/PjM5wDnB3s879Wr4+OjHfIocwGt5czd8c2xqdo3t4EvySnBKRivDafx4
bNhqiXBGApGiA0fCgxGBSSBdAo4SDtTO7qMmDb0TiGXjg33j83TX1AiY/M0IyobO
def search(request):
search_form = SearchForm(request.GET)
if search_form.is_valid():
data = form.cleaned_data
search_results = watson.filter(Issue, data["q"]).filter(
date__gte = data["start_date"],
date__lte = data["end_date"],
item__name = data["item_name"],
)
@etianen
etianen / gist:7526781
Created November 18, 2013 12:09
Pluralizing a label in CSS!
.spinner-count {
&:after {
content: "servings";
}
}
&.spinner-count-1 {
.spinner-count {
&:after {
content: "serving";
}
@etianen
etianen / style.js
Last active December 25, 2015 16:29
A LESS stylesheet loader and compiler for RequireJS, including NodeJS optimization.
/**
* LESS stylesheet loader.
*/
define([
"module",
"text"
], function(
module,
text
@etianen
etianen / unicode_stream_condom.py
Last active December 24, 2015 16:19
How to fix a broken XML source file that contains invalid XML unicode characters.
import tempfile, re, codecs
from contextlib import closing
from functools import partial
RE_UNICODE_CONDOM = re.compile(u"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD]")
MEMORY_BUFFER_SIZE = 1024 * 1024 # 1M
CHUNK_SIZE = 1024 * 512 # 0.5M
return not any (
frozenset(permissions_grant).difference(chain.from_iterable(
parent_permissions_grant
for parent_model_grant, parent_permissions_grant
in parent_scope
if all(
parent_model_grant_part == model_grant_part
for model_grant_part, parent_model_grant_part
in izip_longest(
model_grant,
@etianen
etianen / public-key.txt
Last active December 19, 2015 18:38
My PGP public key.
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.19 (Darwin)
mQENBE228RIBCACuc/n1SvMxe7RQWrgOK4Hi1Pn8K9KcZNy0j+kmk319/W8GiqAC
qOKMcVIl+KA4zBy7KwCUkkEFUEJn4OwQky9NIyAJw7djyWkkMAAGSqvRWrbt+TF4
AOje8EHJTF5r+4tytLRAHl7sRAHkBWdvPJKp5I9KLjbDu55q65dj8Gkjd0lKxk5n
b5IDTn5p3tx82j+DokdJ8YnmGq4fXtG6oUmi+EXlKV24Jo3+mlrNo3MKBMMQekuO
WJLhldnJiapnkaadDKqpiJ+7thPoemou4qizqxHaSZCmThegNzA+kP9sseM1YDk5
kcy2xvxQu77BMpZ3s2zc2vviDY4S9/WMIRWnABEBAAG0HERhdmUgSGFsbCA8ZGF2
ZUBldGlhbmVuLmNvbT6JATsEEwECACUCGy8GCwkIBwMCBhUIAgkKCwQWAgMBAh4B
import random
win_on_switch = 0
win_on_stay = 0
for _ in xrange(100000):
prize_box = random.randint(0, 2)
print "Prize is in box", prize_box
initial_choice_box = random.randint(0, 2)
print "You choose box", initial_choice_box