Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@guillaumepiot
guillaumepiot / gist:8860701
Created February 7, 2014 10:58
Django Weekend - Good practices

#Good practices for project management in Django

#Setting up the environment

Each Django project should be encapsulated in its own virtual environment, allowing us to manage the requirements and dependencies independently.

If you don't have Virtualenv installed, please visit this page and download the virtualenv package. For a simple installation:

@guillaumepiot
guillaumepiot / gist:9760507
Created March 25, 2014 12:07
PHP - Dump MySQL
<?php
$DBUSER="user";
$DBPASSWD="password";
$DATABASE="user_db";
$filename = "backup-" . date("d-m-Y") . ".sql.gz";
$mime = "application/x-gzip";
header( "Content-Type: " . $mime );
@guillaumepiot
guillaumepiot / gist:2884ad0361ffb142fcc5
Last active August 29, 2015 14:00
Protractor selection helper
// Select an object attribute
obj.getAttribute('class').then(function(attr){
console.log(attr);
})
// Get an element inner html
obj.getInnerHtml().then(function(html){
console.log(html);
})
@guillaumepiot
guillaumepiot / gist:71624556ef785c262899
Created May 15, 2014 14:55
REGEX - Catch most html tags
Regex to catch some html tags (does not catch it all though, but does clean up most of it)
<[a-z0-9\:\;\"\{\}\=\/\s\#\-\.\%\_]+>
@guillaumepiot
guillaumepiot / gist:fed87de0433bd4ac4d46
Created May 27, 2014 15:14
OS Mavericks - general pip install error
Mavericks install error:
clang: error: unknown argument: '-mno-fused-madd'
We must tell the OS to ignore the error.
Just type the following:
$ export CFLAGS=-Qunused-arguments
$ export CPPFLAGS=-Qunused-arguments
@guillaumepiot
guillaumepiot / gist:b8f68db3e889938c6816
Last active August 29, 2015 14:02
POLYFILL - Background size cover for IE
// Add the following in a CSS class using background-size:cover;
// IE polyfill for background size
// -ms-behavior: url('/static/css/backgroundsize.min.htc');
<!-- background-size-polyfill v0.2.0 | (c) 2012-2013 Louis-Rémi Babé | MIT License -->
<PUBLIC:COMPONENT lightWeight="true">
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="o.init()" />
<PUBLIC:ATTACH EVENT="ondocumentready" ONEVENT="o.init()" />
<PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="o.handlePropertychange()" />
<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="o.restore()" />
@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;
@guillaumepiot
guillaumepiot / .gitignore
Created July 17, 2014 14:11
GIT default .gitignore for Python modules
*.pyc
.DS_Store
build/
dist/
*.egg-info/
@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: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