instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with creating a simple iOS app that allows users to manage a to-do list. The app should have the following functionality: 1. Display a list of to-do items. 2. Add new to-do items. 3. Mark to-do items as completed. 4. Delete to-do items. You are provided with a basic Swift class representing a to-do item...
magicoder
You are working on a deployment script for a distributed system. The script is responsible for updating the configuration files on all nodes and then running a benchmarking tool to measure the system's performance. The script takes three arguments: a list of all nodes in the system, the name of the configuration file t...
magicoder
You are tasked with implementing a function that processes a list of file operations and returns the total number of successful file writes. The file operations are represented as a series of function calls and their associated outcomes. Each function call can either succeed or fail, and the outcome is denoted by the r...
magicoder
You are tasked with creating a script to process and filter data from multiple trials using a set of parameters. The script should read in a set of trials, apply a specific key, and filter out any lines containing the strings "VAST" or "Both". The filtered results should be saved to separate files for each trial. You ...
magicoder
You are tasked with implementing a custom documentation system for a software library. The system should support the concept of "documentation extensions," which allow developers to annotate their code with additional metadata for documentation generation. Each documentation extension is represented by a class with th...
magicoder
You are given a Java method that sorts an array using the selection sort algorithm. The method takes an array of generic type T and sorts it in ascending order. The `get` method retrieves the element at a given index, and the `set` method sets the value at a given index. Your task is to implement a similar sorting meth...
magicoder
You are working on a Python application that interacts with a MySQL database. The application has a class with a method to retrieve the database cursor. The method is defined as follows: ```python def getCursor(self) -> MySQLCursor: return self.connection.cursor() ``` Your task is to implement a modified version ...
magicoder
You are tasked with implementing the A* search algorithm to find the shortest path between two points on a grid. The grid is represented as a 2D array, where each cell can be either empty or blocked. The algorithm should return a list of positions representing the shortest path from the start position to the goal posit...
magicoder
You are tasked with implementing a class in TypeScript to represent a code snippet. The class should have two properties: `isPrivate`, a boolean indicating whether the code snippet is private or not, and `code`, a string containing the actual code. Your task is to create the TypeScript class `CodeSnippet` with the fol...
magicoder
You are tasked with creating a Python program to manage user authentication for an API. The program should prompt the user for a password using the `getpass` module if the `api_password` variable is `None`. If `api_password` is not `None`, the program should proceed without prompting for a password. Your task is to im...
magicoder
You are tasked with implementing a custom regularization layer for a neural network using TensorFlow/Keras. The regularization layer should apply L1 and L2 regularization to the input tensor and return the regularization term. You are given a code snippet that partially implements the regularization layer. The `Regula...
magicoder
You are tasked with creating a Python program to determine whether a given year is a leap year or not. A leap year is a year that is evenly divisible by 4, except for end-of-century years, which must be divisible by 400 to be considered a leap year. Your program should take a year as input and output whether it is a le...
magicoder
You are working on a PHP application that involves handling authorization for different actions. The code snippet provided is a part of a method in a class. The method is responsible for checking authorization before performing a specific action. The `getActionMethod` method is used to retrieve the action method from t...
magicoder
You are working on a home automation system that includes a remote controller for various devices. The system uses a BlackBoxEvent struct to represent different events triggered by the remote controller. The BlackBoxEvent struct has a type property to specify the type of event and a value property to hold the event-spe...
magicoder
You are tasked with implementing a Python class that represents a job configuration for a distributed computing system. The class should have attributes for the number of instances and a coordination command line. Additionally, the class should have a method to validate the job configuration based on certain criteria. ...
magicoder
You are tasked with implementing a custom error handling mechanism for a Rust application. The goal is to create a macro similar to the `expect` method provided by the Rust standard library's `Option` and `Result` types. The macro should accept a custom error message and handle it appropriately. Your task is to create...
magicoder
You are given an array of integers and a target sum. Your task is to write a function that returns true if there are two distinct elements in the array whose sum equals the target sum, and false otherwise. Write a C++ function with the following signature: ```cpp bool hasTwoSum(const std::vector<int>& nums, int target...
magicoder
You are tasked with creating a program that interacts with the OpenDota API to retrieve and display information about Dota 2 matches. The OpenDota API provides various endpoints for accessing match data, including match details, player statistics, and more. Your program should be able to make HTTP requests to the OpenD...
magicoder
You are tasked with simulating a chat server using Python's Pyro library. The provided code snippet is a part of a multi-threaded chat client that interacts with the chat server. Your goal is to implement a chat client class that can send and receive messages to and from the chat server using Pyro. Your task is to com...
magicoder
You are tasked with implementing a temperature simulation program using the finite element method. The given code snippet is part of a larger program and contains some variable declarations and initializations. Your task is to complete the implementation by writing the code to solve the transient heat conduction equati...
magicoder
You are tasked with implementing a command-line interface for managing contract permissions and status. The provided code snippet contains a list of available commands along with their descriptions. Your goal is to design a program that processes user input to execute the corresponding commands. You need to implement ...
magicoder
You are tasked with implementing a function to determine the longest common prefix string amongst an array of strings. If there is no common prefix, the function should return an empty string "". You need to implement the following function: ```python def longest_common_prefix(strs: List[str]) -> str: pass ``` T...
magicoder
You are working for a mapping software company that specializes in analyzing and visualizing geographical data. Your task is to create a Python function that takes a GeoDataFrame and a distance threshold as input and returns a list of pairs of points that are within the specified distance of each other. To accomplish t...
magicoder
You are tasked with creating a custom PHP model class for a real-time data storage system. The model should interact with a database table named "rt" that has a primary key "id_rt" and allows the storage of specific fields. Your task is to complete the PHP model class by implementing the necessary code to define the ta...
magicoder
You are given a function `valid_count` that takes a string as input. The string consists of multiple lines, where each line contains a space-separated list of words. Your task is to implement the `valid_count` function to count the number of valid passphrases in the input string. A passphrase is considered valid if it ...
magicoder
You are tasked with creating a TypeScript class that represents an ORM (Object-Relational Mapping) entity for storing options related to questions in a database. The provided code snippet is a starting point for the implementation. Your task is to complete the `OrmOption` class by adding the necessary properties and de...
magicoder
You are tasked with creating a function that processes a given array of objects and returns a new array containing specific properties of the objects. Each object in the input array represents a product and has the following structure: ```javascript { id: string, name: string, price: number, category: string }...
magicoder
You are tasked with implementing a Python function to generate a signed JSON Web Token (JWT) using the Google App Engine default service account. The function should take no arguments and return the generated JWT as a string. The JWT should be generated according to the following specifications: - The payload of the J...
magicoder
You are tasked with implementing a program that simulates the behavior of a printer by rearranging and printing a given set of strings in a specific format. The program should take a list of strings as input and output the rearranged strings according to the given format. The printer behavior is defined by the followi...
magicoder
You are tasked with creating a real-time chat application using Node.js and Socket.IO. The code snippet provided initializes a connection event for Socket.IO, allowing for communication between the server and connected clients. Your task is to implement the server-side logic to handle incoming messages from clients and...
magicoder
You are tasked with implementing a program that simulates a simple banking system. The program should allow users to create accounts, deposit and withdraw funds, and check their balance. Each account should have a unique account number, and the program should support multiple accounts. Your task is to implement the `B...
magicoder
You are given a list of tuples, where each tuple contains a date in the format "YYYY-MM-DD" and a corresponding temperature in degrees Fahrenheit. Your task is to write a function to calculate the average temperature for each month and return the result as a dictionary where the keys are the month-year combinations (e....
magicoder
You are tasked with creating a tax calculation program for a country where the tax rates are based on income brackets. The tax calculation is based on the following rules: - If the tax base is less than or equal to 1200 times the value of MANWON, the tax is calculated as 6% of the tax base. - If the tax base is greater...
magicoder
You are tasked with implementing a custom annotation category view in a Swift iOS app. The annotation category view will display a list of categories and allow the user to select a category by tapping on it. To achieve this, you need to complete the implementation of the `AnnotationCategoryView` class and its delegate ...
magicoder
You are given a piece of code that contains a while loop and some conditional statements. The code snippet is part of a larger program that manipulates the value of variable `a` based on certain conditions. The variable `a` is initially not equal to 1, and the loop continues until `a` becomes 1. Inside the loop, there ...
magicoder
You are tasked with implementing a size calculation protocol for a feed cell view in a social media app. The provided code snippet is part of a feed cell view class and includes a property `model` of type `CZFeedModel` and a property `cellComponent` conforming to the `CZFeedCellViewSizeCalculatable` protocol. The `conf...
magicoder
You are tasked with creating a Python function that reads user data from a file and launches an EC2 instance based on certain conditions. The function should take in two parameters: `user_data_file` (a string representing the file path of the user data file) and `instance_class` (a string representing the class of the ...
magicoder
You are tasked with implementing a simple URL routing system for a web application. The system should be able to handle requests for controllers and actions, and if a requested controller is not found, it should fall back to an "EmptyController" to handle the request. You are given a code snippet for an "EmptyControll...
magicoder
You are tasked with writing a script to process speech feature extraction data. The provided code snippet is a part of a larger script and contains several shell commands. Your task is to understand the purpose of the code and write a function to achieve the same functionality in a programming language of your choice. ...
magicoder
You are tasked with creating a program that processes a given software license file to extract and display the licensing information. The license file contains the copyright notice and the license type. The copyright notice is always presented in the format "Copyright (c) [Organization Name]" and the license type is sp...
magicoder
You are tasked with implementing a program that processes a series of commands to manipulate a list of excluded letters. The program should support the following commands: 1. "r <letter>": Remove the specified letter from the list of excluded letters. The program should ignore any attempt to remove a letter that is a...
magicoder
You are tasked with implementing a pipeline for processing and transforming data for a machine learning model. The pipeline should consist of multiple stages, each performing a specific data processing task. Your goal is to create a class, `TrainPipeline`, that allows for the sequential execution of these stages. The ...
magicoder
You are tasked with implementing a pagination system for a web application. The provided code snippet contains two functions, `next_url` and `prev_url`, which are responsible for generating the URLs for the next and previous pages in the paginated results. The `next_url` function takes four arguments: - `url` (string)...
magicoder
You are tasked with implementing a Variational Autoencoder (VAE) using Pyro, a probabilistic programming language built on top of PyTorch. Your goal is to define the model and guide functions for the VAE, which involves creating an encoder and decoder network, setting up the model for the conditional probability distri...
magicoder
You are tasked with implementing a generic method to set the value of a list at a specific index. The method signature is as follows: ```csharp void ListSetByIndex<T>(string key, long index, T value); ``` The method takes three parameters: - `key`: A string representing the key of the list. - `index`: A long represen...
magicoder
You are tasked with creating a program that processes a list of GitHub repositories and their respective star counts. The program should read in the repository data and output the repositories with the highest number of stars. You are given a code snippet that represents a partial input file containing repository data...
magicoder
You are tasked with creating a program that analyzes a given software license text to extract and count the occurrences of specific keywords related to the permissions and limitations stated in the license. You are given a string representing the text of a software license. The license text contains statements about p...
magicoder
You are tasked with creating a command-line interface (CLI) tool for managing datasets. The tool should allow users to select a dataset from a list of available options and specify a batch size for processing the selected dataset. Your task is to implement the functionality for parsing command-line arguments using the...
magicoder
You are working on a Python application that manages settings for different lessons. The application has a class `LessonManager` with several methods related to handling lesson settings. The class has the following methods: 1. `_settings_template_path_for_lesson(lesson)`: This method takes a `lesson` object as input a...
magicoder
You are tasked with creating a program to parse and extract specific information from HTML code. The given HTML snippet is a part of a navigation bar in a web application. Your task is to write a function that extracts all the URLs from the `href` attributes of the anchor (`<a>`) tags in the HTML code. Write a functio...
magicoder
You are working on a computer vision project and need to implement a function to calculate the transformation matrix for converting 3D coordinates to 2D image coordinates. The transformation involves camera calibration parameters and the 3D coordinates of a point in the world coordinate system. You are given the follow...
magicoder
You are tasked with implementing a function to process a list of messages and return a summary of the messages in a specific format. The function `get_message` takes an array of string slices `input` as input and should return a formatted summary of the messages. The function should process the input messages and retu...
magicoder
You are working on a blockchain-based application using the EOSIO platform. In this scenario, you need to create a smart contract that manages the issuance and transfer of a custom token called "MyToken." The smart contract should include functionalities to create new tokens, transfer tokens between accounts, and retri...
magicoder
You are tasked with creating a function that simulates a simplified version of a database delete operation. The function should take in an array of objects representing database records and an ID, and then remove the record with the matching ID from the array. If the ID is not found in the array, the function should re...
magicoder
You are tasked with implementing a simple audio processing system. The system has an Audio Manager class, AKManager, which can be configured to apply different audio effects to the input audio signal. The available audio effects are represented by different classes, such as flanger, reverb, and chorus. The AKManager ha...
magicoder
You are tasked with creating a function that searches for a specific category within an array of associative arrays. The function should return the index of the first occurrence of the category within the array, or -1 if the category is not found. The function should be implemented in PHP. You are given the following ...
magicoder
You are tasked with creating a script that will parse a configuration file and extract specific information from it. The configuration file contains various settings for a system, and you need to extract the value of the "device" setting. The configuration file follows a specific format: - Each setting is on a new lin...
magicoder
You are tasked with implementing a Java class that manages a list of commerce item transactions. The class should provide methods to add, remove, and retrieve commerce item transactions, as well as calculate the total value of all transactions. You are given a partial code snippet for the `CommerceManager` class, whic...
magicoder
You are tasked with creating a Python program that fetches the public IP address of the user's machine and extracts the country and city information from the retrieved webpage. You should use the `requests` library to send an HTTP GET request to the "http://myip.ipip.net/" URL, parse the HTML content to extract the IP ...
magicoder
You are tasked with creating a simple command-line tool that emulates a basic calculator. The tool should accept user input for two numbers and an operator, perform the corresponding arithmetic operation, and display the result. However, the tool should also handle potential errors gracefully. Your task is to implemen...
magicoder
You are tasked with creating a Java Swing application that allows users to draw shapes on a canvas. The application should provide a menu with options to select different shapes (e.g., rectangle, circle, line) and a color palette to choose the drawing color. When a shape is selected, the user should be able to click an...
magicoder
You are tasked with implementing a Python function that processes an image array using various NumPy and OpenCV operations. The function takes in an input image array `shuffled_img` of shape (N, H, W, C), where N represents the number of images, H is the height, W is the width, and C is the number of channels. The func...
magicoder
You are tasked with implementing a TestRunBuilder class that allows for the construction of test runs for a software testing framework. The class should provide methods for setting various attributes of a test run, such as owner, environment, and tags. The provided code snippet is a method from the TestRunBuilder class...
magicoder
You are given a code snippet that involves manipulating a list of objects and measuring the time taken for the operations. Your task is to create a program that simulates a similar scenario and measures the time taken for the operations. Your program should perform the following steps: 1. Create a class `TestClass` w...
magicoder
You are tasked with implementing a generic repository pattern for a data access layer in a C# application. The repository pattern is a common way to abstract the data access logic from the rest of the application, providing a consistent interface for data operations. Your task is to create a generic repository class th...
magicoder
You are given a string `base` containing a person's name. Your task is to write a function `generate_usernames` that takes the base name and a list of integers as input and returns a list of usernames generated by appending each integer to the base name. If the integer is negative, it should be appended as a negative n...
magicoder
You are tasked with implementing a simple simulation system for a game engine. The provided code snippet contains two functions related to the simulation module: `mod_simulation_load` and `mod_simulation_update`. Your goal is to complete the implementation of the `mod_simulation_update` function to simulate the behavio...
magicoder
You are tasked with creating a PHP function that processes user registration data and stores it in a database. Your function should handle validation, insertion, and error handling. You are provided with the following code snippet as a starting point: ```php if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username...
magicoder
You are tasked with implementing a custom data loader for a machine learning model. The data loader should be able to handle both training and testing datasets, and it should support batching and shuffling of the data. You are given a code snippet that initializes and returns the train and test data loaders using the ...
magicoder
You are tasked with designing a system for scheduling and executing periodic tasks using a thread pool in Rust. The system should allow for the execution of a specific task at fixed intervals, and it should be able to handle concurrent execution of multiple tasks. Your task is to implement a function `schedule_periodi...
magicoder
You are tasked with implementing a function that generates an indented representation of a hierarchical structure. The function takes an object `obj` and returns a string representing the object's position within the hierarchy. The indentation is based on the level of the object within the hierarchy, and special charac...
magicoder
You are tasked with creating a script to automate the process of adding and updating packages in an OpenWrt firmware build environment. OpenWrt is a Linux-based open-source operating system designed for embedded devices. The firmware is often customized by adding or removing packages to suit specific requirements. You...
magicoder
You are given a string containing a series of opening and closing curly braces. Your task is to write a function that determines if the braces are properly nested. A pair of braces is considered properly nested if the opening and closing braces match and are in the correct order. Write a function `isProperlyNested` th...
magicoder
You are tasked with creating a program that simulates a simple text-based game. The game involves a character navigating through a grid-based world, collecting treasures, and avoiding obstacles. The character's movements are controlled by the user's input. Your task is to implement the movement logic for the character...
magicoder
You are tasked with implementing a role-based access control system for a web application. The system should allow users to be assigned different roles, each with its own set of permissions. Your task is to write a function that takes a role name as input and returns the corresponding permissions associated with that r...
magicoder
You are tasked with implementing a function to process a list of tables and generate a final table based on certain conditions. The function should take in a list of tables and return the final table after applying specific operations. You are given a class `Plot` with an attribute `table_list` representing a list of ...
magicoder
You are tasked with implementing a function to factorize a given integer using the Elliptic Curve Method (ECM) or a default factorization method. The function `factorization` takes three parameters: `x` (the integer to be factorized), `timeout_duration` (the maximum time allowed for factorization), and `use_ecm` (a boo...
magicoder
You are working on a bioinformatics pipeline that involves processing DNA sequencing data in the BAM file format. The code snippet provided is a part of a Python script that utilizes the `subprocess` module to execute a command-line tool called `samtools`. This tool is used for manipulating BAM files, specifically for ...
magicoder
You are working on a project that involves assembling images and managing package manifests. The project has a file structure where the main code is in a directory, and there are subdirectories containing configuration files and package manifests. The code snippet provided is from a Python file in the main directory, w...
magicoder
You are working on a project that involves compiling and packaging a set of source code files written in C#. Your task is to create a script that automates the compilation and packaging process. The script should perform the following steps: 1. Compile all the C# source code files in the current directory into executab...
magicoder
You are working on a serverless search application that utilizes Apache Lucene for indexing and searching documents. The code snippet provided is a part of the serverless search core module and defines a custom field type called `AllField`. This field type is used to index all the content of a document, including its f...
magicoder
You are tasked with implementing a buffer pool manager for a database system. The buffer pool manager is responsible for managing a collection of fixed-size buffers in memory, which are used to cache disk pages. The provided code snippet is a method within the buffer pool manager that processes input buffers and writes...
magicoder
You are tasked with implementing a simple decorator pattern in JavaScript. Decorators are a structural design pattern that allows behavior to be added to individual objects dynamically, without affecting the behavior of other objects from the same class. In this problem, you will create a set of decorators to modify th...
magicoder
You are tasked with implementing a simple logging system for a web server. The server receives requests for different hostnames, and you need to log a warning message if the requested hostname does not have a corresponding server configuration. You are given a Rust code snippet that handles the case when no server con...
magicoder
You are tasked with implementing a utility class for managing time-related operations in a data processing application. The utility class, `TimeUtil`, is responsible for calculating the time difference in minutes between two given timestamps. The class also includes methods for setting dataset instances and process per...
magicoder
You are tasked with creating a Python class that represents a financial entity using SQLAlchemy, a popular Python SQL toolkit and Object-Relational Mapping (ORM) library. Your task is to define the `Funding` class, which should inherit from the `Base` class and be mapped to a table named `financement` in the database. ...
magicoder
You are tasked with implementing a Python unit test for a method that disassociates a Quality of Service (QoS) specification from a volume type in a storage system. The code snippet provided is a part of a unit test for this functionality. Your task is to write the unit test method `test_disassociate` that verifies the...
magicoder
You are tasked with creating a Python function that processes a Protobuf message and extracts information about its fields and enums. The function should take in a Protobuf message descriptor and return a dictionary containing the names of the message fields and all the enum types present in the message. The function ...
magicoder
You are tasked with implementing a Python function that manages environment paths and executes commands with a timeout. The provided code snippet includes a partial implementation of this functionality. Your task is to complete the implementation of the `run_command` function and ensure that it can execute commands wit...
magicoder
You are tasked with creating a class for a user interface (UI) element in a game development framework. The UI element should have properties for height, caption, icon, and behavior when pressed. Additionally, it should provide a method for rendering the UI element on the screen. Create a C# class named `UIElement` wi...
magicoder
You are tasked with creating a Python function that processes a YAML file containing information about resources and converts them to RDF format. The function should extract resource URLs from the YAML file and convert them to RDF. You are given a code snippet that initializes a variable `res_i` to 0 and iterates thr...
magicoder
You are tasked with implementing a function to calculate the SHA-256 hash of a given string. The SHA-256 algorithm is a widely used cryptographic hash function that produces a 256-bit (32-byte) hash value. Your function should take a string as input and return the corresponding SHA-256 hash in hexadecimal format. Your...
magicoder
You are given a list of integers `valores`. Your task is to write a function that finds the indices of all occurrences of the smallest value in the list and returns them as a list. If the smallest value appears multiple times, all corresponding indices should be included in the output list. Write a function `find_smal...
magicoder
You are tasked with implementing a function to calculate the Supertrend indicator for a given set of stock prices. The Supertrend indicator is used in technical analysis to identify the direction of the asset's price movement. It is calculated based on the average true range (ATR) and the multiplier value. The formula ...
magicoder
You are tasked with implementing a class that manages the state of instances and their purge status. The class should have the following functionalities: 1. Store state information for instances. 2. Mark instances for purging. 3. Track if the state information has been modified. You need to implement the `InstanceMan...
magicoder
You are tasked with implementing a shared coroutine queue system in Swift. The shared coroutine queue system should support a fixed capacity and allow multiple coroutines to enqueue and dequeue items concurrently. The system should be implemented using the `FifoQueue` data structure, which is a first-in-first-out queue...
magicoder
You are tasked with creating a SwiftUI view that presents a web view when a button is tapped. You need to utilize the `@Environment` property wrapper to access the presentation mode and a `@State` property to control the presentation of the web view. Your task is to complete the `WebViewPresenter` view by implementing...
magicoder
You are tasked with implementing a Python class that represents a version number. The version number is represented as a tuple of integers, where each integer corresponds to a specific component of the version (e.g., major, minor, patch). Your task is to create a class that allows for easy manipulation and comparison o...
magicoder
You are tasked with creating a Python program that interacts with an external command-line tool to process JSON data. The program should read a JSON file, modify its contents, and then pass the modified JSON data to the external tool for further processing. Your task is to implement the Python program to achieve this f...
magicoder
You are tasked with implementing a class hierarchy to represent different departments within a company. Each department has a name and a unique identifier. Your goal is to create a set of classes that accurately model this relationship and provide a method to retrieve the department's identifier. You should create a b...
magicoder