Skip to content

Instantly share code, notes, and snippets.

@danfoust
danfoust / parse.html
Last active November 16, 2018 19:10
Parse XML File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Parse XML</title>
<script>
function getXML(fileUrl)
{
@danfoust
danfoust / style.css
Created December 18, 2018 19:58
If you're lazy loading images, this will prevent the flash of alt text that appears before the images are loaded.
img:not([src]) {
visibility: hidden;
}
/* IE/Edge */
img[data-src]:not([src]),
img[data-srcset]:not([src]) {
display: block;
min-height: 1px;
}
@danfoust
danfoust / jquery-passive-listener.js
Created December 20, 2018 22:01
Improves scroll performance by making jQuery events passive. Run directly after jQuery script is loaded. Read more: https://stackoverflow.com/questions/46094912/added-non-passive-event-listener-to-a-scroll-blocking-touchstart-event
jQuery.event.special.touchstart = {
setup: function( _, ns, handle ){
if ( ns.includes("noPreventDefault") ) {
this.addEventListener("touchstart", handle, { passive: false });
} else {
this.addEventListener("touchstart", handle, { passive: true });
}
}
};
@danfoust
danfoust / copyToClipboard.js
Created February 28, 2019 19:12
Simple Vanilla js approach for copying text of data attribute on click
document.querySelectorAll('.copy-text').forEach(function(elem) {
elem.addEventListener('click', function() {
var copyText = this.getAttribute('data-copyText');
copyToClipboard(copyText);
});
});
function copyToClipboard(text) {
var selected = false;
@danfoust
danfoust / settings.json
Created October 29, 2020 12:21
VSCode Settings
{
// -> Files
"files.trimTrailingWhitespace": true,
// -> Editor
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
@danfoust
danfoust / certgen.sh
Last active November 21, 2020 00:21
Create new SSL certs
#!/bin/bash
source /usr/bin/cprintf.sh
###########################################################
# Generate a new SSL
# @param string $1 domain
if [ -n "$1" ]; then
domain="$1"
@danfoust
danfoust / actions.php
Last active November 21, 2020 00:26
Useful Wordpress setup
add_action( 'init', function() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Remove oEmbed discovery links.
@danfoust
danfoust / main.go
Last active November 22, 2020 15:11
Simple Go HTTP Test
package main
import (
"fmt"
"net/http"
)
func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello World")
}
@danfoust
danfoust / nginx_Dockerfile
Created November 23, 2020 02:39
Basic Nginx + PHP-FPM Docker config
FROM nginx:1.19.4-alpine
COPY default.conf /etc/nginx/conf.d/
WORKDIR /var/www/html
@danfoust
danfoust / .vimrc
Created December 2, 2020 02:18
My custom Vim configuration
" Show line numbers
set nu
" Enable filetype plugins
filetype plugin on
filetype indent on
"Always show current position
set ruler