Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<script>
window.startClerk = async () => {
function formRedirect(){
const form = '<form method="get" action="" name="redirect"></form>';
@JLarky
JLarky / 01_t3Env.ts
Last active May 3, 2023 03:41
This is @t3-oss/env-core but if you don't want to send zod to client bundle (be careful, it's for Astro, not Next.js) https://twitter.com/JLarky/status/1653595995744395264
// src/t3Env.ts
import { createEnv, LooseOptions, StrictOptions } from '@t3-oss/env-core';
import { z, ZodType, ZodString } from 'zod';
function validateEnv<
TPrefix extends string,
TServer extends Record<string, ZodType> = NonNullable<unknown>,
TClient extends Record<string, ZodType> = NonNullable<unknown>
>(opts: LooseOptions<TPrefix, TServer, TClient> | StrictOptions<TPrefix, TServer, TClient>) {
return opts;
@JLarky
JLarky / 01_ExampleUsage.astro
Created April 11, 2023 13:08
Playing with youtube facade based on vb/lazyframe
<LazyFrame
loading="lazy"
style={{
position: "absolute",
top: "0",
left: "0",
width: "100%",
height: "100%",
borderRadius: "10px",
}}
@JLarky
JLarky / 00_README.md
Last active March 26, 2023 18:08
Asking the same question different AI models
@JLarky
JLarky / index.astro
Created March 6, 2023 01:49
How to detect if the page is crawled by bot (Google Bot, Search Bot) in Astro (astro.build)
---
import isbot from "isbot";
const isBot = isbot(Astro.request.headers.get("User-Agent"));
console.log("isBot", isBot);
---
<h1>{isBot ? "bot" : "user"}</h1>
@JLarky
JLarky / README.md
Last active March 2, 2023 23:08
Quick and dirty GPT Tokenizer in one command

dev

deno run --watch --allow-net main.ts
curl -d 'test world :)' http://localhost:8085

prod

deno run --allow-net=0.0.0.0:8085 https://gist.githubusercontent.com/JLarky/6a77d9d483b7f0067fd3eea1b785e628/raw/3cf707ae447f8309564b94613a014f9ddf3f972d/main.ts

curl -d 'test world :)' http://localhost:8085

@JLarky
JLarky / 10kb.txt
Created February 20, 2023 01:06
both files when gzipped produce 1.5kb files https://twitter.com/alpinelogic1/status/1627465760334401538
bbbbbbaaaaaaabbaabaaabaabaaaaabbbbbabaaabaaababaaaabbbaabaababbaaaaabaabbababbaabaaaabaabbbaababbaabbaaabbaabaaabbbbbbaaababaabaaabbbabbbaababbaaaaaaaaabaabaaaaaaaaaaaabbbaaababaabaaabaaaaababaabaaaaabaaaaabaababababaaaababbbabbaababaaabbaaaaaabaaabaaaabaaaaabaabaaaaaababbabbaaaababaabbbaababaabaabaaaaabbbbaabbababaaaaabaabaabbaaabababaaaaabbbbbabaabaabbabaabaabaaaabaaaaabbaaaaabbbaabaabaaabaaabbbaabbbabbaaaaaaaabababbaaaabbaaabaaabababaaaaaabababaabaabbabbbaaabaaaaaabbaabbbabaabaaaaaaaaaaaaaaaabbaaaabaaaabaaaaaabbbaaabbabaaaaaaabbaaababaabaabaabaaaaaabbbaabbaabbaababaaabbbababaaaabbaaaaabbaaabaaaaaaaaabaabbbabaaaabbabaaaababbaaabbabaababbaabaababaabaaabbbbaaabaaaabbbbbaabbbaababbbaaababababbbabbbababbbaaabaaaabaababaaaabaabbabaaabbbaaabaabaababababaaaaaabbaabbaaaaabaaababaabaaababbaabbbaabbbbaaaaababaaaaaabaaaabaaababababaaaaaaababaaabaaababbaaaaaaabababbbabaabaabbbaababababaabbaabaaababaabbabbbaaaababbaaabbbabaaaaaabbabbababaaaaaabaaaaabaaaabaaaabaaaabaaabaaaaaaabbbababaaaabaaaaabaabaabbbabaaababaaabaaaaaba
@JLarky
JLarky / list files node.js
Last active February 6, 2023 18:26
how to list files in a folder in node.js https://sharegpt.com/c/RW0fYB3
async function listFiles(dir: string) {
try {
const { readdir } = await import('fs/promises');
const files = await readdir(dir);
console.log(files);
} catch (err) {
throw err;
}
}
console.log(await listFiles('.'));
// ~/Library/Application\ Support/Code/User/keybindings.json
// https://sharegpt.com/c/jZsUO6C
{
"key": "shift+z shift+z",
"command": "workbench.action.files.save",
"when": "editorTextFocus && amVim.mode == 'NORMAL'"
},
{
<template id="copy-button"><CopyButton /></template>
<script>
// https://www.roboleary.net/2022/01/13/copy-code-to-clipboard-blog.html
if (navigator.clipboard) {
let copyButton = document.querySelector("#copy-button") as HTMLTemplateElement;
let blocks = document.querySelectorAll("pre.astro-code");
blocks.forEach(block => {
let button = document.createElement("button");
const icon = copyButton.content.cloneNode(true);
button.appendChild(icon);