View show-hide-fields.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
View checkAll.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
} | |
} |
View format_field_to_currency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
View test_image_upload.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View weeks_in_month.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; |
View weeks_in_month.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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` |
View mysite.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ |
NewerOlder