Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Foust danfoust

  • US
View GitHub Profile
@danfoust
danfoust / scatter-gather.go
Created Dec 30, 2020
Work will only take as long as slowest process
View scatter-gather.go
// Scatter
c := make(chan result, 10)
for i := 0; i < cap(c); i++ {
go func() {
val, err := process()
c <- result{val, err}
}()
}
// Gather
@danfoust
danfoust / async-await.go
Created Dec 30, 2020
Async/Await in Golang
View async-await.go
c := make(chan User, 1)
go func() { c <- getUser() }() // async
user := <-c // await
@danfoust
danfoust / .vimrc
Created Dec 2, 2020
My custom Vim configuration
View .vimrc
" Show line numbers
set nu
" Enable filetype plugins
filetype plugin on
filetype indent on
"Always show current position
set ruler
@danfoust
danfoust / nginx_Dockerfile
Created Nov 23, 2020
Basic Nginx + PHP-FPM Docker config
View nginx_Dockerfile
FROM nginx:1.19.4-alpine
COPY default.conf /etc/nginx/conf.d/
WORKDIR /var/www/html
@danfoust
danfoust / main.go
Last active Nov 22, 2020
Simple Go HTTP Test
View main.go
package main
import (
"fmt"
"net/http"
)
func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello World")
}
View settings.json
{
// -> Files
"files.trimTrailingWhitespace": true,
// -> Editor
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
@danfoust
danfoust / actions.php
Last active Nov 21, 2020
Useful Wordpress setup
View actions.php
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 / certgen.sh
Last active Nov 21, 2020
Create new SSL certs
View certgen.sh
#!/bin/bash
source /usr/bin/cprintf.sh
###########################################################
# Generate a new SSL
# @param string $1 domain
if [ -n "$1" ]; then
domain="$1"
@danfoust
danfoust / copyToClipboard.js
Created Feb 28, 2019
Simple Vanilla js approach for copying text of data attribute on click
View copyToClipboard.js
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 / jquery-passive-listener.js
Created Dec 20, 2018
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
View jquery-passive-listener.js
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 });
}
}
};