Skip to content

Instantly share code, notes, and snippets.

View segdeha's full-sized avatar
🏠
Working from home

Andrew Hedges segdeha

🏠
Working from home
View GitHub Profile
@segdeha
segdeha / less-annoying.js
Created November 27, 2018 23:55
Make web pages less annoying by removing most videos and ads as well as elements set to `position: fixed`
javascript:(function(){Array.from(document.querySelectorAll('.canvas-yahoovideo,iframe,video')).forEach(video=>video.parentNode.removeChild(video));Array.from(document.querySelectorAll('*')).filter(node=>window.getComputedStyle(node).position==='fixed').forEach(node=>node.style.display='none');}());
@segdeha
segdeha / loops.js
Created August 17, 2018 21:22
`for of` versus `forEach`
let arr = ['a', 'b', 'c'];
for (const [i, x] of arr.entries()) {
console.log(i, x);
}
arr.forEach((x, i ) => {
console.log(i, x);
});

Keybase proof

I hereby claim:

  • I am segdeha on github.
  • I am segdeha (https://keybase.io/segdeha) on keybase.
  • I have a public key ASAHfqvOme4nKsxgAglMCDbROQQ_DebYzZ2XEOGz3k7A0Qo

To claim this, I am signing this object:

@segdeha
segdeha / strings.js
Created September 29, 2016 17:58
Method for creating abstracted string generators
/**
* Returns a function that composes strings from ES6 template literals.
* Based on http://stackoverflow.com/a/22619256/11577
*
* @usage formatter`${0}, ${1}!`.format('Hello', 'world') // -> 'Hello, world!'
*
* @param array<string> literals Array of string literals
* @param array<mixed> substitutions Rest parameter of substitution values
*
* @return function
bob = [
['a', 'b'],
['c', 'd'],
['e', 'f', 'g'],
['i'],
['j', 'k'],
['l', 'm'],
['n']
]
@segdeha
segdeha / ajax-post.js
Last active October 28, 2015 19:34
Smallest possible Ajax implementation of POST requests (195 characters)
function p(u,p,c){var x=new XMLHttpRequest;x.open('POST',u);x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.onreadystatechange=function(){3<x.readyState&&c(x)};x.send(p)}
// based on: http://snipt.org/rpp (which seems now defunct)
function Template(str) {
this.rgx = /{{([^{}]*)}}/g
this.str = str || ''
}
Template.prototype.evaluate = function (vals) {
vals = vals || {}
function repr(str, match) {
return 'string' === typeof vals[match] || 'number' === typeof vals[match] ? vals[match] : str
}
function Timer() {
this.start = +new Date
}
Timer.prototype.stop = function () {
this.stop = +new Date
this.elapsed = '<em>Elapsed: ' + (this.stop - this.start) + 'ms</em>'
}
@segdeha
segdeha / klass.js
Created August 29, 2015 23:02
Simple example of chaining
/**
* Allow chaining of classList methods
* @usage klass( document.querySelector('#my-view') ).remove( 'hidden' ).adds( ['active', 'loading'] );
*/
function klass(el) {
var api = (function () {
return {
add : function (klass) {
el.classList.add(klass);
@segdeha
segdeha / ajax120.js
Last active June 23, 2020 04:21
Smallest possible Ajax implementation (120 characters)
function a(u,c){var x=new XMLHttpRequest;x.open('GET',u);x.onreadystatechange=function(){3<x.readyState&&c(x)};x.send()}