Skip to content

Instantly share code, notes, and snippets.

@danfoust
danfoust / settings.jsonc
Created December 28, 2025 21:03
VSCode settings
{
// Editor
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.renderWhitespace": "all",
@danfoust
danfoust / gist:0a85eca3fe71e69ecfeb1851fb7d5fb6
Created February 23, 2025 19:23
uBlock Origin - Hide search results by domain
# Desktop
www.google.com##div[class="g"]:has(a[href*="example.com"])
# Mobile
www.google.com##div[lang="en"]:has(a[href*="example.com"])
@danfoust
danfoust / Dockerfile
Created October 27, 2024 17:53
Local Ansible - Vagrant with Docker Provider
##############################################################################################
# This helps unblock me on following a long with materials for learning Ansible and Kubernetes
# locally, which rely on a VM service.
#
# I did not want to use VirtualBox, because on Linux it requires tainting the kernel. I also
# already have Docker installed and it's said to have better performance/less overhead.
#
# This Dockerfile will setup an Ubuntu container and configure it to support SSH, which is
# required for testing Ansible locally with Vagrant.
#
@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 / 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 / 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;
}