Skip to content

Instantly share code, notes, and snippets.

View getdave's full-sized avatar
🏖️
AFK - I may not respond for a while...

Dave Smith getdave

🏖️
AFK - I may not respond for a while...
View GitHub Profile
@getdave
getdave / gist:a39175e3d33dc877f56c63e389f5f028
Last active June 5, 2017 15:48
Constructor Functions in JavaScript
const Person = function(name) {
this.name = name; // set instance property
}
// Define "shared" methods on prototype property
Person.prototype.greet = function() {
console.log(`Hello ${this.name}!`);
}
const dave = new Person('David');
@getdave
getdave / 301-redirect-checker.js
Last active June 5, 2017 15:50
Basic 301 redirect checker using NodeJS
var Crawler = require("crawler");
var map = require("lodash.map");
var chalk = require('chalk');
var errorStyle = chalk.bold.red;
var successStyle = chalk.bold.green;
var errors = [];
var c = new Crawler({
rateLimit: 200,
@getdave
getdave / fetch-image.js
Created September 15, 2017 10:00
Fetch an image using the Fetch API
var myImage = 'someimage.jpg';
fetch(myImage)
.then(response => response.blob()) //To extract the image body content from the response, we use the blob() method
.then(myBlob => {
// An objectURL is then created from the extracted Blob, which is then inserted into the img.
const objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});
@getdave
getdave / laravel-select-range-with-default
Last active June 27, 2018 02:16
Laravel selectRange with default
Form::macro('selectRangeWithDefault', function($name, $start, $end, $selected = null, $default = null, $attributes = [])
{
if ( is_null($default) ) {
return Form::selectRange($name, $start, $end, $selected, $attributes);
}
$range = array_combine($range = range($start, $end), $range);
$range = [null => $default] + $range;
@getdave
getdave / youtube-pomodoro-timer-src.js
Last active February 19, 2019 10:24
YouTube Pomodoro Timer - starts a timer and stops running <video> when completes. Your very own simple Pomodoro for YouTube (or <video> service)
(function() {
let _takingTooLongTimeout;
const alarmSound = new Audio("https://archive.org/download/alarm_162/alarm.ogg");
const startVideo = () => {
document.querySelector("video").play();
};
const stopVideo = () => {
document.querySelector("video").pause();
@getdave
getdave / gutenberg-possible-group-block-dimensions.txt
Created January 6, 2020 12:21
Gutenberg annotations for all possible combinations of dimension sizes for the Group Block
<!-- wp:group {"paddingSize":"default","marginSize":"default"} -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:heading -->
<h2>paddingDefault/marginDefault</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:group -->
@getdave
getdave / gitrebasebranch.sh
Created March 22, 2021 11:06 — forked from aduth/gitrebasebranch.sh
Git - Interactive rebase against own merge base
#!/bin/bash
git rebase -i $(git merge-base HEAD master)
@getdave
getdave / video-picture-in-picture-bookmarklet.js
Last active March 17, 2022 11:38
Picture In Picture API bookmarketlet - finds the first video element on the page and toggles between Picture In Picture mode - https://developers.google.com/web/updates/2018/10/watch-video-using-picture-in-picture
javascript:(function()%7B(async%20function()%20%7Bconst%20video%20%3D%20document.querySelector('video')%3Bif(!video)%20%7Balert(%22No%20video%20element%20found%20on%20page%22)%3B%7Dif%20(video%20!%3D%3D%20document.pictureInPictureElement)%20%7Bawait%20video.requestPictureInPicture()%3B%7D%20else%20%7Bawait%20document.exitPictureInPicture()%3B%7D%7D())%7D)()
@getdave
getdave / tamper-monkey-expand-github-pr-comments.js
Last active March 17, 2022 11:40
A Tampermonkey script to automatically expand all those pesky folded Github PR comments.
// ==UserScript==
// @name Recursively expand Github PR comments
// @namespace http://aheadcreative.co.uk/
// @version 1.0
// @description Automatically expands all those pesky folded Github PR comments.
// @author Dave Smith (@getdave). Please contact for questions and feedback
// @match https://github.com/*/*/pull/*
// @copyright 2020, Ahead Creative
// @updateURL https://gist.githubusercontent.com/getdave/9b9087055decf6f6cb7bfada08fcd3d1/raw/
// ==/UserScript==
@getdave
getdave / .htaccess
Created November 5, 2018 16:22
Redirect website including all sub dirs to equivalent on new domain with query string identifier
RewriteEngine on
RewriteCond %{HTTP_HOST} ^source-domain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.source-domain.com [NC]
RewriteRule ^(.*)$ https://target-domain.com/$1?source=sourcedomain [L,R=302,NC]