import json import random # ========================== # CODING & DEVELOPER DATA CREATOR # ========================== coding_examples = [ ("Write a Python function to reverse a string.", "def reverse_string(s):\n return s[::-1]"), ("Explain what a class is in Python.", "A class is a blueprint for creating objects. It defines attributes and methods that its objects will have."), ("Fix this Python error: TypeError: 'int' object is not iterable.", "You are likely trying to loop over an integer. Use range() or convert it to an iterable."), ("Write a JavaScript function to check if a number is even.", "function isEven(num) {\n return num % 2 === 0;\n}"), ("Explain how async/await works in JavaScript.", "Async/await allows asynchronous code to be written in a synchronous style using Promises under the hood."), ("Write a simple React component that shows 'Hello World'.", "function HelloWorld() {\n return

Hello World

;\n}\nexport default HelloWorld;"), ("Explain what Big O notation is.", "Big O notation describes how the runtime or space requirements of an algorithm grow relative to the input size."), ("Create a function in C++ that returns the factorial of a number.", "int factorial(int n) {\n return (n <= 1) ? 1 : n * factorial(n - 1);\n}"), ("Explain what an API is.", "An API (Application Programming Interface) allows two systems to communicate by exposing data or functions programmatically."), ("Write a SQL query to select all users older than 25.", "SELECT * FROM users WHERE age > 25;"), ("Explain what recursion is.", "Recursion is when a function calls itself to solve smaller instances of a problem."), ("Write a Python program to check if a string is a palindrome.", "def is_palindrome(s):\n s = s.lower().replace(' ', '')\n return s == s[::-1]"), ("Explain what a REST API is.", "A REST API uses HTTP methods (GET, POST, PUT, DELETE) to manage resources identified by URLs."), ("Write a JavaScript program to fetch data from an API.", "fetch('https://api.example.com/data')\n .then(res => res.json())\n .then(data => console.log(data));"), ("Explain the difference between == and === in JavaScript.", "== compares values with type coercion, while === compares both value and type."), ("Write a Python decorator that logs function calls.", "def log_calls(func):\n def wrapper(*args, **kwargs):\n print(f'Calling {func.__name__}')\n return func(*args, **kwargs)\n return wrapper"), ("Explain what machine learning is.", "Machine learning is a branch of AI where algorithms learn patterns from data to make predictions or decisions without being explicitly programmed."), ("Write a Python list comprehension to get squares of numbers from 1 to 10.", "[x**2 for x in range(1, 11)]"), ("Explain the difference between list and tuple in Python.", "A list is mutable (can be changed), while a tuple is immutable (cannot be changed)."), ("Explain how Git works.", "Git is a version control system that tracks changes in code and allows collaboration through commits and branches.") ] # ========================== # GENERATE EXTENDED DATASET # ========================== dataset = [] for _ in range(1000): # Generate 1000 examples instruction, response = random.choice(coding_examples) dataset.append({ "category": "coding", "instruction": instruction, "response": response }) # ========================== # SAVE TO JSONL # ========================== output_file = "coding_ai_dataset.jsonl" with open(output_file, "w", encoding="utf-8") as f: for ex in dataset: f.write(json.dumps(ex, ensure_ascii=False) + "\n") print(f"✅ Created {len(dataset)} coding & dev examples.") print(f"📄 Saved as {output_file}")