Skip to content

Instantly share code, notes, and snippets.

View yayMark's full-sized avatar
💾
Gettin ma tech awn

Mark Hewitt yayMark

💾
Gettin ma tech awn
  • Perth, Western Australia
View GitHub Profile
@yayMark
yayMark / attribute-within-element.regex.txt
Last active November 1, 2023 06:30
RegEx: look for an element name containing and attribute name over a single or multiple lines
<elementname(?:.*?(\n){0,}){1,}?.*?attributename
@yayMark
yayMark / backup.sh
Created June 12, 2021 00:58
Shell: backup web directory and database
#!/bin/bash
_project="project"
_env="local"
_root="/mnt/c/work/hmr/backups"
_webdir="web"
_webext=".tar.gz"
if [ -n "$1" ] && [ "$1" != " " ]; then
_suffix="-$1"
@yayMark
yayMark / keybindings.json
Created August 11, 2020 02:41
Visual Studio Code snippets
[
{
"key": "shift+alt+cmd+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.log('${TM_SELECTED_TEXT}$1: ', ${TM_SELECTED_TEXT})$2;"
}
},
{
@yayMark
yayMark / hideTwitterTrending.js
Last active March 8, 2020 00:49
JS: hide trending on Twitter
const sidebar = document.querySelectorAll('[data-testid=sidebarColumn]')[0];
const trending = sidebar.querySelector('div > div > div > div > div > div:nth-child(3)');
trending.style.display = 'none';
@yayMark
yayMark / objectAsJSON.js
Last active March 8, 2020 00:47
JavaScript: pretty print an object as formatted plain text
console.log(JSON.stringify(obj, null, 2));
@yayMark
yayMark / redirect-test.sh
Created October 4, 2019 23:08
Shell: test if a website is redirecting due to server or application software
curl -I http://site.test
@yayMark
yayMark / gist:ffdb066c0a7517ef023add8edd1987e5
Created October 4, 2019 02:46
RegEx: multiline string match
<StyledDialog[\n\s][\s\S]*?size=({'|')xs
@yayMark
yayMark / carsalesHelper.js
Last active September 17, 2019 23:55
JavaScript: carsales.com.au helper - get the year of the car and odometer reading from the DOM
// year of car
document.querySelector('.details-wrapper h1').innerText.split(' ')[0]
// odometer
Number(document.querySelector('.key-details-item-title').innerText.split(' ')[0].replace(/,/g, ''))/20000
// 20000 km average a year
@yayMark
yayMark / swap_regular_and_sale_prices.php
Created October 18, 2018 02:54
WooCommerce: swap sale and regular pricing display
<?php
add_filter( 'woocommerce_get_price_html', 'my_price_html', 100, 2 );
function my_price_html( $price, $product ){
// swap the regular and sale prices
$pos_start = strpos($price, '<del>');
if ($pos_start !== false) {
$end = '</del>';
$end_length = strlen($end);
$pos_end_start = strpos($price, $end);
$pos_end = $pos_end_start + $end_length;
@yayMark
yayMark / add_bootstrap_control_class.php
Created September 5, 2018 05:48
Apply Bootstrap 4 custom checkboxes and radio buttons to Gravity Fields generated forms
<?php
// Apply Bootstrap 4 custom checkboxes and radio buttons to Gravity Fields generated forms
// Derived from https://jayhoffmann.com/using-gravity-forms-bootstrap-styles/
add_filter( 'gform_field_container', 'add_bootstrap_control_class', 10, 6 );
function add_bootstrap_control_class( $field_container, $field, $form, $css_class, $style, $field_content ) {
$id = $field->id;
$field_id = is_admin() || empty( $form ) ? "field_{$id}" : 'field_' . $form['id'] . "_$id";