Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@guillaumepiot
guillaumepiot / gist:89c61981ffd9848ffda7
Last active August 29, 2015 14:06
DJANGO - Decorate "include" in urlpatterns
from django.core.urlresolvers import RegexURLResolver
from django.contrib.auth.decorators import login_required
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
@guillaumepiot
guillaumepiot / gist:a436da4e51baf675aef4
Created September 16, 2014 09:58
NGINX - Set WSGI timeout
location / {
include uwsgi_params;
uwsgi_param SCRIPT_NAME "";
uwsgi_pass 127.0.0.1:8003;
uwsgi_read_timeout 300;
}
@guillaumepiot
guillaumepiot / thumbnail-carousel.bxslider.html
Last active July 11, 2019 18:43
bxSlider with thumbnails carousel
@guillaumepiot
guillaumepiot / gist:c0b7f9b69332204f7338
Created September 5, 2014 10:24
DJANGO - Inline formset factory - Minimum form number required
# Thanks to Torchbox
# http://techblog.torchbox.com/post/54428118919/minimum-number-of-forms-in-a-django-formset
from django import forms
class MinimumRequiredFormSet(forms.models.BaseInlineFormSet):
"""
Inline formset that enforces a minimum number of non-deleted forms
that are not empty
@guillaumepiot
guillaumepiot / gist:d325cd7dc65d886b6659
Created August 1, 2014 10:12
Fisher–Yates - Array shuffling
function shuffle(array) {
var n = array.length, t, i;
while (n) {
i = Math.random() * n-- | 0; // 0 ≤ i < n
t = array[n];
array[n] = array[i];
array[i] = t;
}
return array;
}
@guillaumepiot
guillaumepiot / gist:e015a3dea6f8ffd661be
Created July 23, 2014 09:07
NGINX - Rewrite query string to url path
location ~ /more_details.php {
if ($args ~* "^profileID=(\d+)") {
set $mid $1;
set $args '';
rewrite ^.*$ /view/$mid permanent;
}
}
@guillaumepiot
guillaumepiot / .gitignore
Created July 17, 2014 14:11
GIT default .gitignore for Python modules
*.pyc
.DS_Store
build/
dist/
*.egg-info/
@guillaumepiot
guillaumepiot / _messages.html
Created July 17, 2014 10:27
Django messages HTML for bootstrap
{% if messages %}
<div class="container messages">
<div class="row">
<div class="col-md-12">
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">
<a class="close" data-dismiss="alert" href="#">×</a>
{{ message }}
</div>
{% endfor %}
@guillaumepiot
guillaumepiot / custom_modelchoicefield.py
Last active July 5, 2023 14:01
Django Form - Custom ModelChoiceField label
from django import forms
from django.utils.safestring import mark_safe
class CustomModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return mark_safe("My Object custom label <strong>%i</strong>" % obj.id)
class MyForm(forms.ModelForm):
my_field = CustomModelChoiceField(label=_('The form label'), queryset=MyModel.objects.filter(), widget=forms.RadioSelect, empty_label=None)
@guillaumepiot
guillaumepiot / gist:a098623d5be450569499
Created June 16, 2014 15:50
Raphael animated pie/doughnut chart
<script src="/media/js/raphael-min.js"></script>
<script type="text/javascript">
var paper;
var arc;
var colorArr = ["#d0ad6d","#E78B6D","#DD64B3","#7BDD69","#E7E06D"];
var pieData = [112, 50, 67];
var sectorAngleArr = [];
var total = 0;
var startAngle = -90;
var endAngle = -90;