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/$%7Burl%7D?q=function&page=2330&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 28562 results for "function"(6151ms)

Snake_gamemain.tsx4 matches

@ilianp•Updated 6 months ago
8const INITIAL_FOOD = { x: 15, y: 15 };
9
10// Helper function to check if two directions are opposite
11const isOppositeDirection = (dir1, dir2) => {
12 const oppositeMap = {
19};
20
21function SnakeGame() {
22 const [snake, setSnake] = useState(INITIAL_SNAKE);
23 const [food, setFood] = useState(INITIAL_FOOD);
211}
212
213function client() {
214 createRoot(document.getElementById("root")).render(<SnakeGame />);
215}
216if (typeof document !== "undefined") { client(); }
217
218export default async function server(request: Request): Promise<Response> {
219 return new Response(`
220 <html>

switchExtractormain.tsx2 matches

@temptemp•Updated 6 months ago
12const dataChart: { variable: string; value: number }[][] = [];
13
14function getValueOf(text: string): number {
15 const pattern = new RegExp(`,${text}=0x([a-zA-Z0-9]+)`, "g");
16 const match = pattern.exec(str);
40 }
41};
42export function solve(p: Array<any> | string) {
43 if (Array.isArray(p)) {
44 return p;

scraper_templateREADME.md1 match

@dkinzer222•Updated 6 months ago
133. Adjust the if statement to detect changes and update your blob
14
154. Craft a message to be sent with `sendNotification()` function

sqlitemain.tsx5 matches

@dkinzer222•Updated 6 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
48}
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
62}
63
64function createResError(body: string) {
65 try {
66 const e = zLibsqlError.parse(JSON.parse(body));
113 *
114 * The types are currently shown for types declared in a SQL table. For
115 * column types of function calls, for example, an empty string is
116 * returned.
117 */

jsonpubmain.tsx31 matches

@yawnxyz•Updated 6 months ago
336 const room = db.joinRoom('editor', 'main');
337
338 // Add jq processing functions
339 async function jqFilter(input, filter) {
340 try {
341 const jsonString = typeof input === 'string' ? input : JSON.stringify(input);
349
350 // Add jq filter input with enter key handler
351 $('#jq-filter').on('keypress', async function(e) {
352 if (e.which === 13) { // Enter key
353 e.preventDefault();
400 document.body.appendChild(cursorContainer);
401
402 function updateCursor(e) {
403 const cursor = {
404 x: e.clientX,
411 }
412
413 function createCursorElement(peerId, cursor) {
414 let el = document.getElementById('cursor-' + peerId);
415 if (!el) {
428 }
429
430 function removeCursor(peerId) {
431 const el = document.getElementById('cursor-' + peerId);
432 if (el) el.remove();
433 }
434
435 $(function() {
436 // Track cursor movement
437 document.addEventListener('mousemove', throttle(updateCursor, 50));
484 });
485
486 function saveJsonDoc(content, isNew = false) {
487 if (!content) return;
488
520 }, 500);
521
522 $('#json-input').bind('input', function() {
523 const inputData = $(this).val();
524 debouncedSave(inputData, !currentDocId);
525 });
526
527 function updateDocsList(docs) {
528 const $list = $('#docs-list');
529 $list.empty();
573 });
574
575 // Resizer functionality
576 const $resizer = $("#resizer");
577 const $jsonInput = $("#json-input");
588 let isResizing = false;
589
590 $resizer.on("mousedown", function() {
591 isResizing = true;
592 $("body").css("cursor", "ew-resize");
593 });
594
595 $(document).on("mousemove", function(e) {
596 if (!isResizing) return;
597 const totalWidth = $("body").width();
604 });
605
606 $(document).on("mouseup", function() {
607 if (isResizing) {
608 isResizing = false;
644
645 // Add click handler for Apply jq button
646 $('#apply-jq').on('click', async function() {
647 const filter = $('#jq-filter').val().trim();
648 const rawInput = $('#json-input').val().trim();
665 });
666
667 // Add XML to JSON conversion function
668 function parseXmlToJson(xml) {
669 // If this is the document node, get the root element
670 if (xml.nodeType === 9) { // DOCUMENT_NODE
721 }
722
723 // Add these helper functions before detectInputFormat
724
725
726 // Modify detectInputFormat function
727 function detectInputFormat(input) {
728
729 // Rest of your existing format detection code...
791
792 // Update createJsonView to show filter info
793 function createJsonView(json, parent, depth = 0, meta = {}) {
794 if (depth === 0) {
795 if (meta.compressed) {
848 parent.append(element);
849
850 toggle.on("click", function() {
851 $(this).parent().toggleClass("collapsed");
852 });
882 }
883
884 // Add this function near other utility functions
885 async function applyJqFilter(rawInput, filter) {
886 if (!rawInput) {
887 $("#json-view").empty();
914
915 // Modify updateJsonView to use the jq filter if present
916 async function updateJsonView() {
917 const rawInput = $("#json-input").val()?.trim() || '';
918 const filter = $("#jq-filter").val()?.trim();
958
959 // Modify the document ready section to include jq filter changes
960 $(document).ready(function() {
961 const jsonInput = $("#json-input");
962 const jqFilter = $("#jq-filter");
977 });
978
979 // Utility function to throttle cursor updates
980 function throttle(func, limit) {
981 let inThrottle;
982 return function(...args) {
983 if (!inThrottle) {
984 func.apply(this, args);
990
991 // Add debounce utility
992 function debounce(func, wait) {
993 let timeout;
994 return function executedFunction(...args) {
995 const later = () => {
996 clearTimeout(timeout);

telegramWebhookEchoMessagemain.tsx17 matches

@dcm31•Updated 6 months ago
47};
48
49async function handleMessage(message) {
50 const userMessage = message.text;
51 const chatId = message.chat.id;
62}
63
64async function processUserInputWithAI(userMessage: string, tasks: Task[], state: UserState): Promise<{ response: string, updatedTasks: Task[], updatedState: UserState, suggestedActions: string[] }> {
65 const taskListString = JSON.stringify(tasks);
66 const stateString = JSON.stringify(state);
78 Based on the user's message and the conversation context, determine the appropriate action to take and execute it.
79 Be proactive in guiding the user through their tasks, focusing on prioritization and breaking down tasks into microsteps.
80 You can use the following functions:
81 - addTask(tasks: Task[], title: string): Adds a new task
82 - markTaskAsDone(tasks: Task[], taskId: string): Marks a task as done
138}
139
140function addTask(tasks: Task[], title: string) {
141 const newTask: Task = {
142 id: Date.now().toString(),
150}
151
152function markTaskAsDone(tasks: Task[], taskId: string) {
153 const task = findTask(tasks, taskId);
154 if (task) {
157}
158
159function breakDownTask(tasks: Task[], taskId: string, subtasks: string[]) {
160 const task = findTask(tasks, taskId);
161 if (task) {
175}
176
177function findTask(tasks: Task[], taskId: string): Task | null {
178 return tasks.find(task => task.id === taskId) || null;
179}
180
181function compareTaskPriorities(tasks: Task[], taskId1: string, taskId2: string) {
182 const task1 = findTask(tasks, taskId1);
183 const task2 = findTask(tasks, taskId2);
191}
192
193function suggestMicrosteps(taskTitle: string): string[] {
194 // This function would ideally use AI to generate suggestions, but for simplicity, we'll return static suggestions
195 return ["Get materials", "Prepare workspace", "Start first step"];
196}
197
198function navigateTaskHierarchy(tasks: Task[], currentTaskId: string | null, direction: 'up' | 'down' | 'next' | 'prev'): string | null {
199 if (!currentTaskId) return null;
200 const currentTask = findTask(tasks, currentTaskId);
217}
218
219function generateTaskList(tasks: Task[], showCompleted: boolean, parentId: string | null = null, indent = ''): string {
220 let list = '';
221 const currentLevelTasks = tasks.filter(task => task.parent_id === parentId && (showCompleted || !task.done));
231}
232
233async function sendResponse(chatId: number, message: string, suggestedActions: string[]) {
234 const keyboard = [
235 ...suggestedActions.map(action => [{ text: action }]),
254}
255
256async function getTasks(chatId: number): Promise<Task[]> {
257 const key = `tasks_${chatId}`;
258 try {
265}
266
267async function updateTasks(chatId: number, tasks: Task[]) {
268 const key = `tasks_${chatId}`;
269 try {
274}
275
276async function getUserState(chatId: number): Promise<UserState> {
277 const key = `state_${chatId}`;
278 try {
285}
286
287async function updateUserState(chatId: number, state: UserState) {
288 const key = `state_${chatId}`;
289 try {

firehosemain.tsx3 matches

@stevekrouse•Updated 6 months ago
9const agent = new AtpAgent({ service });
10
11function App() {
12 const [messages, setMessages] = useState([]);
13 const [isActive, setIsActive] = useState(true);
213}
214
215function client() {
216 createRoot(document.getElementById("root")).render(<App />);
217}
221}
222
223export default async function server(request: Request): Promise<Response> {
224 return new Response(
225 `

blob_adminmain.tsx9 matches

@steveVT•Updated 6 months ago
12}
13
14function Tooltip({ children, content }: TooltipProps) {
15 const [isVisible, setIsVisible] = useState(false);
16 const tooltipRef = useRef<HTMLDivElement>(null);
51}
52
53function formatBytes(bytes, decimals = 2) {
54 if (bytes === 0) return "0 Bytes";
55 const k = 1024;
60}
61
62function copyToClipboard(text) {
63 navigator.clipboard.writeText(text).then(() => {
64 console.log("Text copied to clipboard");
68}
69
70function ActionMenu({ blob, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
71 const [isOpen, setIsOpen] = useState(false);
72 const menuRef = useRef(null);
75
76 useEffect(() => {
77 function handleClickOutside(event) {
78 if (menuRef.current && !menuRef.current.contains(event.target)) {
79 event.stopPropagation();
157}
158
159function BlobItem({ blob, onSelect, isSelected, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
160 const [isLoading, setIsLoading] = useState(false);
161 const decodedKey = decodeURIComponent(blob.key);
218}
219
220function App({ initialEmail, initialProfile }) {
221 const encodeKey = (key: string) => encodeURIComponent(key);
222 const decodeKey = (key: string) => decodeURIComponent(key);
644}
645
646function client() {
647 const initialEmail = document.getElementById("root").getAttribute("data-email");
648 const initialProfile = JSON.parse(document.getElementById("root").getAttribute("data-profile"));
654if (typeof document !== "undefined") { client(); }
655
656export default lastlogin(async function handler(request: Request): Promise<Response> {
657 if (request.method === "GET" && request.url.includes("/api/public/")) {
658 const url = new URL(request.url);

chatgptchessmain.tsx4 matches

@tmcw•Updated 6 months ago
42 let game = new Chess(position)
43
44 function onDragStart(source, piece, position, orientation) {
45 // do not pick up pieces if the game is over
46 if (game.isGameOver()) return false
55 }
56
57 function onDrop(source: string, target: string) {
58 // see if the move is legal
59 try {
86 // update the board position after the piece snap
87 // for castling, en passant, pawn promotion
88 function onSnapEnd() {
89 board.position(game.fen())
90 }
91
92 function updateStatus() {
93 var status = ""
94

workersmain.tsx4 matches

@temptemp•Updated 6 months ago
20};
21
22async function uuidGen() {
23 const randomBytes = CryptoJS.lib.WordArray.random(16);
24 let hex = randomBytes.toString(CryptoJS.enc.Hex);
27 return hex;
28}
29export async function boundGen() {
30 const randomBytes = CryptoJS.lib.WordArray.random(16);
31 const hex = randomBytes.toString(CryptoJS.enc.Hex);
33 return boundary;
34}
35async function formDataGen(files: File[]) {
36 const boundary = await boundGen();
37 let body = "";
57 };
58}
59async function upload(formData: any, user: string) {
60 const _ = await fetch("https://workers.cloudflare.com/playground/api/worker", {
61 "headers": {

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 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.