Skip to content

Instantly share code, notes, and snippets.

View joshuabaker's full-sized avatar
🎭

Joshua Baker joshuabaker

🎭
View GitHub Profile
@joshuabaker
joshuabaker / keybase.md
Created July 23, 2018 15:59
Keybase proof.

Keybase proof

I hereby claim:

  • I am joshuabaker on github.
  • I am joshuabaker (https://keybase.io/joshuabaker) on keybase.
  • I have a public key ASATyrPN0eBfpZ3ItW5ehJwZr0lRZATQJy0ZpojHnr7B3go

To claim this, I am signing this object:

@joshuabaker
joshuabaker / strip-utm-params-min.js
Last active June 7, 2018 15:42
Snippet to remove UTM parameters from using the History API.
!function(){var e=history,t=location;if(e&&e.replaceState&&t.search){var n=t.search.slice(1).split("&"),l=n.filter(function(e){return"utm_"!==e.slice(0,4)});if(l.length<n.length){var a=l.length?"?"+l.join("&"):"",i=t.pathname+a+t.hash;setTimeout(function(){e.replaceState(null,null,i)},3e3)}}}();
@joshuabaker
joshuabaker / sdlt.php
Last active August 17, 2017 11:35
Stamp duty land tax calculator that allows variable bands.
<?php
$bands = [
[
'threshold' => 0,
'primaryRate' => 0,
'secondaryRate' => 0.03,
],
[
'threshold' => 125000,
@joshuabaker
joshuabaker / commands.sh
Created November 27, 2016 15:25
Helpful git commands.
# Get latest tag
git describe --abbrev=0 --tags
# Get latest commit
git rev-parse HEAD
# Get latest commit author
git --no-pager show -s --format="%aN <%aE>" HEAD
# Get latest commit message (trimmed)
@joshuabaker
joshuabaker / table_sizes.sql
Created September 19, 2016 16:14
MySQL query that returns tables, row counts, and size in megabytes.
select
`table_schema` as `database`,
`table_name` as `table`,
format(`table_rows`, 0) as `rows`,
format(round(((`data_length` + `index_length`) / 1024 / 1024), 2), 2) as `megabytes`
from `information_schema`.`TABLES`
where `table_schema` != 'information_schema'
order by `database`, `data_length` + `index_length` desc;
@joshuabaker
joshuabaker / query.sql
Created August 18, 2016 13:38
Appends “ (duplicate)” to any duplicate tags within a Craft CMS database. Assumes table prefix is `craft_`.
UPDATE craft_content
SET craft_content.title = CONCAT(craft_content.title, ' (duplicate)')
WHERE craft_content.elementId IN (
SELECT tmp.elementId
FROM (
SELECT *
FROM craft_content
) AS tmp
JOIN craft_tags ON craft_tags.id = tmp.elementId
GROUP BY tmp.title
@joshuabaker
joshuabaker / insert-async-script.js
Created March 2, 2016 17:03
Insert a script and creates a global object. Inspired by the Google Analytics tracking code, and other services that don’t care about blocking pages.
(function(window, document, tag, src, object) {
window[object] = window[object] || [];
var script = document.createElement(tag);
script.async = true;
script.src = src;
var firstScript = document.getElementsByTagName(tag)[0];
firstScript.parentNode.insertBefore(script, firstScript);
}(window, document, 'script', '//example.com/path/to/file.js', 'myObject'));
@joshuabaker
joshuabaker / modernizr.videoautoplay.js
Created September 16, 2015 13:17
An adjust Modernizr test to check for autoplay support on video elements.
(function() {
var addTest = Modernizr.addTest;
var timeout;
var waitTime = 300;
var elem = document.createElement('video');
var elemStyle = elem.style;
function testAutoplay(arg) {
clearTimeout(timeout);
elem.removeEventListener('playing', testAutoplay, false);
@joshuabaker
joshuabaker / general.php
Created July 14, 2015 18:44
CloudFlare compatible config for Craft CMS.
<?php
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'],'on') === 0 || $_SERVER['HTTPS'] == 1))
{
$protocol = 'https://';
}
else if ( ! empty($_SERVER['HTTP_X_FORWARDED_PROTO']))
{
$protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://';
}