Skip to content

Instantly share code, notes, and snippets.

View joshuabaker's full-sized avatar
🎭

Joshua Baker joshuabaker

🎭
View GitHub Profile
@joshuabaker
joshuabaker / component.jsx
Created December 15, 2020 11:24
Component JSX template for Intellij
import React from 'react'
import css from '@styled-system/css';
import PropTypes from 'prop-types';
import styled from 'styled-components';
function ${NAME}() {
return <>
{'${NAME}'}
</>
}
@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'] . '://';
}
@joshuabaker
joshuabaker / html.js
Created July 23, 2014 15:31
Sample script to load a script asynchronously whilst queuing method calls. Inspired by the Google Analytics tracking code.
// Placed into HTML
(function(window, document, tag, src, property, script, before)
{
window['LoaderObject'] = property;
window[property] = window[property] || function()
{
(window[property].q = window[property].q || []).push(arguments);
}
@joshuabaker
joshuabaker / package.json
Last active January 15, 2019 17:01
Removes outline for mouse users but preserves it for keyboard users.
{
"name": "remove-focus-outline",
"version": "1.0.0"
}
@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 / gist:179e1a9ff6f727cdc7e5
Created March 30, 2015 10:58
Get a line change count for additions and deletions between two commits — replace ‘commit1’ and ‘commit2’ with commit hashes — optionally by author.
git log --numstat --pretty="%H" commit1..commit2 | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}' --author="Your Name"
@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;