Skip to content

Instantly share code, notes, and snippets.

View johnmurch's full-sized avatar

John Murch johnmurch

View GitHub Profile
@johnmurch
johnmurch / dump.sh
Created September 14, 2016 12:59
Merge error and log files into 1 file
#!/bin/bash
tail -n +1 file1.txt file2.txt file3.txt >> log.txt
#==> file1.txt <==
#<contents of file1.txt>
#==> file2.txt <==
#<contents of file2.txt>
#==> file3.txt <==
#<contents of file3.txt>
@johnmurch
johnmurch / clickaway.js
Last active September 15, 2016 17:45
JS Scripts on closing modals - WIP
(function () {
var el = document.elementFromPoint(500, 100);
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 1, 1, false, false, false, false, 0, null);
el.dispatchEvent(evt);
});
@johnmurch
johnmurch / thirty-days-or-less.js
Created February 15, 2017 17:37
Determine is today within 30 days of a date and/or has past
var today = new Date();
alert(today);
var future_date = new Date('2017/1/20 13:03:35 GMT-0400');
alert(future_date);
var difference = future_date.getTime() - today.getTime();
var thirty_days = 3600 * 24 * 30 * 1000;
alert(difference < thirty_days);
@johnmurch
johnmurch / gist:6ea196e5f5b337cdc1da083299edcf07
Created June 27, 2017 18:58
Backup Raspberry Pi Remote
ssh root@raspberrypi dd if=/dev/mmcblk0 | gzip -c > img.gz
@johnmurch
johnmurch / phone.js
Last active April 1, 2019 12:21
Phone Number Sanitize and Print Friendly
var phone = '2125551212';
// make 10 digit phone number pretty
phone = phone.replace(/[^\d]+/g, '')
.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
// (212) 555 - 1212
console.log(phone);
var inputPhone = "(212) 555 - 1212";
var cleanPhone = inputPhone.replace(/\D/g,'');
@johnmurch
johnmurch / client.py
Created June 6, 2018 14:55
Python Simple Socket Server
import socket
s = socket.socket()
host = "0.0.0.0" # REPLACE with IP of server
port = 12345
s.connect((host, port))
s.send("foo")
s.close()
@johnmurch
johnmurch / sample-form.html
Last active August 2, 2018 01:44
Passing GA UTM Data to Form
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<meta name="description" content="A multi column contact form for Bootstrap 4" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<style type="text/css">
@johnmurch
johnmurch / serp.js
Created August 3, 2018 00:11
Parse SERP on-page via Chrome Console
// RUN from console in Chrome on a Google SERP page -> use &num=100 param in URL
var links = [];
for(i=0;i<=100;i++){
if(document.evaluate('//*[@id="rso"]/div/div/div['+i+']/div/div/h3/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue){
links.push({
"url":document.evaluate('//*[@id="rso"]/div/div/div['+i+']/div/div/h3/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.href,
"title":document.evaluate('//*[@id="rso"]/div/div/div['+i+']/div/div/h3/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML,
"description":document.evaluate('//*[@id="rso"]/div/div/div['+i+']/div/div/div/div/span', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML
});
}
@johnmurch
johnmurch / twitter-follower-onpage.js
Last active August 6, 2018 12:47
Twitter Follower Parse on-page
// Twitter URL
// document.querySelectorAll('.ProfileCard-avatarLink')[2].href
// Twitter Handle
// document.querySelectorAll('.ProfileCard-avatarLink')[2].href.replace("https://twitter.com/","")
// Twitter Name
// document.querySelectorAll('.ProfileNameTruncated-link')[3].innerHTML.trim()
// Twitter Profile Image
@johnmurch
johnmurch / monitor.sh
Last active August 9, 2018 15:01
Ghetto Pi Monitor & Server Restart
#!/bin/bash
LOGFILE="/home/pi/status.log"
MAILGUN_API_KEY="XXXXXXXX"
MAILGUN_DOMAIN="XXXXXX"
SENDER="XXXXXXX"
RECEPIENT="XXXXX"
SUBJECT="Server Down"
TEXT="Restarting Server..."
echolog()