Skip to content

Instantly share code, notes, and snippets.

View johnmurch's full-sized avatar

John Murch johnmurch

View GitHub Profile
@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 / 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 / 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 / epoch
Created October 10, 2019 00:54
Terminal command to get epoch
date +%s
@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 / 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 / epoch2date.js
Created November 3, 2019 03:03
Convert EPOCH to Date
var utcSeconds = 1234567890;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
@johnmurch
johnmurch / gist-getHostname-getDomain.js
Created March 11, 2020 01:24
getHostname & getDomain -- Simple function for parsing
function getHostName(url) {
var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
return match[2];
}
else {
return null;
}
}
@johnmurch
johnmurch / headings.js
Created March 24, 2020 23:55
Puppeteer Heading tags - Snippet
const h1s = await page.evaluate(
() => [...document.querySelectorAll('h1')].map(elem => elem.innerText.trim()))
const h2s = await page.evaluate(
() => [...document.querySelectorAll('h2')].map(elem => elem.innerText.trim()))
const h3s = await page.evaluate(
() => [...document.querySelectorAll('h3')].map(elem => elem.innerText.trim()))
const h4s = await page.evaluate(
() => [...document.querySelectorAll('h4')].map(elem => elem.innerText.trim()))
const h5s = await page.evaluate(
() => [...document.querySelectorAll('h5')].map(elem => elem.innerText.trim()))
@johnmurch
johnmurch / save.js
Created May 6, 2020 04:22
console.save - Use to download an object from Google Chrome Console
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'