Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=741&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 7802 results for "function"(457ms)

react_client_forkmain.tsx3 matches

@charmaine•Updated 3 months ago
4import { blob } from "https://esm.town/v/std/blob?v=10";
5
6function App({ initialTodos }: { initialTodos: { text: string; }[]; }) {
7 const [todos, setTodos] = useState<{ text: string; }[]>(Array.isArray(initialTodos) ? initialTodos : []);
8 const [newTodo, setNewTodo] = useState("");
109}
110
111function client() {
112 const fetchTodos = async () => {
113 const response = await fetch('/todos');
123if (typeof document !== "undefined") { client(); }
124
125export default async function server(request: Request) {
126 if (request.method === 'POST' && request.url.endsWith('/add-todo')) {
127 const body = await request.json();

valTownInspoListmain.tsx1 match

@charmaine•Updated 3 months ago
119}, {
120 "title": "Generate PDFs",
121 "description": "Generate PDFs using val functions by using an external library like jsPDF",
122 "val": "@vtdocs.examplePDF",
123 image:

vbloghono-adapter6 matches

@jxnblk•Updated 3 months ago
7const app = new Hono();
8
9function Style() {
10 return <style>{`body{margin:0;padding:32px;font-family:Menlo, monospace}`}</style>;
11}
12
13function Home(data: Data, c: Context) {
14 return (
15 <div>
29}
30
31function Post(data: Data, c: Context) {
32 const name = c.req.param("post");
33 const post = data.posts.find(p => p.name === name);
46}
47
48function NotFound(data: Data, c: Context) {
49 const name = c.req.param("post");
50 return (
59type RouteComponent = (data: Data, context: Context<any, any, {}>) => JSX.Element;
60
61function route(Component: RouteComponent, data: Data) {
62 return async (c) => c.html(Component(data, c));
63}
64
65export default function honoAdapter(data: Data) {
66 app.get("/", route(Home, data));
67 app.get("/posts/:post", route(Post, data));

vblogdata1 match

@jxnblk•Updated 3 months ago
4import { parse } from "./parse";
5
6async function getData() {
7 const src = await getPosts();
8 const posts = await Promise.all(src.map((p) => parse(p, [frontmatter, markdown])));

surprisingEmbeddingsindex4 matches

@tmcw•Updated 3 months ago
13const THROTTLE = 1000
14
15function blockAi(ua: string) {
16 if (
17 bots.some(b => {
92
93// Based on https://github.com/Shawns2759/vector-similarity MIT
94function dotProduct(a: number[], b: number[]): number {
95 return a.reduce((sum, value, index) => sum + value * b[index], 0)
96}
97
98function vectorMagnitude(a: number[]): number {
99 return Math.sqrt(a.reduce((sum, value) => sum + value * value, 0))
100}
101
102function cosineSimilarity(a: number[], b: number[]): number {
103 const dotProd = dotProduct(a, b)
104 const magnitudeA = vectorMagnitude(a)

OpenTownieindex4 matches

@shouser•Updated 3 months ago
5import { generateCodeAnthropic, makeFullPrompt } from "./backend/generateCode";
6
7function App() {
8 const [messages, setMessages] = useState<{ content: string; role: string }[]>([]);
9 const [inputMessage, setInputMessage] = useState("make a todo app");
11 const [bearerToken, _setBearerToken] = useState(localStorage.getItem("val-town-bearer"));
12
13 function setBearerToken(token: string) {
14 _setBearerToken(token);
15 localStorage.setItem("val-town-bearer", token);
79}
80
81function client() {
82 createRoot(document.getElementById("root")).render(<App />);
83}
84if (typeof document !== "undefined") { client(); }
85
86export default async function server(req: Request): Promise<Response> {
87 // console.log(req);
88 if (req.method === "POST") {

OpenTowniegenerateCode2 matches

@shouser•Updated 3 months ago
1import OpenAI from "https://esm.sh/openai";
2
3function parseValResponse(response: string) {
4 const codeBlockRegex = /```val type=(\w+)\n([\s\S]*?)```/;
5 const match = response.match(codeBlockRegex);
25}
26
27export async function generateCodeAnthropic(messages: Message[]): Promise<ValResponse | null> {
28 const system = await (await fetch(`${import.meta.url.split("/").slice(0, -1).join("/")}/system_prompt.txt`)).text();
29

reactRouter7server.tsx1 match

@justbe•Updated 3 months ago
1import { handler } from "./entry.server.tsx";
2
3export default async function(request: Request) {
4 const url = new URL(request.url);
5 if (url.pathname == "/js/entry.client.js") {

reactRouter7about.tsx1 match

@justbe•Updated 3 months ago
4import type loader from "./about.loader.js";
5
6export default function About() {
7 let data = useLoaderData<typeof loader>();
8 return <h1>{data.message}</h1>;

userEnrichmenthome.tsx1 match

@justbe•Updated 3 months ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2
3export default function Home() {
4 return <h1>This is just a test!</h1>;
5}

getFileEmail4 file matches

@shouser•Updated 6 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago