Skip to content

Instantly share code, notes, and snippets.

View disintegrator's full-sized avatar

Georges Haidar disintegrator

View GitHub Profile
@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 / 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 / typescriptreact.json
Created December 18, 2020 10:11
VS Code snippets
{
"React function component": {
"prefix": "nrf",
"body": [
"import * as React from \"react\";",
"",
"export interface ${1:$TM_FILENAME_BASE}Props {}",
"",
"const ${1:$TM_FILENAME_BASE}: React.FC<${1:$TM_FILENAME_BASE}Props> = props => {",
" return <>{props.children}</>;",
@disintegrator
disintegrator / example_1.html
Created December 11, 2020 15:11
Having Fun with Markdown and Remark
<h1>I am a level 1 heading</h1>
<p class="subtitle subtitle--1">I am a level 1 subtitle</p>
<p class="subtitle subtitle--2">I am a level 2 subtitle</p>
<p class="subtitle subtitle--6">
Up to six levels are supported corresponding to heading levels
</p>
@disintegrator
disintegrator / pino.d.ts
Created September 24, 2020 12:53
An example TypeScript declaration file that demonstrates how to augment the type definitions of a third party library.
import "pino";
declare module "pino" {
interface LoggerOptions {
// @types/pino does not currently expose this option
nestedKey?: string;
}
}
@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
}