Spaces:
Sleeping
Sleeping
| [ | |
| { | |
| "code": "def calculate_bmi(weight: float, height: float) -> float:\n \"\"\"Calculate Body Mass Index\"\"\"\n if height <= 0:\n raise ValueError(\"Height must be positive\")\n return weight / (height ** 2)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "BMI calculator with validation" | |
| }, | |
| { | |
| "code": "def celsius_to_fahrenheit(celsius: float) -> float:\n \"\"\"Convert Celsius to Fahrenheit\"\"\"\n return (celsius * 9/5) + 32", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Temperature conversion" | |
| }, | |
| { | |
| "code": "import random\n\ndef generate_password(length: int = 12) -> str:\n \"\"\"Generate secure random password\"\"\"\n import string\n chars = string.ascii_letters + string.digits + string.punctuation\n return ''.join(random.choice(chars) for _ in range(length))", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Password generator" | |
| }, | |
| { | |
| "code": "def is_palindrome(s: str) -> bool:\n \"\"\"Check if string is palindrome\"\"\"\n s = ''.join(c.lower() for c in s if c.isalnum())\n return s == s[::-1]", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Palindrome checker" | |
| }, | |
| { | |
| "code": "def count_words(text: str) -> int:\n \"\"\"Count words in a string\"\"\"\n return len(text.split())", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Word counter" | |
| }, | |
| { | |
| "code": "import os\n\ndef get_file_size(filepath: str) -> int:\n \"\"\"Get file size in bytes\"\"\"\n try:\n return os.path.getsize(filepath)\n except OSError:\n return -1", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "File size utility" | |
| }, | |
| { | |
| "code": "def reverse_list(lst: list) -> list:\n \"\"\"Reverse a list without modifying original\"\"\"\n return lst[::-1]", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "List reversal" | |
| }, | |
| { | |
| "code": "def find_max(numbers: list) -> float:\n \"\"\"Find maximum value in list\"\"\"\n if not numbers:\n return None\n return max(numbers)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Find max value" | |
| }, | |
| { | |
| "code": "def find_min(numbers: list) -> float:\n \"\"\"Find minimum value in list\"\"\"\n if not numbers:\n return None\n return min(numbers)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Find min value" | |
| }, | |
| { | |
| "code": "def average(numbers: list) -> float:\n \"\"\"Calculate average of list\"\"\"\n if not numbers:\n return 0.0\n return sum(numbers) / len(numbers)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Calculate average" | |
| }, | |
| { | |
| "code": "def to_uppercase(text: str) -> str:\n \"\"\"Convert string to uppercase\"\"\"\n return text.upper()", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Uppercase converter" | |
| }, | |
| { | |
| "code": "def to_lowercase(text: str) -> str:\n \"\"\"Convert string to lowercase\"\"\"\n return text.lower()", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Lowercase converter" | |
| }, | |
| { | |
| "code": "def capitalize_words(text: str) -> str:\n \"\"\"Capitalize first letter of each word\"\"\"\n return text.title()", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Title case converter" | |
| }, | |
| { | |
| "code": "import json\n\ndef save_json(data: dict, filepath: str):\n \"\"\"Save dictionary to JSON file\"\"\"\n with open(filepath, 'w', encoding='utf-8') as f:\n json.dump(data, f, indent=4)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "JSON saver" | |
| }, | |
| { | |
| "code": "import csv\n\ndef read_csv(filepath: str) -> list:\n \"\"\"Read CSV file into list of dicts\"\"\"\n with open(filepath, 'r', newline='') as f:\n return list(csv.DictReader(f))", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "CSV reader" | |
| }, | |
| { | |
| "code": "import time\n\ndef timer_decorator(func):\n \"\"\"Decorator to measure execution time\"\"\"\n def wrapper(*args, **kwargs):\n start = time.time()\n result = func(*args, **kwargs)\n end = time.time()\n print(f\"{func.__name__} took {end-start:.4f}s\")\n return result\n return wrapper", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Timer decorator" | |
| }, | |
| { | |
| "code": "def flatten_dict(d: dict, parent_key: str = '', sep: str = '_') -> dict:\n \"\"\"Flatten nested dictionary\"\"\"\n items = []\n for k, v in d.items():\n new_key = f\"{parent_key}{sep}{k}\" if parent_key else k\n if isinstance(v, dict):\n items.extend(flatten_dict(v, new_key, sep=sep).items())\n else:\n items.append((new_key, v))\n return dict(items)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Dict flattener" | |
| }, | |
| { | |
| "code": "def safe_division(a: float, b: float) -> float:\n \"\"\"Divide with zero check\"\"\"\n if b == 0:\n return 0.0\n return a / b", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Safe division" | |
| }, | |
| { | |
| "code": "def get_extension(filename: str) -> str:\n \"\"\"Get file extension\"\"\"\n if '.' not in filename:\n return ''\n return filename.split('.')[-1]", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "File extension extractor" | |
| }, | |
| { | |
| "code": "import re\n\ndef is_valid_email(email: str) -> bool:\n \"\"\"Validate email format\"\"\"\n pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$'\n return bool(re.match(pattern, email))", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Email validator" | |
| }, | |
| { | |
| "code": "def clamp(n: float, min_val: float, max_val: float) -> float:\n \"\"\"Clamp number between min and max\"\"\"\n return max(min_val, min(n, max_val))", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Clamp function" | |
| }, | |
| { | |
| "code": "def lerp(start: float, end: float, t: float) -> float:\n \"\"\"Linear interpolation\"\"\"\n return start + t * (end - start)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Linear interpolation" | |
| }, | |
| { | |
| "code": "def factorial_iterative(n: int) -> int:\n \"\"\"Calculate factorial iteratively\"\"\"\n result = 1\n for i in range(2, n + 1):\n result *= i\n return result", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Iterative factorial" | |
| }, | |
| { | |
| "code": "def fibonacci_iterative(n: int) -> int:\n \"\"\"Calculate Fibonacci iteratively\"\"\"\n if n <= 1:\n return n\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, a + b\n return b", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Iterative Fibonacci" | |
| }, | |
| { | |
| "code": "def gcd(a: int, b: int) -> int:\n \"\"\"Calculate Greatest Common Divisor\"\"\"\n while b:\n a, b = b, a % b\n return a", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "GCD calculator" | |
| }, | |
| { | |
| "code": "def lcm(a: int, b: int) -> int:\n \"\"\"Calculate Least Common Multiple\"\"\"\n if a == 0 or b == 0:\n return 0\n return abs(a * b) // gcd(a, b)", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "LCM calculator" | |
| }, | |
| { | |
| "code": "def is_even(n: int) -> bool:\n \"\"\"Check if number is even\"\"\"\n return n % 2 == 0", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Even checker" | |
| }, | |
| { | |
| "code": "def is_odd(n: int) -> bool:\n \"\"\"Check if number is odd\"\"\"\n return n % 2 != 0", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Odd checker" | |
| }, | |
| { | |
| "code": "def square(n: float) -> float:\n \"\"\"Calculate square of number\"\"\"\n return n * n", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Square calculator" | |
| }, | |
| { | |
| "code": "def cube(n: float) -> float:\n \"\"\"Calculate cube of number\"\"\"\n return n * n * n", | |
| "language": "python", | |
| "task": "boilerplate", | |
| "description": "Cube calculator" | |
| } | |
| ] |