Skip to content

Instantly share code, notes, and snippets.

View jdvivar's full-sized avatar
💭
"Fail faster"

Daniel Vivar jdvivar

💭
"Fail faster"
View GitHub Profile
@jdvivar
jdvivar / compile_sagepay_templates.sh
Last active March 22, 2018 13:39
Excerpt of a script to compile Sagepay XML/XSLT2 into HTML
#!/usr/bin/env bash
# This file is a excerpt of a bigger script
# Files lists, they should be matching
xml_list=(
'authorisation'
'card_authentication'
'card_details'
'error'
@jdvivar
jdvivar / sagepay.sh
Created March 22, 2018 13:40
Script to compile Sagepay XML/XSLT2 into HTML
#!/usr/bin/env bash
# Sagepay templates script file
# Function to show help with the use of this script
help()
{
echo "compile Compiles XML/XSLT to HTML"
echo "bundle Create bundle to send to Sagepay"
echo "help Show this help"
echo ""
@jdvivar
jdvivar / findAnchorURLs.js
Last active December 10, 2019 12:42
Find all anchor URLs (including in web components' shadow root nodes)
function recursiveFindAnchors(node) {
if (!node) return []
// Find anchors URLs
const bareAnchorURLs = [...node.querySelectorAll('a')].map(anchor => formatHref(anchor.href))
// Find all shadow roots
const allShadowRoots = [...node.querySelectorAll('*')].filter(node => node.shadowRoot).map(node => node.shadowRoot)
// No web components in here
@jdvivar
jdvivar / waitThenDo.js
Last active March 25, 2020 12:56
Wait for an element to appear, then when it does, do something with it
const interval = window.setInterval(() => {
// Search target element
const target = document.querySelector(...)
if (target) {
window.clearInterval(interval)
// Do something with target element
target.innerText = 'Meow'
}
}, 100)
@jdvivar
jdvivar / webComponentStyleAddition.js
Last active January 24, 2020 13:06
Add style rules inside Web Components
// target is a web component with an open ShadowDOM
const target = document.querySelector(...)
target.shadowRoot.styleSheets[0].insertRule(`
selector {
padding: 8px;
}
`)
@jdvivar
jdvivar / pixel-anchor-observer.js
Last active March 8, 2020 11:47
Improved pixel anchor observer from
// Res.: https://css-tricks.com/styling-based-on-scroll-position/
let anchor = document.getElementById('pixel-anchor')
if (!anchor) {
const interval = window.setInterval(() => {
anchor = document.getElementById('pixel-anchor')
if (anchor) {
window.clearInterval(interval)
createObserver(anchor)
@jdvivar
jdvivar / gist:40afcf8b0a68e22bbc9bbf3df60d5dd7
Created October 28, 2020 13:53
NPM script to remove 443 port from package-lock
"remove-443": "sed -i '' 's/.net:443/.net/g' package-lock.json"
@jdvivar
jdvivar / customElementDedupe.ts
Created June 2, 2021 14:58
Dedupe customElements definitions
export function customElementDedupe(): void {
const define: Function = window.customElements.define.bind(window.customElements);
window.customElements.define = (
name: string,
constructor: Function,
options: object,
): void => {
if (!window.customElements.get(name)) define(name, constructor, options);
};
}
@jdvivar
jdvivar / ffmpeg example
Last active January 25, 2023 12:46
Simple ffmpeg one liner
# With a specific codec
-i input
-codec:v video codec to use, most modern is libx265
# libx265 is slower but provides a smaller file size output, by default is usually
# libx264 which is the most compatible, faster than x265 but with a bigger file output
$ ffmpeg -i video.mov -codec:v libx265 video.mp4
# Simplest version