Skip to content

Instantly share code, notes, and snippets.

View guillaumepiot's full-sized avatar

Guillaume Piot guillaumepiot

View GitHub Profile
@guillaumepiot
guillaumepiot / weeks_in_month.js
Last active August 10, 2018 15:38
Weeks in month using Moment.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 / show-hide-fields.js
Created January 29, 2018 17:09
Show / hide fields based on field value
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";
@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 / parallax.js
Last active August 14, 2017 13:58
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 August 9, 2017 14:07
Javascript: Check all / Check none
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 08:28
Augment text input to format currency - Duplicate origin field, format to currency display
// 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 / gist:7805726
Created December 5, 2013 14:12
UNSLIDER JS - Thumbnails navigation control and trailer
// Extension for unslider.js, add a thumbnail trailer
// HOW TO USE
// Include this script in your page first, after unslider.js
// Then output the thumbnails as follows:
// <div class="slide-control">
// <a href="#prev" class="unslider-arrow prev"></a>
// <a href="#next" class="unslider-arrow next"></a>
// <div class="thumbnail_slider" style="width: 368px;">
@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 / gist:5585590
Last active December 5, 2016 09:25
jQuery - YouTube video play/stop on modal open/hide
$('.close').click(function(){
$('#video').modal('hide');
})
$('#open-video').click(function(){
$('#video').modal({'show':true}).on('hidden', function () {
toggleVideo('hide');
});
toggleVideo();
})
@guillaumepiot
guillaumepiot / admin.py
Last active November 16, 2016 19:39
DJANGO CookBook - Custom list filter
# Tested in Django 1.6
# Import default list filter
from django.contrib.admin import SimpleListFilter
# Create the filter
class InvoicePaidFilter(SimpleListFilter):
title = _('Paid')
parameter_name = 'paid'