Navigation Menu

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 / addDay.js
Created March 22, 2019 02:13
JavaScript: add a day to a date if one time is less than another
const startedTime = '14:30';
const completedTime = '01:15';
const startedDate = '20/01/2019';
if (completedTime < startedTime) {
const [day, month, year] = startedDate.split('/');
const currentDate = new Date(Date.parse(`${year}-${month}-${day}`));
const currentDateUnix = currentDate.valueOf();
const newDateUnix = currentDateUnix + 24*60*60*1000;
@yayMark
yayMark / findParentTagId.js
Created March 9, 2019 23:44
WordPress, Elementor: Get to a parent element of a Elementor element that I attach a class to. I wish I didn't have to do this.
function findParentTagId(childClass, parentTag) {
var element = document.querySelector(childClass);
var tag = element.tagName;
// repeat until you get to body
while (tag != 'body') {
element = element.parentElement;
if (element.tagName.toLowerCase() === parentTag.toLowerCase()) {
var dataset = element.dataset['id'];
return document.querySelector('[data-id="' + dataset + '"]');