Skip to content

Instantly share code, notes, and snippets.

Avatar

Sebastian Good scagood

View GitHub Profile
View .readme.md

Hover-highlight-selectors

This will script will do a few things

  1. It will create a toggle able transparent box around the element you're hovering over.
  2. When control is held (with /flamencist/SelectorGenerator included) and an element is clicked a pop-up of the CSS-selector of the element you clicked on will show.
  3. This hover outline effect can be toggled using scroll lock on your keyboard.

Running

Simply include:

@scagood
scagood / Promise.almost.es5.js
Created Mar 12, 2018
Promise.all `ignoring` the rejections.
View Promise.almost.es5.js
Promise.almost = function(array) {
return Promise.all(
array.map(function(promise) {
return promise.catch
? promise.catch(function(error) {
return error;
})
: promise;
})
);
@scagood
scagood / example.js
Created Mar 5, 2018
A naiive XML formatter.
View example.js
// Example format, using '\t' as the indenter
formatXml(`<xmlstuff id=123 style="asd"><head></head>
<tag1>
rerasdfas
fvzx
ss
</tag1></xmlstuff>
`, '\t')
// output:
output = `<xmlstuff id=123 style="asd">
@scagood
scagood / destructor.js
Created Feb 12, 2018
ES6 esq destructor given an input array and a string
View destructor.js
function destructor(values, keys) {
const output = {};
const kReg = /(?:"([^"]+)"|'([^']+)'|(\w+))/g;
keys = keys.replace(/\{[^{}]+\}/g, match => match.replace(kReg, '"$1$2$3":"$1$2$3"'));
keys = keys.replace(kReg, '"$1$2$3"');
console.log(keys);
keys = JSON.parse(keys);
function forAll(array, func, loc) {
View for-raw-d.js
require('events').EventEmitter.defaultMaxListeners = 250;
const net = require('net');
const strs = require('stringstream')
process.setMaxListeners(0);
const inPort = 541;
const toPort = 8080;
@scagood
scagood / domMonitor.js
Created Jan 29, 2018
Monitor the DOM for the creation of specific tags (Not sure what this can be used for... but hey!)
View domMonitor.js
const domMonitor = function (tagname, eventname, options) {
tagname = tagname.trim().toLowerCase();
eventname = eventname.trim();
options = options || {};
const property = options.property || 'outline-color';
const propertyFrom = options.property || '#fff';
const propertyTo = options.property || '#000';
const evn = new Event(eventname, {
@scagood
scagood / 1.iFrame.Relative.Messages.md
Created Jan 29, 2018
iframe message events attached to the iframe, not the window
View 1.iFrame.Relative.Messages.md

Attach message events to iframe elements

Usage

Very simply copy/download and include iframe.message.js into your document, then start attatching event listeners.

Example inclusions:

<script src="iframe.message.js"></script>

Or:

@scagood
scagood / funcToWorker.js
Created Jan 26, 2018
Runs a given function inside a web worker.
View funcToWorker.js
function workerFromFunc(func) {
// Convert the function to a string
// Make the auto callable
func = '(' + func.toString() + ')()';
// Convert the function to a blob
const type = 'application/javascript';
const blob = new Blob(
[func],
{type}
@scagood
scagood / getArgs.js
Created Jan 26, 2018
Provides a simple function to get the arguments of a function
View getArgs.js
function getArgs(func) {
/**
* Basic function regex
* - /^function\s*\w*\(([\w\W]*?)\)\s*{/
*
* Arrow function regex
* - /^([^()]*)\s*=>/
* - /^\(([\w\W]*?)\)\s*=>/
* */
@scagood
scagood / cssPath.js
Created Jan 25, 2018
A simple function to get the CSS style path of an element.
View cssPath.js
const cssPath = (function () {
function tagUnique(l) {
const es = [].filter.call(
l.parentElement.children,
e => e !== l
);
return -1 === []
.map.call(es, e => e.tagName)
.indexOf(l.tagName);
}