Skip to content

Instantly share code, notes, and snippets.

View johnmurch's full-sized avatar

John Murch johnmurch

View GitHub Profile
@johnmurch
johnmurch / date.js
Last active November 5, 2020 17:56
dd/mm/yyyy hh:mm:ss
var d = new Date();
alert(
("00" + (d.getMonth() + 1)).slice(-2) + "/" +
("00" + d.getDate()).slice(-2) + "/" +
d.getFullYear() + " " +
("00" + d.getHours()).slice(-2) + ":" +
("00" + d.getMinutes()).slice(-2) + ":" +
("00" + d.getSeconds()).slice(-2)
);
@johnmurch
johnmurch / autoclose.js
Created October 12, 2019 02:33
Random Puppeteer Snippet - Closes most modals
// fuck modals!
await page.evaluate(() => {
Array.from(document.getElementsByClassName('close')).filter((c) => { c.click()})
});
@johnmurch
johnmurch / epoch
Created October 10, 2019 00:54
Terminal command to get epoch
date +%s
@johnmurch
johnmurch / RunFromTerminal
Created January 14, 2019 18:07
Replace spaces with hyphens in Mac file names - cd to directory and run the following
for i in *; do mv "$i" "`echo $i | sed -e 's, ,-,g'`"; done
@johnmurch
johnmurch / csvRead.js
Created January 10, 2019 16:06
Read a CSV file in Node.js
var fs = require('fs'),
readline = require('readline'),
stream = require('stream');
var instream = fs.createReadStream('./FILE.csv');
var outstream = new stream;
outstream.readable = true;
var isHeaders = true; // default - there exists a header, or swap true/false
var headers = [];
@johnmurch
johnmurch / log.js
Last active December 4, 2018 16:29
Making Logging Great Again
function _log(blob){
console.log(blob)
}
function _jlog(blob){
console.log(JSON.stringify(blob,null,4))
}
/*
* Example
@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()
@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 / 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 / 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">