Skip to content

Instantly share code, notes, and snippets.

Guillaume Piot guillaumepiot

Block or report user

Report or block guillaumepiot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@guillaumepiot
guillaumepiot / show-hide-fields.js
Created Jan 29, 2018
Show / hide fields based on field value
View show-hide-fields.js
var required_financial_fields = {{LOAN_REQUIRED_FINANCIAL_FIELDS|safe}};
var fields = []
for(var key in required_financial_fields) {
fields = fields.concat(required_financial_fields[key])
}
function hideAllFields() {
for(var i = 0; i < fields.length; i++) {
document.querySelector('[name='+fields[i]+']').parentNode.parentNode.style.display = "none";
View parallax.js
// For a given HTML snippet with the class "parallax"
//
// <div class="parallax" style="height: 400px; overflow: hidden;">
// <div style="background-image:url('http://via.placeholder.com/1600x780');"></div>
// </div>
(function(){
var speedRatio = 4
var minYOffset = -200
@guillaumepiot
guillaumepiot / checkAll.js
Created Aug 9, 2017
Javascript: Check all / Check none
View checkAll.js
function toggleCheckboxes(){
var checkboxes = document.querySelectorAll("[name=accommodation]")
var allChecked = Array.prototype.every.call(checkboxes, function(item){ return item.checked })
if (allChecked) {
checkboxes.forEach(function(item){ item.checked = false })
} else {
checkboxes.forEach(function(item){ item.checked = true })
}
}
@guillaumepiot
guillaumepiot / format_field_to_currency.js
Last active May 12, 2017
Augment text input to format currency - Duplicate origin field, format to currency display
View format_field_to_currency.js
// Author: Guillaume Piot, Alex Russell
// Copyright 2017
// MIT License
var currency_fields = document.getElementsByClassName('form__text--currency')
function formatCurrencyField(elm){
// Duplicate the element to create:
// - a hidden version with the integer value tp submitted to the form
// - a new text input to display the formatted value
@guillaumepiot
guillaumepiot / test_image_upload.py
Last active May 20, 2019
Django Rest Framework - Image/File upload test
View test_image_upload.py
import os
import io
from PIL import Image
from django.core.urlresolvers import reverse
from django.conf import settings
from rest_framework import status
from rest_framework.test import APITestCase
View contenttools-background-image.coffee
# Example integration of a background-image uploader
# Author: Guillaume Piot
# Email: guillaume@cotidia.com
# Company: Cotidia Ltd
# Licence: MIT
#
# The div holder is absolute positioned within the parent div
#
# <div class="[ article__image ] [ article-image ] [ editable ] [ parallax ]" data-name="article_image">
# <div
@guillaumepiot
guillaumepiot / weeks_in_month.js
Last active Aug 10, 2018
Weeks in month using Moment.js
View weeks_in_month.js
var get_calendar;
var calendar, endDay, firstDay, firstWeekDay, headerRow, i, j, lastWeekDay, len, len1, month, monthRange, row, startDate, week, weekRange, weeks, year,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
get_calendar = function(year, month) {
startDate = moment([year, month]);
firstDay = moment(startDate).startOf('month');
endDay = moment(startDate).endOf('month');
monthRange = moment.range(firstDay, endDay);
weeks = [];
@guillaumepiot
guillaumepiot / weeks_in_month.coffee
Last active Jul 10, 2018
Get all the weeks in a given month and year using Moment.js
View weeks_in_month.coffee
# year and month are variables
year = 2015
month = 7 # August (0 indexed)
startDate = moment([year, month])
# Get the first and last day of the month
firstDay = moment(startDate).startOf('month')
endDay = moment(startDate).endOf('month')
# Create a range for the month we can iterate through
View secret-key-gen.py
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@guillaumepiot
guillaumepiot / mysite.conf
Last active Dec 10, 2015
WSGI - Upstart file for Django 1.9
View mysite.conf
description "uWSGI server for <domain-name>"
start on runlevel 2
stop on runlevel [016]
respawn
exec /<path-to-myvenv>/bin/uwsgi --chdir=<code_dir> \
--module=<app-name>.wsgi:application \
--env DJANGO_SETTINGS_MODULE=<app-name>.settings.production \
--master --pidfile=/tmp/<mysitename>-master.pid \
--socket=127.0.0.1:<wsgi_port> \
--processes=3 \
You can’t perform that action at this time.