Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@guillaumepiot
guillaumepiot / nginx.conf
Last active December 18, 2015 16:39
NGINX - Default site vhost
# Redirect from www to nothing if not accepting domain name only
server {
server_name www.<domain-name>;
rewrite ^(.*) http://<domain-name>$1 permanent;
}
server {
listen 80;
server_name <domain-name>;
error_log /var/www/<mysitename>/logs/error.log;
root /var/www/<mysitename>/;
@guillaumepiot
guillaumepiot / gist:5813538
Created June 19, 2013 11:12
uWSGI - Default site config
description "uWSGI server for mysite.com"
start on runlevel 2
stop on runlevel [016]
respawn
exec /usr/local/bin/uwsgi \
--chdir=/var/www/mysite.com \
--virtualenv=/var/www/mysite.com \
--pythonpath=/var/www/mysite.com/mysiteproject \
--socket 127.0.0.1:8888 \
--env DJANGO_SETTINGS_MODULE=mysiteproject.settings.production \
@guillaumepiot
guillaumepiot / gist:5821367
Last active December 18, 2015 17:49
PYPI - Example setup file
import os
from distutils.core import setup
from setuptools import find_packages
VERSION = __import__("cmsbase").VERSION
CLASSIFIERS = [
'Framework :: Django',
'Intended Audience :: Developers',
@guillaumepiot
guillaumepiot / gist:5877944
Created June 27, 2013 16:29
JAVASCRIPT - Placeholder fallback for IE
/* This code is licensed under Creative Commons Attribution 3.0 *
* You may share and remix the script so long as you attribute the *
* original author, Andrew January. *
* http://creativecommons.org/licenses/by/3.0/ */
$(document).ready(function() {
// Check to see if the browser already supports placeholder text (introduced in HTML5). If it does,
// then we don't need to do anything.
var i = document.createElement('input');
if ('placeholder' in i) {
@guillaumepiot
guillaumepiot / gist:6062629
Created July 23, 2013 14:08
DJANGO - HTML pagination with page numbers as links
<div class="pagination">
<ul>
<li {% if not partners.has_previous %}class="disabled"{% endif %}><a href="{% if partners.has_previous %}?page={{ partners.previous_page_number }}{% if category_filter %}&category={{category_filter.identifier}}{% endif %}{% endif %}">&laquo;</a></li>
{% for page in partners.paginator.page_range %}
<li {% if partners.number == page %}class="active"{% endif %}><a href="?page={{page}}{% if category_filter %}&category={{category_filter.identifier}}{% endif %}">{{page}}</a></li>
{% endfor %}
<li {% if not partners.has_next %}class="disabled"{% endif %}><a href="{% if partners.has_next %}?page={{ partners.next_page_number }}{% if category_filter %}&category={{category_filter.identifier}}{% endif %}{% endif %}">&raquo;</a></li>
@guillaumepiot
guillaumepiot / contact_form_tags.py
Last active December 20, 2015 03:19
DJANGO - Contact form template tag
import sys, httplib, urllib
from django.utils.translation import ugettext_lazy as _
from django import forms
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from django import template
register = template.Library()
@guillaumepiot
guillaumepiot / models.py
Created August 9, 2013 10:09
CMSBase - Testimonials model
from django.db import models
from django.utils.translation import ugettext_lazy as _
from cmsbase.models import Page
class Testimonial(models.Model):
content = models.TextField(max_length=500)
author = models.CharField(max_length=100, blank=True, null=True)
related_to = models.ManyToManyField(Page, blank=True, null=True)
publish = models.BooleanField()
@guillaumepiot
guillaumepiot / admin.py
Created August 9, 2013 10:16
CMSBase - Testimonials admin
from django.contrib import admin
from django import forms
from django.utils.translation import ugettext_lazy as _
from mptt.forms import TreeNodeMultipleChoiceField
from cmsbase.models import Page
from hollyfield.models import Testimonial
@guillaumepiot
guillaumepiot / gist:6267548
Created August 19, 2013 09:54
NGINX - Default index.html
<html>
<head>
<title>Welcome to our server</title>
<style>
body{
font-family: Helvetica, Arial, sans-serif;
}
.message{
width:330px;
padding:20px 40px;
@guillaumepiot
guillaumepiot / gist:6413288
Last active December 22, 2015 03:49
PYTHON - Generate a random password
import string
from random import choice
def generate_random_password(length=8, chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", digits=string.digits, specials=u'!@$%&?'):
#raise Exception(string.letters)
password = u''.join([choice(unicode(digits)) for i in range(3)])
password += u''.join([choice(unicode(chars.lower())) for i in range(3)])
password += u''.join([choice(unicode(chars.upper())) for i in range(3)])
password += u''.join([choice(specials) for i in range(1)])
return password