Skip to content

Instantly share code, notes, and snippets.

View donbrae's full-sized avatar

donbrae

View GitHub Profile
# HTTPS redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
# END HTTPS
# Force non-www SSL
# https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
@donbrae
donbrae / get-cookies.js
Created August 18, 2020 11:54
Get list of currently set cookies
(function () {
let cookies = [];
document.cookie.split(';').forEach(cookie => {
cookies.push(cookie.split('=')[0]);
});
console.log(cookies.join(','));
})();
@donbrae
donbrae / MY_MODULE.js
Last active August 18, 2020 12:59
Basic JavaScript module pattern
/**
* @name MY_MODULE
* @author Jamie Smith
* @description Basic JavaScript module template with config and state objects, and private and public functions
*/
const MY_MODULE = (function () {
"use strict";
@donbrae
donbrae / getQueryString.js
Last active August 18, 2020 13:34
Gets query string and returns as an object of key-value pairs
/**
* Gets query string and returns as an object of key-value pairs
* @returns {Object or null}
*/
function getQueryString() {
let q = document.location.href.split('?')[1];
let o = {};
if (q && q.length) {
@donbrae
donbrae / Bash cheat sheet.md
Last active June 1, 2022 06:25
A bash cheat sheet

Changing directories (cd)

cd /var/www/my_website (go to /var/www/my_website directory)

cd .. (go up a directory)

cd / (go to root directory)

cd ~ (go to home directory)

@donbrae
donbrae / pdf-page-numbers
Created August 5, 2019 10:51
Bash script to add page numbers to PDFs. Liftit frae http://forums.debian.net/viewtopic.php?t=30598#p174267.
#!/bin/sh
# we'll hide the work in a temporary directory
mkdir tmp_num
cp numbers.pdf tmp_num/.
cp newbook.pdf tmp_num/.
cd tmp_num/
# burst newbook into its component pages and extract total pages
pdftk newbook.pdf burst output book_%04d.pdf
@donbrae
donbrae / Nineties Man
Last active June 30, 2022 13:58
Nineties Man chord chart
Nineties Man
4/4
___ Intro
D7sus4 | Bbmaj7 | D7sus4 | Bbmaj7 :||
___ Verse
@donbrae
donbrae / highlight-string.html
Last active July 5, 2022 11:47
Some JavaScript for finding and highlighting a string on the page.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Highlight element</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Find and highlight string" />
<style type="text/css">
html {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Open Sans, Helvetica Neue;
@donbrae
donbrae / xhr-request.js
Last active July 5, 2022 11:54
Vanilla JS Ajax/XHR request
function XHRRequest(url, type = 'text/plain') {
const request = new XMLHttpRequest();
request.open('GET', `${url}?${new Date().getTime()}`, true);
request.setRequestHeader('Content-type', type);
request.onload = function () {
if (this.status >= 200 && this.status < 400) { // Success
console.log('Success', this.response);
} else
@donbrae
donbrae / Apple Music desktop keyboard shortcuts.md
Last active July 6, 2022 18:58
Basic but useful keyboard shortcuts for the Apple Music macOS desktop client, with the ex-Spotify user in mind.
  • Command + L: go to the current song
    • I use this when I’m listening to something and searching for something else, and then want to get back to the currently playing song in the context in which I started playing it (e.g. from an album or playlist)
  • Command + F: search
    • Similar to Command + L or Command + K in Spotify
  • Command + Option + F: find in playlist
    • Similar to Spotify’s Filter function
  • Command + [: go back (à la Safari)
  • Doesn’t work universally, or at least not like it does in Safari or Spotify