Skip to content

Instantly share code, notes, and snippets.

View bameyrick's full-sized avatar

Ben Meyrick bameyrick

View GitHub Profile
@bameyrick
bameyrick / export-jira-tickets.sh
Last active April 29, 2024 09:31
Export CSV of JIRA tickets for current branch
#!/bin/bash
# The name of your main branch e.g. main, trunk
MAIN_BRANCH='main'
# The prefix added to your JIRA tickets
JIRA_PREFIX='JIRA'
# The url of your JIRA
JIRA_URL='https://example.atlassian.net'
@bameyrick
bameyrick / delete-merged
Last active April 7, 2022 15:19
Deletes branches that have been merged on remote. Can be added to your .zshrc
delete-merged() {
git remote prune origin; git fetch -p; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
}
@bameyrick
bameyrick / replace-not-between-tags.txt
Created January 3, 2019 11:05
Regex to replace something that is not wrapped / between HTML tags
/(?!<div[^>]*?>)(Test)(?![^<]*?<\/div>)/g
@bameyrick
bameyrick / attribute-observer.js
Created August 4, 2016 16:06
Watch for changes and mutations to attributes on DOM elements
window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
if(window.MutationObserver) {
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
console.log(mutation.attributeName)
});
});
observer.observe(document.getElementById('#my-element'), { attributes: true });
@bameyrick
bameyrick / geography.js
Created July 20, 2016 15:59
Calculate distance between two positions (latitude and longitude)
export function calculate_distance(latLng_a, latLng_b)
{
const radius = 6371;
const lat_a = latLng_a.split(',')[0];
const lng_a = latLng_a.split(',')[1];
const lat_b = latLng_b.split(',')[0];
const lng_b = latLng_b.split(',')[1];
const dLat = ConvertToRadians(lat_a - lat_b);
const dLon = ConvertToRadians(lng_a - lng_b);
@bameyrick
bameyrick / _fluid-property.scss
Last active June 8, 2016 08:37
Useful for responsive CSS typography
/*
Props:
$property: Any CSS that accepts calc(), viewport units and pixels, ie. Most properties… height/width/padding/font-size etc.
$min: The minimum size.
$max: The maximum size.
$start: $min will be used at any resolution lower than this.
$end: $max value will be used at any resolution higher than this.
$clip: When set to false, this disables clipping with the $start and $end properties.
$clipAtStart: When set to false, this disables clipping with the $start property.
$clipAtEnd: When set to false, this disables clipping with the $end property.
@bameyrick
bameyrick / detect-number-of-children.css
Created March 29, 2016 09:04
Detect the number of children purely in css
/* one item */
li:first-child:nth-last-child(1) {
width: 100%;
}
/* two items */
li:first-child:nth-last-child(2),
li:first-child:nth-last-child(2) ~ li {
width: 50%;
}
@bameyrick
bameyrick / validate-uk-phone.js
Last active August 10, 2016 10:05
ES6 Validate a UK Telephone number
export default function ValidateUKPhone(number) {
const errorMessages = [
"Please enter a UK telephone number without the country code.",
"UK telephone numbers should contain 10 or 11 digits.",
"The telephone number should start with a 0.",
"The telephone number is either invalid or inappropriate."
];
@bameyrick
bameyrick / hex-to-rgb.js
Last active August 10, 2016 10:06
Convert a hex colour value to RGB values
function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, (m, r, g, b) => {
return r + r + g + g + b + b;
});
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
@bameyrick
bameyrick / Micro Template Parser
Created July 7, 2015 16:04
A simple script to parse microtemplates
(function () {
var cache = {};
this.tmpl = function tmpl(str, data) {
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('" +
str.replace(/[\r\t\n]/g, " ")