stevensDemogenerateFunFacts.ts8 matches
11* @returns Array of previous fun facts
12*/
13async function getPreviousFunFacts() {
14try {
15const result = await sqlite.execute(
32* @param dates Array of date strings in ISO format
33*/
34async function deleteExistingFunFacts(dates) {
35try {
36for (const date of dates) {
51* @param factText The fun fact text
52*/
53async function insertFunFact(date, factText) {
54try {
55await sqlite.execute(
75* @returns Array of generated fun facts
76*/
77async function generateFunFacts(previousFacts) {
78try {
79// Get API key from environment
197* @returns Array of parsed facts
198*/
199function parseFallbackFacts(responseText, expectedDates) {
200// Try to extract facts using regex
201const factPattern = /(\d{4}-\d{2}-\d{2})["']?[,:]?\s*["']?(.*?)["']?[,}]/gs;
260261/**
262* Main function to generate and store fun facts for the next 7 days
263*/
264export async function generateAndStoreFunFacts() {
265try {
266// Get previous fun facts
301* Intended to be used as a Val Town cron job
302*/
303export default async function() {
304console.log("Running fun facts generation cron job...");
305return await generateAndStoreFunFacts();
stevensDemo.cursorrules15 matches
8### 1. Script Vals
910- Basic JavaScript/TypeScript functions
11- Can be imported by other vals
12- Example structure:
1314```typescript
15export function myFunction() {
16// Your code here
17}
2526```typescript
27export default async function (req: Request) {
28return new Response("Hello World");
29}
3738```typescript
39export default async function () {
40// Scheduled task code
41}
4950```typescript
51export default async function (email: Email) {
52// Process email
53}
5758- Ask clarifying questions when requirements are ambiguous
59- Provide complete, functional solutions rather than skeleton implementations
60- Test your logic against edge cases before presenting the final solution
61- Ensure all code follows Val Town's specific platform requirements
70- **Never bake in secrets into the code** - always use environment variables
71- Include comments explaining complex logic (avoid commenting obvious operations)
72- Follow modern ES6+ conventions and functional programming practices if possible
7374## Val Town Standard Libraries
7576Val Town provides several hosted services and utility functions.
7778### Blob Storage
124```
125126## Val Town Utility Functions
127128Val Town provides several utility functions to help with common project tasks.
129130### Importing Utilities
176{
177name: "should add numbers correctly",
178function: () => {
179expect(1 + 1).toBe(2);
180},
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
213โ โ โโโ README.md
214โ โโโ index.ts # Main entry point
226โโโ shared/
227โโโ README.md
228โโโ utils.ts # Shared types and functions
229```
230232- Hono is the recommended API framework (similar to Express, Flask, or Sinatra)
233- Main entry point should be `backend/index.ts`
234- **Static asset serving:** Use the utility functions to read and serve project files:
235```ts
236// Use the serveFile utility to handle content types automatically
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
275- Export clear query functions with proper TypeScript typing
276- Follow the queries and migrations pattern from the example
277
stevensDemocronDailyBrief.ts1 match
1import { sendDailyBriefing } from "./sendDailyBrief.ts";
23export async function cronDailyBrief() {
4try {
5const chatId = Deno.env.get("TELEGRAM_CHAT_ID");
stevensDemoApp.tsx2 matches
62};
6364export function App() {
65const [memories, setMemories] = useState<Memory[]>([]);
66const [loading, setLoading] = useState(true);
139const data = await response.json();
140141// Change the sorting function to show memories in chronological order
142const sortedMemories = [...data].sort((a, b) => {
143const dateA = a.createdDate || 0;
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
23export function TownieIcon({
4size = 24,
5color = "currentColor",
50}
5152export function Circle ({
53filled,
54}: {
74}
7576export function Square ({
77size = 24,
78}: {
9899// icons from https://lucide.dev
100export function SquarePenIcon () {
101return (
102<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-square-pen-icon lucide-square-pen"><path d="M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"/></svg>
104}
105106export function FileCode2Icon () {
107return (
108<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-file-code2-icon lucide-file-code-2"><path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="m5 12-3 3 3 3"/><path d="m9 18 3-3-3-3"/></svg>
110}
111112export function SparklesIcon () {
113return (
114<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-sparkles-icon lucide-sparkles"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/><path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/></svg>
116}
117118export function EyeIcon () {
119return (
120<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-eye-icon lucide-eye"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>
122}
123124export function ExternalLinkIcon () {
125return (
126<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-external-link-icon lucide-external-link"><path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/></svg>
128}
129130export function KeyRoundIcon () {
131return (
132<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-key-round-icon lucide-key-round"><path d="M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z"/><circle cx="16.5" cy="7.5" r=".5" fill="currentColor"/></svg>
134}
135136export function LockKeyholeIcon () {
137return (
138<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-lock-keyhole-icon lucide-lock-keyhole"><circle cx="12" cy="16" r="1"/><rect x="3" y="10" width="18" height="12" rx="2"/><path d="M7 10V7a5 5 0 0 1 10 0v3"/></svg>
140}
141142export function PlusIcon () {
143return (
144<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-plus-icon lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
146}
147148export function ArrowUpIcon () {
149return (
150<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-arrow-up-icon lucide-arrow-up"><path d="m5 12 7-7 7 7"/><path d="M12 19V5"/></svg>
152}
153154export function RefreshIcon ({ size = 24 }: { size: number }) {
155return (
156<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-rotate-cw-icon lucide-rotate-cw"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></svg>
158}
159160export function XIcon ({ size = 24 }: {
161size?: number;
162}) {
166}
167168export function VolumeOffIcon ({ size = 24 }) {
169return (
170<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-volume-off-icon lucide-volume-off"><path d="M16 9a5 5 0 0 1 .95 2.293"/><path d="M19.364 5.636a9 9 0 0 1 1.889 9.96"/><path d="m2 2 20 20"/><path d="m7 7-.587.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298V11"/><path d="M9.828 4.172A.686.686 0 0 1 11 4.657v.686"/></svg>
172}
173174export function Volume2Icon ({ size = 24 }) {
175return (
176<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="lucide lucide-volume2-icon lucide-volume-2"><path d="M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z"/><path d="M16 9a5 5 0 0 1 0 6"/><path d="M19.364 18.364a9 9 0 0 0 0-12.728"/></svg>
untitled-5703README.md1 match
19โ โโโ database/
20โ โ โโโ migrations.ts # Schema definitions
21โ โ โโโ queries.ts # DB query functions
22โ โโโ index.ts # Main API entry point
23โโโ frontend/
hdindex.html3 matches
1export default function(req) {
2return new Response(
3`<!DOCTYPE html>
421422<script>
423document.addEventListener('DOMContentLoaded', function() {
424const faqQuestions = document.querySelectorAll('.faq-question');
425
426faqQuestions.forEach(question => {
427question.addEventListener('click', function() {
428const faqItem = this.parentElement;
429const isActive = faqItem.classList.contains('active');
test-multiembedt.tsx2 matches
7"Accept-Language": "en-US,en;q=0.9"
8};
9export default async function(req: Request): Promise<Response> {
10const API_URL: string = "https://api.val.town";
11async function proxiedFetch(input: string | URL, requestInit?: RequestInit) {
12let query = new URLSearchParams({
13url: input.toString(),
untitled-5703index.js21 matches
5657// Tab switching
58function switchTab(tabName) {
59// Update active tab
60state.activeTab = tabName;
8586// Authentication
87function login() {
88const username = elements.usernameInput.value.trim();
89if (username) {
99}
100101function logout() {
102state.currentUsername = '';
103localStorage.removeItem('username');
110}
111112function updateAuthUI() {
113if (state.currentUsername) {
114elements.loginSection.classList.add('hidden');
131}
132133// Jobs functionality
134async function fetchJobs() {
135try {
136const response = await fetch('/api/jobs');
145}
146147function renderJobs() {
148if (state.jobs.length === 0) {
149elements.jobsList.innerHTML = '<p class="text-gray-500">No jobs available. Be the first to post one!</p>';
168}
169170async function submitJob(event) {
171event.preventDefault();
172
221}
222223// Chat functionality
224function enableChat() {
225elements.chatInput.disabled = false;
226elements.sendMessageButton.disabled = false;
228}
229230function disableChat() {
231elements.chatInput.disabled = true;
232elements.sendMessageButton.disabled = true;
234}
235236async function fetchMessages() {
237try {
238const response = await fetch('/api/messages');
253}
254255function renderMessages() {
256if (state.messages.length === 0) {
257elements.chatMessages.innerHTML = '<p class="text-center text-gray-500">No messages yet. Start the conversation!</p>';
278}
279280function scrollChatToBottom() {
281elements.chatMessages.scrollTop = elements.chatMessages.scrollHeight;
282}
283284async function sendMessage() {
285const content = elements.chatInput.value.trim();
286if (!content || !state.currentUsername) return;
313}
314315// Utility functions
316function formatDate(dateString) {
317const date = new Date(dateString);
318return date.toLocaleString();
319}
320321function escapeHtml(unsafe) {
322return unsafe
323.replace(/&/g, "&")
329330// Setup polling for chat messages
331function setupMessagePolling() {
332// Initial fetch
333fetchMessages();
338339// Event listeners
340function setupEventListeners() {
341// Tab switching
342elements.jobsTab.addEventListener('click', () => switchTab('jobs'));
362363// Initialize the app
364function init() {
365// Setup event listeners
366setupEventListeners();
untitled-5703queries.ts5 matches
3233// Job queries
34export async function getAllJobs(): Promise<Job[]> {
35const result = await sqlite.execute(
36`SELECT * FROM ${JOBS_TABLE} ORDER BY created_at DESC`
39}
4041export async function getJob(id: number): Promise<Job | null> {
42const result = await sqlite.execute(
43`SELECT * FROM ${JOBS_TABLE} WHERE id = ?`,
47}
4849export async function createJob(job: JobInput): Promise<Job> {
50const created_at = new Date().toISOString();
51const result = await sqlite.execute(
5960// Message queries
61export async function getMessages(limit = 50): Promise<Message[]> {
62const result = await sqlite.execute(
63`SELECT * FROM ${MESSAGES_TABLE} ORDER BY created_at DESC LIMIT ?`,
67}
6869export async function createMessage(message: MessageInput): Promise<Message> {
70const created_at = new Date().toISOString();
71const result = await sqlite.execute(