Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@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 / 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 / array-deep-copy.coffee
Last active August 29, 2015 14:07
Javascript - Array deep copy with jQuery $.extend
# Deep copy the *items* list of objects
items_list = []
for item in items
items_list.push($.extend({}, item))
@guillaumepiot
guillaumepiot / gist:edea914f06558581737a
Created October 6, 2014 12:45
Python - Time difference formatting
from dateutil.relativedelta import relativedelta
# Calculate the relative timedelta
relative_delta = relativedelta(now_gmt, posted_time_gmt)
relative_time_format = {
'future' : 'in %s',
'past' : '%s ago',
's' : 'a few seconds',
'm' : 'a minute',
@guillaumepiot
guillaumepiot / gist:d8985bc8aa4f1d660174
Last active August 29, 2015 14:07
DJANGO - Minimum required formset
from django import forms
# how to use:
# Formset = inlineformset_factory(ParentModel, Model, ModelForm, \
# formset=MinimumRequiredFormSet, extra=1, can_delete=True)
# instance = Formset(request.POST or None, instance=obj, prefix="prefix_form", \
# minimum_forms=2, minimum_forms_message="At least two items are required.",)
class MinimumRequiredFormSet(forms.models.BaseInlineFormSet):
"""
@guillaumepiot
guillaumepiot / gist:a61094256997ddd8cfe6
Created October 20, 2014 14:03
JQUERY - Check if element is in view
# * Add jquery support for checking if an element is in view
$.fn.inView = () ->
$win = $(window)
viewport = {
top: $win.scrollTop()
left: $win.scrollLeft()
}
@guillaumepiot
guillaumepiot / gist:4e1028076b115ab93439
Created November 25, 2014 12:40
JAVASCRIPT - Count number format
# Format count numbers depending on how they are:
# 1-999: 999
# 1000+: 1K
# 1100+: 1.1K
# 10000+: 10K
# 100000+: 100K
# 1000000+: 1M
# 1100000+: 1.1M
window.format_count = (value)->
@guillaumepiot
guillaumepiot / gist:56191c0256f9ae9bf8e1
Created December 16, 2014 14:08
JAVASCRIPT - Set cursor positon in input and textarea
setSelectionRange: (input, selectionStart, selectionEnd)->
if input.setSelectionRange
input.focus()
input.setSelectionRange(selectionStart, selectionEnd)
else if input.createTextRange
range = input.createTextRange()
range.collapse(true)
range.moveEnd('character', selectionEnd)
@guillaumepiot
guillaumepiot / abbreviate.coffee
Last active August 29, 2015 14:16
COFFEESCRIPT - Abbreviate string
window.abbreviate = (str, max, suffix) ->
#
# Trim leading and trailing white space
#
str = str.replace /^\s+|\s+$/g, ""
#
# If the string is less than max, return it
#
@guillaumepiot
guillaumepiot / array-uniquify.coffee
Last active August 29, 2015 14:19
COFFEESCRIPT - Uniquify Array
usernames = ['@guillaumepiot','@lemans','@guillaumepiot']
isUnique = (value, index, array)->
array.indexOf(value) == index
console.log usernames.filter(isUnique)