This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Uses various heurisitics to determine if an error is a connection error. | |
*/ | |
export function isConnectionError(err: unknown): boolean { | |
if (typeof err !== "object" || err == null) { | |
return false; | |
} | |
// Covers fetch in Deno as well | |
const isBrowserErr = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chromium bug: https://issues.chromium.org/issues/40450316 | |
const headers = new Headers(); | |
headers.set("user-agent", "fancy/1.0"); | |
console.log(headers.get("user-agent") == null); | |
// Prints: false | |
const req = new Request(''); | |
req.headers.set("user-agent", "fancy/1.0"); | |
console.log(req.headers.get("user-agent") == null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function tryParseURL(input: unknown): URL | null { | |
if (input instanceof URL) { | |
return input; | |
} | |
if (typeof input !== "string") { | |
return null; | |
} | |
try { | |
return new URL(input); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package log | |
import ( | |
"context" | |
"log/slog" | |
) | |
// A DiscardHandler discards all log records. | |
type DiscardHandler struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"runtime" | |
) | |
func Assert(group string, pairs ...any) error { | |
if len(pairs)%2 != 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logGroup(label: string) { | |
console.group(label) | |
return { | |
[Symbol.dispose]: () => { | |
console.groupEnd() | |
} | |
} | |
} | |
function demo() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package functional | |
import ( | |
"context" | |
"errors" | |
"time" | |
"github.com/benthosdev/benthos/v4/public/service" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package debounce | |
import ( | |
"context" | |
"errors" | |
"fmt" | |
"sync" | |
"time" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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}</>;", |
NewerOlder