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/$%7Bsuccess?q=function&page=2461&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 28542 results for "function"(6382ms)

darkMagentaFlamingoREADME.md1 match

@jamisonlUpdated 9 months ago
1Bot for Cama discord server. To initialize new slash commands, you have to run a separate bit of code. This is for modifying their functionality

convenientAzureSparrowmain.tsx2 matches

@gioUpdated 9 months ago
4const apiKey = "your_api_key";
5
6// Function to send SMS
7async function sendSMS(to, from) {
8 try {
9 const response = await axios.post(

numbergamemain.tsx4 matches

@tnorthcuttUpdated 9 months ago
27const HUE_DIFF = 25;
28
29function getColor(value: number): string {
30 const power = Math.log2(value / 2);
31 const hue = (power * HUE_DIFF) % 360;
33}
34
35function App() {
36 const [board, setBoard] = useState<number[][]>([]);
37 const [selectedCells, setSelectedCells] = useState<[number, number][]>([]);
281}
282
283function client() {
284 createRoot(document.getElementById("root")).render(<App />);
285}
289}
290
291async function server(request: Request): Promise<Response> {
292 return new Response(
293 `

easingbattlegroundmain.tsx23 matches

@ejfoxUpdated 9 months ago
4import { BrowserRouter as Router, Route, Link, Routes } from "https://esm.sh/react-router-dom";
5
6function EasingVisualizer({ easing }) {
7 const canvasRef = React.useRef(null);
8
13 const height = canvas.height;
14
15 function drawCurve() {
16 ctx.clearRect(0, 0, width, height);
17
18 const [x1, y1, x2, y2] = easing.params;
19
20 const bezierFunction = cubicBezier(x1, y1, x2, y2);
21
22 ctx.beginPath();
23 ctx.moveTo(0, height);
24 for (let t = 0; t <= 1; t += 0.01) {
25 const point = bezierFunction(t);
26 const x = point.x * width;
27 const y = height - point.y * height;
34 // Animate the dot
35 const time = (Date.now() % 3000) / 3000;
36 const point = bezierFunction(time);
37 const x = point.x * width;
38 const y = height - point.y * height;
44 }
45
46 const animationFrame = requestAnimationFrame(function animate() {
47 drawCurve();
48 requestAnimationFrame(animate);
55}
56
57function cubicBezier(x1, y1, x2, y2) {
58 return function(t) {
59 const cx = 3 * x1;
60 const bx = 3 * (x2 - x1) - cx;
72}
73
74function EasingGuide() {
75 return (
76 <div className="bg-gray-100 p-6 rounded-lg mb-8">
92 <h3 className="text-xl font-semibold mb-2">🧙‍♂️ Cubic-Bezier Magic:</h3>
93 <p className="mb-4">
94 Input your easing as a cubic-bezier function, like this:
95 <code className="bg-gray-200 px-2 py-1 rounded">cubic-bezier(0.05, 0.00, 0.16, 0.13)</code>
96 </p>
104}
105
106function EasingForm({ onSubmit }) {
107 const [newEasing, setNewEasing] = useState({ name: '', author: '', params: [0.05, 0.00, 0.16, 0.13] });
108
109 function handleSubmit(e) {
110 e.preventDefault();
111 onSubmit(newEasing);
113 }
114
115 function handleCubicBezierInput(e) {
116 const value = e.target.value;
117 const match = value.match(/cubic-bezier\(([\d.]+),\s*([\d.]+),\s*([\d.]+),\s*([\d.]+)\)/);
125 <form onSubmit={handleSubmit} className="mb-8">
126 <div className="mb-4">
127 <label htmlFor="easingInput" className="block mb-2 font-semibold">Easing Function (cubic-bezier format):</label>
128 <input
129 id="easingInput"
163}
164
165function Leaderboard({ easings, onVote, votedEasings }) {
166 return (
167 <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
184}
185
186function Home({ easings, onSubmit, onVote, votedEasings }) {
187 return (
188 <div>
200}
201
202function FullLeaderboard({ easings, onVote, votedEasings }) {
203 return (
204 <div>
214}
215
216function App() {
217 const [easings, setEasings] = useState([]);
218 const [votedEasings, setVotedEasings] = useState([]);
222 }, []);
223
224 async function fetchEasings() {
225 const response = await fetch('/easings');
226 const data = await response.json();
228 }
229
230 async function submitEasing(newEasing) {
231 await fetch('/easings', {
232 method: 'POST',
237 }
238
239 async function vote(id, direction) {
240 await fetch(`/vote/${id}/${direction}`, { method: 'POST' });
241 setVotedEasings([...votedEasings, id]);
256}
257
258function client() {
259 createRoot(document.getElementById("root")).render(<App />);
260}
264}
265
266async function server(request: Request): Promise<Response> {
267 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
268 const SCHEMA_VERSION = 1

ChatGPTTextDefinitionUserscriptmain.tsx13 matches

@xsecUpdated 9 months ago
11// ==/UserScript==
12
13(function() {
14 "use strict";
15
71 };
72
73 // Run the function when the page loads
74 window.addEventListener("load", () => {
75 console.log("Page loaded, running toggleStylesBasedOnWidth");
77 });
78
79 // Also run the function when the window is resized
80 window.addEventListener("resize", () => {
81 console.log("Window resized, running toggleStylesBasedOnWidth");
201
202 // Stream processing
203 async function* streamProcessor(reader) {
204 const decoder = new TextDecoder();
205 let buffer = "";
237
238 // API response handling
239 async function processApiResponse(response) {
240 const reader = response.body.getReader();
241
253
254 // Selection handling
255 async function handleSelection() {
256 console.time("handleSelection");
257 const selectedText = getSelectedText();
291 }
292
293 // Helper functions
294 function getSelectedText() {
295 return window.getSelection().toString().trim();
296 }
343 };
344
345 // Function to create a new section and append it properly
346 const showLoadingPopup = (selectedText) => {
347 const popup = createPopup();
362 };
363
364 function clearPreviousPopup() {
365 const previousPopup = document.getElementById("definition-popup");
366 if (previousPopup) {
427 };
428
429 function createCloseButton() {
430 console.log("Creating close button");
431
463 }
464
465 async function makeApiRequest(text) {
466 console.log(`Preparing to send fetch request for text: "${text}"`);
467 try {
482 }
483
484 // Pure functions to calculate dimensions and positioning
485 const calculateCharacterSize = () => {
486 const tempElement = document.createElement("span");

chatREADME.md1 match

@xsecUpdated 9 months ago
1# OpenAI ChatGPT helper function
2
3This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.

chatmain.tsx3 matches

@xsecUpdated 9 months ago
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
2
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
14/**
15 * Initiates a chat conversation with OpenAI's GPT model and retrieves the content of the first response.
16 * This function can handle both single string inputs and arrays of message objects.
17 * It supports various GPT models, allowing for flexibility in choosing the model based on the application's needs.
18 *
21 * @returns {Promise<string>} A promise that resolves to the content of the first response from the completion.
22 */
23export async function chat(
24 input: string | Message[],
25 options?: Omit<ChatCompletionCreateParamsNonStreaming, "messages">,

caniuse_notifiermain.tsx2 matches

@stevekrouseUpdated 9 months ago
7const dataKey = "caniuse-data";
8
9function Feature({ feature }: any) {
10 const links = feature.links ?? [];
11 return (
27}
28
29export default async function(interval: Interval) {
30 const previousDataUpdatedAt = await blob.getJSON(updatedKey) ?? 0;
31 const previousData = await blob.getJSON(dataKey);

clickTrackerWebsitemain.tsx3 matches

@ankitkr0Updated 9 months ago
7import confetti from 'https://esm.sh/canvas-confetti';
8
9function App() {
10 const [clicks, setClicks] = useState(0);
11
49}
50
51function client() {
52 createRoot(document.getElementById("root")).render(<App />);
53}
55if (typeof document !== "undefined") { client(); }
56
57async function server(request: Request): Promise<Response> {
58 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
59 const SCHEMA_VERSION = 2

lucia_sqlitemain.tsx5 matches

@yawnxyzUpdated 9 months ago
4import { generateId, Scrypt } from "npm:lucia";
5
6export async function createTables(userTable: string, sessionTable: string) {
7 return sqlite.batch([
8 `CREATE TABLE ${userTable} (
22}
23
24async function safeExecute({ userTable, sessionTable, query, error }: {
25 userTable: string;
26 sessionTable: string;
40}
41
42export async function createUser({ userTable, sessionTable, username, password, github_id, google_id }: {
43 userTable: string;
44 sessionTable: string;
65}
66
67export async function getUser(
68 { userTable, sessionTable, username, github_id, google_id }: {
69 userTable: string;
98}
99
100export async function verifyPassword(hashed_password: string, password: string): Promise<boolean> {
101 return new Scrypt().verify(hashed_password, password);
102}

getFileEmail4 file matches

@shouserUpdated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblkUpdated 1 month ago
Simple functional CSS library for Val Town
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.