Skip to content

Instantly share code, notes, and snippets.

@iimos
iimos / NodeList-ext.js
Created September 18, 2015 06:09
document.querySelectorAll("*").forEach
"forEach,map,filter,reduce,reduceRight,every,some".split(",").forEach(function(p) {
NodeList.prototype[p] = HTMLCollection.prototype[p] = Array.prototype[p]
})
@iimos
iimos / xpath.js
Last active June 24, 2024 17:05
Micro function that gives xpath by element and elements by xpath.
function xpath(el) {
if (typeof el == "string") return document.evaluate(el, document, null, 0, null)
if (!el || el.nodeType != 1) return ''
if (el.id) return "//*[@id='" + el.id + "']"
var sames = [].filter.call(el.parentNode.children, function (x) { return x.tagName == el.tagName })
return xpath(el.parentNode) + '/' + el.tagName.toLowerCase() + (sames.length > 1 ? '['+([].indexOf.call(sames, el)+1)+']' : '')
}
// Usage:
@iimos
iimos / optimize-images.sh
Last active August 21, 2023 08:50
Script for JPEG images optimization
#! /bin/sh
# Usage 1:
# optimize-images.sh /images/dir
#
# Usage 2:
# cd /images/dir
# optimize-images.sh
EXTENSIONS="jpe?g"