Skip to content

Instantly share code, notes, and snippets.

View richarddewit's full-sized avatar
🗿
〰️〰️〰️〰️

Kerani richarddewit

🗿
〰️〰️〰️〰️
View GitHub Profile
// Adds 'unloading' class to `html` tag when navigating away from the page
//
// Make sure downloads open in another page with target="_blank"
// "beforeunload" is fired any time a link is clicked.
// If the link points to a file to download, the user won't be actually
// leaving the page, but beforeunload will still have fired.
(function () {
var unload = {};
unload.init = function () {
var $window = $(window);
var $header = $('.sticky-header');
var scrolling = false;
var previousTop = 0;
var currentTop = 0;
var scrollDelta = 10;
var scrollOffset = 150;
$header.once('init-autohide-header', function() {
$window.on('scroll', function(){
@richarddewit
richarddewit / slugify.php
Last active March 15, 2019 08:49
Slugify a string
<?php
/**
* Converts text from
* "thing + (Beep) $%^boop"
* to
* "thing-beep-boop"
*
* @author Richard de Wit
* @link https://gist.github.com/richarddewit/06692629a1503f931ff9d54002ffc14e
*
@richarddewit
richarddewit / throttled-resize-event.js
Last active April 18, 2018 08:10
Throttled resize/scroll events
var resizing = false;
$(window).on('resize', function() {
if (!resizing) {
resizing = true;
if (!window.requestAnimationFrame) {
setTimeout(onResizeFunction, 250);
} else {
requestAnimationFrame(onResizeFunction);
}
@richarddewit
richarddewit / nearest-whole-aspect-ratio.js
Last active April 1, 2019 10:40
Calculate nearest whole size on aspect ratio
// Paste this in your JavaScript console:
var width = 1440;
var height = 500;
var minWidth = 1000;
var maxWidth = 1500;
var ar = height / width;
for (var i = minWidth; i < maxWidth; i++) {
if (ar * i % 1 === 0) {
console.log(i + 'x' + (i * ar));
@richarddewit
richarddewit / _aspect-ratio.scss
Last active April 18, 2018 08:05
Aspect ratio
@mixin aspect-ratio($width, $height, $content-selector: '.content') {
position: relative;
&:before {
display: block;
content: '';
width: 100%;
padding-top: ($height / $width) * 100%;
}
.check-visible {
opacity: 0;
transform: translateY(30px);
transition-duration: .3s;
transition-timing-function: ease;
transition-property: opacity, transform;
}
.check-visible.is-visible {
opacity: 1;
var copyBtn = document.querySelector('.js-copy-button');
var originalContent = copyBtn.innerHTML;
copyBtn.addEventListener('click', function(event) {
var copyContents = document.querySelector('.js-copy-contents');
// Clear selection first
window.getSelection().removeAllRanges();
// Select the contents
var range = document.createRange();

How to trust a local development Root CA

(this guide focuses on Laravel's development server, Homestead)

For example; Homestead by default creates SSL certificates for your local websites, however you have to always click "Proceed/Trust/Make exception" or trust every website's certificate manually before being able to visit the site. By installing the Root CA (roughly: the certificate which is used to create the website certificates), you instantly trust all certificates that are derived from it.

Getting the Root CA

Normally on an Nginx webserver (e.g. on Homestead) the certificates are stored in the /etc/nginx/ssl folder. You see all the certificates that are generated for your local websites, including 3 crucial files:

  • ca.homestead.homestead.cnf
  • ca.homestead.homestead.crt
@richarddewit
richarddewit / randomIBANs.py
Last active January 15, 2019 10:13
Generate X random IBANs for Dutch bank ABN
#!/usr/bin/env python
import sys
import random
def main():
try:
count = int(sys.argv[1])
if count <= 0:
raise ValueError