Skip to content

Instantly share code, notes, and snippets.

View johnmurch's full-sized avatar

John Murch johnmurch

View GitHub Profile
<!-- JUST ADD JS -->
<html>
<head>
<style>
/*! CSS Used from: https://fonts.googleapis.com/css?family=Google+Sans:400,500|Roboto:400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700|Material+Icons */
.material-icons{font-family:'Material Icons';font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:'liga';-webkit-font-smoothing:antialiased;}
/*! CSS Used from: https://www.gstatic.com/devrel-devsite/prod/v4d5d232859440be8edf63a1095b80ebe5c19605e99f3b348a30c4b0140c2eb88/cloud/css/app.css */
devsite-code{clear:both;direction:ltr!important;display:block;margin:16px 0;overflow:hidden;position:relative;}
devsite-code .devsite-code-buttons-container{position:absolute;right:0;top:0;}
devsite-code .devsite-code-buttons-container button{-webkit-box-align:center;-webkit-align-items:center;align-items:center;background:0;border:0;-webkit-border-radius
@johnmurch
johnmurch / keywordsFromUrl.js
Last active October 22, 2020 01:36
Parse keywords from URL
let url = "https://www.amazon.com/SanDisk-128GB-microSDXC-Memory-Adapter/dp/B073JYC4XM/";
let kwparse = (url.replace('https://','').replace('http://','').replace('www','').replace('com','').split('-').join().split('/').join().split('.')).join(',').replace(/^,/, '')
let kwuniq = [...new Set(kwparse.split(','))].filter(function(e){return e});
console.log(kwuniq)
// ["amazon", "SanDisk", "128GB", "microSDXC", "Memory", "Adapter", "dp", "B073JYC4XM"]
// Hat Tip - Find a cleaner version at https://gist.github.com/dsottimano/52060e6a43d96804f33c59366c472305
@johnmurch
johnmurch / parse.js
Created August 14, 2020 02:50
params
var myurl = "journey?reference=123&line=A&destination=China&operator=Belbo&departure=1043&vehicle=ARC";
var keyval = myurl.split('?')[1].split('&');
for(var x=0,y=keyval.length; x<y; x+=1)
console.log(keyval[x], keyval[x].split('=')[0], keyval[x].split('=')[1]);
/*
reference=123 reference 123
line=A line A
destination=China destination China
operator=Belbo operator Belbo
@johnmurch
johnmurch / isEnglish.js
Created September 11, 2020 01:31
Is URL English?
let url = "https://test.com/現役軍人轉公職-警察有哪些方法-補助5萬如何申請-4db7c0fd81b0"
const english = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?^[ -~]+$/;
if (english.test(url)) {
console.log("URL IS ENGLISH-most likely")
}
@johnmurch
johnmurch / links-console.js
Created September 11, 2020 01:35
PASTE INTO CHROME CONSOLE
@johnmurch
johnmurch / json2csv.js
Created October 16, 2020 20:16
json2csv quick hack
const data = [
{ "name": "John", "time": new Date().toISOString(), "age": "old" },
{
"name": "Jeff", "time": new Date().toISOString(), "age": "older"
}
]
const header = Object.keys(data[0]).map(_ => JSON.stringify(_)).join(';') + '\n'
const outData = data.reduce((acc, row) => {
return acc + Object.values(row).map(_ => JSON.stringify(_)).join(';') + '\n'
@johnmurch
johnmurch / getMakeModel.js
Last active October 22, 2020 15:13
Based on the copypasta code of a tweet, extract vehicle make/model from a url
/*
This was inspired by https://twitter.com/saksters/status/1319018185744650240 as a better way to extract vehicle make and model from a url
*/
// This should be in some database you have - array of makes and all of their models
const db = [{
"make": "Renault",
"models": ["Captur", "Clio", "Clio Grandtour", "Espace", "Express", "Fluence", "Grand Espace", "Grand Modus", "Grand Scenic", "Kadjar", "Kangoo", "Kangoo Express", "Koleos", "Laguna", "Laguna Grandtour", "Latitude", "Mascott", "Mégane", "Mégane CC", "Mégane Combi", "Mégane Grandtour", "Mégane Coupé", "Mégane Scénic", "Scénic", "Talisman", "Talisman Grandtour", "Thalia", "Twingo", "Wind", "Zoé"]
},
{
// open https://moz.com/mozcast
// open console and paste
let w = JSON.parse(JSON.stringify(document.querySelector('#metrics').__vue__.weather))
console.table(w)
@johnmurch
johnmurch / json2table.js
Last active August 23, 2021 18:46
table2json
function json2Table(json) {
let cols = Object.keys(json[0]);
//Map over columns, make headers,join into string
let headerRow = cols
.map(col => `<th>${col}</th>`)
.join("");
//map over array of json objs, for each row(obj) map over column values,
@johnmurch
johnmurch / upload.html
Created August 18, 2021 12:33
CSV Upload and Parse
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<head>
<title>CSV Upload/Parse</title>