Skip to content

Instantly share code, notes, and snippets.

@danfoust
danfoust / launch.json | with npm script
Created April 13, 2022 01:27
Serverless Offline launch.json for breakpoints
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Serverless Offline",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}/backend",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "debug"]
@danfoust
danfoust / string-keys.type.ts
Created April 8, 2022 15:11
Narrow string | number union with utility type
/*
If you try to do `keyof SomeType`, and `SomeType` has an interface of `[key: string]: x`
TypeScript will infer that to a union of `string | number` because JavaScript coerces numeric
indexes to strings.
Example: obj[0] -> obj["0"]
This can make it annoying to try to create an interface for interacting with one of these
types when we know we only want to accept string values, or that's a rule we want to enforce.
@danfoust
danfoust / scatter-gather.go
Created December 30, 2020 12:55
Work will only take as long as slowest process
// 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 December 30, 2020 12:52
Async/Await in Golang
c := make(chan User, 1)
go func() { c <- getUser() }() // async
user := <-c // await
@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
@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 / 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 / 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 / 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 / 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"