Skip to content

Instantly share code, notes, and snippets.

View disintegrator's full-sized avatar

Georges Haidar disintegrator

View GitHub Profile
@disintegrator
disintegrator / https-during-dev.macos.sh
Last active April 23, 2024 22:41
Use Caddy, mkcert and dnsmasq to expose your development server over HTTPS
brew install caddy mkcert nss dnsmasq
mkcert -install
mkcert '*.app.test' '*.cdn.test'
# rename the certs and move them under /usr/local/etc/caddy/certs
cat <<EOF > /usr/local/etc/caddy/Caddyfile
*.app.test:443, *.cdn.test:443 {
@disintegrator
disintegrator / discard.go
Created March 4, 2024 10:11
DiscardHandler for log/slog in Go
package log
import (
"context"
"log/slog"
)
// A DiscardHandler discards all log records.
type DiscardHandler struct{}
@disintegrator
disintegrator / assert.go
Last active March 1, 2024 13:04
Assertions in Go
package main
import (
"errors"
"fmt"
"runtime"
)
func Assert(group string, pairs ...any) error {
if len(pairs)%2 != 0 {
@disintegrator
disintegrator / demo.ts
Last active November 10, 2023 15:13
console.group and the `using` keyword
function logGroup(label: string) {
console.group(label)
return {
[Symbol.dispose]: () => {
console.groupEnd()
}
}
}
function demo() {
package functional
import (
"context"
"errors"
"time"
"github.com/benthosdev/benthos/v4/public/service"
)
@disintegrator
disintegrator / sample.test.ts
Last active June 19, 2023 16:52
A sample test helper used to acquire resources and automatically tear them down with the upcoming `using` keyword.
// This is untested code. More of a proof of concept for what's to come...
async function $acquire<
Resource
>(fn: () => Promise<readonly [resource: Resource, teadown?: () => void]>) {
let [resource, teardown = () => {}] = await fn();
return {
resource,
[Symbol.dispose]: teardown,
}
@disintegrator
disintegrator / wdio.conf.js
Created June 9, 2017 04:13
Run Chrome Headless with WebdriverIO and selenium-standalone
exports.config = {
capabilities: [
{
browserName: 'chrome',
chromeOptions: {
args: ['headless', 'disable-gpu'],
},
},
],
services: ['selenium-standalone'],
@disintegrator
disintegrator / GatsbyContentfulWithReadingTime.graphql
Last active June 19, 2022 13:43
Add a reading time estimate to all your Contentful rich text nodes in GatsbyJS
{
contentfulBlogPost {
body {
fields {
readingTime {
text
minutes
time
words
}
@disintegrator
disintegrator / debounce.go
Created December 23, 2021 18:52
A debouncer that sends pulses on a channel (Golang, Go)
package debounce
import (
"context"
"errors"
"fmt"
"sync"
"time"
)
@disintegrator
disintegrator / TypeHolesInTS.md
Last active November 3, 2021 02:45
Type holes in TypeScript

Type holes in TypeScript

In TypeScript there are a few ways you can sidestep type inference and the compiler to introduce type holes in your code. Type holes are parts of the code where we’ve lied or hid information from the compiler and can be a source of bugs that are not present in properly typed code. The common ones I see are listed below in order of really bad to bad.

Type assertions

const something = getValue() as any;
const cat = dog as Cat;