Leaderboard
Prompts
Review this Python function and identify all issues: ```python def get_cat_ages(cats): ages = [] for i in range(len(cats)): if cats[i]["age"] > 0: ages.append(cats[i]["age"]) else: ages.append("unknown") return sum(ages) / len(ages) ``` List each bug, explain why it's a problem, and provide a corrected version.
Review this JavaScript code for a rate limiter and identify bugs, race conditions, and design issues: ```javascript class RateLimiter { constructor(maxRequests, windowMs) { this.requests = []; this.maxRequests = maxRequests; this.windowMs = windowMs; } async allowRequest() { const now = Date.now(); this.requests = this.requests.filter(t => now - t < this.windowMs); if (this.requests.length < this.maxRequests) { this.requests.push(now); return true; } return false; } } ``` Consider correctness, performance at scale, and production readiness.
This SQL query is slow on a table with 50M rows. Explain why and suggest improvements: ```sql SELECT u.name, COUNT(*) as post_count FROM users u LEFT JOIN posts p ON u.id = p.user_id WHERE p.created_at > NOW() - INTERVAL '30 days' OR p.created_at IS NULL GROUP BY u.name HAVING COUNT(*) > 0 ORDER BY post_count DESC LIMIT 20; ``` The table has indexes on `users.id` and `posts.user_id`.
A junior developer wrote this cat feeding scheduler. Review it kindly but thoroughly — identify issues and suggest improvements while being encouraging: ```python import time import datetime feeding_times = ["8:00", "12:00", "18:00"] def check_feeding(): while True: now = str(datetime.datetime.now().hour) + ":" + str(datetime.datetime.now().minute).zfill(2) if now in feeding_times: print("FEED THE CAT!") time.sleep(61) time.sleep(1) check_feeding() ```
Review this Go HTTP middleware for authentication. Focus on security vulnerabilities: ```go func AuthMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { token := r.Header.Get("Authorization") if token == "" { token = r.URL.Query().Get("token") } if token == os.Getenv("API_SECRET") { next.ServeHTTP(w, r) return } user, err := validateJWT(token) if err != nil { http.Error(w, "unauthorized", 401) return } ctx := context.WithValue(r.Context(), "user", user) next.ServeHTTP(w, r.WithContext(ctx)) }) } ```








