Skip to content

Instantly share code, notes, and snippets.

View mknospe's full-sized avatar

Martin Knospe mknospe

  • Berlin, Germany
View GitHub Profile
@mknospe
mknospe / generateGoogleCustomFontLinks.js
Created May 28, 2019 10:01
Synchronous NodeJS script to parse CSS files and read out used font-family, font-weight and font-styles to generate a <link> tag for Google custom fonts.
@mknospe
mknospe / elementReadyObserver.js
Created May 3, 2019 10:15
ES5 Element ready observer using a MutationObserver to detect, if an HTML element generated on runtime is ready to be accessed.
function isElement(addedNode, selector, callback) {
if (typeof addedNode.querySelector === 'function' && addedNode.querySelector(selector)) {
callback();
}
}
var elementReadyObserver = new MutationObserver(function (mutations) {
for (var i=0, numMutations=mutations.length; i<numMutations; i++) {
for (var j=0, numNodes=mutations[i].addedNodes.length; j<numNodes; j++) {
isElement(mutations[i].addedNodes[j], '#YOUR-CSS-SELECTOR > .OF-THE-ELEMENT.TO-OBSERVE', function() {
@mknospe
mknospe / carrierLookup.js
Last active April 25, 2019 16:04
NodeJS script to lookup carrier information in parallel using the paid service twilio. (https://www.twilio.com/docs/api/lookups) The data is read from a CSV-file, parsed, processed and written to the output csv-file.
// Install dependencies
// npm i -s node-fetch csv-writer csvtojson
const fetch = require('node-fetch');
const csvToJson = require('csvtojson');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
function lookup(phonenumber) {
const sid = '__YOUR_TWILIO_SID__';
const token = '__YOUR_TWILIO_AUTH_TOKEN__';