instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with testing the `add` method within a class. The `add` method takes two parameters `a` and `b`, and prints their sum. Your goal is to write test cases to cover various scenarios, including different input combinations and edge cases. The input combinations to be tested are: 1. 1 and 2 2. -1 and -2 3. 0...
magicoder
You are tasked with creating a Python class that utilizes an ObsceneDetector to filter out obscene words from a given text file. The ObsceneDetector is a class that can identify and flag obscene words, and the FileLoader is a class that can load a text file. Your task is to implement a class called `TextFilter` that us...
magicoder
You are tasked with implementing a topological sort algorithm to order the vertices of a directed acyclic graph (DAG) in a specific sequence. The topological sort algorithm arranges the vertices in such a way that for every directed edge from vertex u to vertex v, u comes before v in the ordering. This ordering is not ...
magicoder
You are tasked with implementing a simple word frequency counter in Rust. You need to create a function that takes a string as input and returns a HashMap containing the frequency of each word in the input string. For this problem, a word is defined as any sequence of non-whitespace characters. Your task is to impleme...
magicoder
You are tasked with implementing a URL generator function in PHP. The function should take a route name, an optional array of parameters, and a boolean flag indicating whether the URL should be generated as scheme-relative. The function should return the generated URL as a string. The function signature is as follows:...
magicoder
You are tasked with implementing a class that manages user IDs for a system. The class should have the following functionality: 1. Initialize the user ID to a default value of 1 if no initial ID is provided. 2. Allow retrieval of the current user ID. 3. Allow incrementing the user ID by a specified amount. 4. Allow re...
magicoder
You are tasked with implementing a function to parse an ISO 8601 formatted date string and return an object containing the time in seconds and the time zone offset in minutes. The function signature is: ```javascript /** * Parses an ISO 8601 formatted date string and returns an object containing the time in seconds a...
magicoder
You are tasked with creating a Django REST framework application for managing tasks. The given code snippet is a part of the URL configuration and view registration for the application. Your task is to complete the implementation of the `TaskViewset` and `HelloAPIView` classes to handle task management and a simple gre...
magicoder
You are tasked with creating a Python program to automate the process of formatting an Excel spreadsheet. Your program should read data from a given input file, adjust the column widths based on the maximum length of the data in each column, and then save the formatted spreadsheet to a specified output file. Your prog...
magicoder
You are tasked with creating a script to automate the management of NGINX proxy containers in a Docker environment. The script should locate the NGINX proxy container based on a specific label, and then execute a shell script within the container to test and reload the NGINX configuration. Given the code snippet below...
magicoder
You are tasked with implementing a program to analyze the operations performed on a text file. The program should calculate the total number of insertions, deletions, and substitutions made to the file and write the results to an output file. You are given a code snippet that calculates the total number of insertions,...
magicoder
You are tasked with implementing a custom login screen for a mobile application. The login screen should have a rounded login button and a light-colored status bar. You are provided with a code snippet from the `UIViewController` subclass that handles the login screen's view setup. The `LoginButton` is a UI element rep...
magicoder
You are tasked with implementing a pagination system for a web application. The pagination system should allow users to navigate through a list of items, displaying a certain number of items per page. The code snippet provided is a part of the pagination logic in a PHP application. The `$pagination` variable is used t...
magicoder
You are tasked with implementing a function that retrieves gold price history based on the provided request parameters. The function should take in the request parameters and return a Promise that resolves to the gold price history data. You are given the following code snippet as a starting point: ```typescript expo...
magicoder
You are tasked with creating a script that will process a given input file and perform a specific operation based on the file's contents. The input file will contain a series of commands, each on a new line. Your script should read the input file, execute the commands, and then output the result of each command to a se...
magicoder
You are working on a project that involves analyzing semantic graphs to extract meaningful information. As part of this project, you need to implement a method for object concept embedding using Python. You are given a class `SemanticGraphAnalyzer` that represents a semantic graph and provides a method `object_concept...
magicoder
You are tasked with implementing a function that imports a line from a given curve and scales it by a specified factor. The function should handle the case where the input curve is not of the expected type and return an appropriate error message. You are given the following code snippet as a starting point: ```python...
magicoder
You are tasked with implementing a function to filter and process log data in a file synchronization application. The application has a data structure `rsyncUIdata` containing log information, and a `selectedlog` representing the currently selected log. Additionally, there is a `selectedconfig` object representing the ...
magicoder
You are tasked with implementing a function that performs a specific type of text transformation. The transformation is based on the concept of graphemes and the Fano encoding method. Graphemes are the smallest units of writing in a language that distinguish meaning, while Fano encoding is a technique for data compress...
magicoder
You are tasked with creating a Python function that processes user input related to Toon displays. The function is part of an asynchronous Python class and interacts with the Toon API. Your goal is to complete the implementation of the `async_step_display` function, which is responsible for selecting a Toon display to ...
magicoder
You are tasked with implementing a simple order processing system using object-oriented programming in Python. Your task is to create a class hierarchy for processing orders, and then implement a method for calculating the total cost of an order. Create a base class `AbstractOrder` with the following specifications: -...
magicoder
You are tasked with creating a command-line translation tool using Python. Your program should utilize the `argparse` module to handle command-line arguments and the `translate_process` function to perform the actual translation. Your task is to complete the implementation of the `main_translate` function, which will ...
magicoder
You are tasked with creating a Rust function that performs a specific mathematical operation. Your task is to implement a function called `multiply_by_two` that takes an integer as input and returns the result of multiplying the input by 2. The function signature should be as follows: ```rust pub fn multiply_by_two(a:...
magicoder
You are tasked with implementing a function to parse a binary file format used for storing configuration data in a specific format. The file format consists of a series of records, each of which contains a 64-bit offset followed by a variable-length payload. The goal is to extract and process the payload data based on ...
magicoder
You are tasked with implementing a function to update the skew values of nodes in an AVL (Adelson-Velsky and Landis) tree. An AVL tree is a self-balancing binary search tree where the difference in heights of the left and right subtrees for every node is at most 1. The skew value of a node in an AVL tree can be one of ...
magicoder
You are tasked with creating a program that analyzes the licensing information of software projects. The program should read in a text file containing the licensing information of various software projects and determine whether each project is distributed under the GNU General Public License (GPL) and, if so, which ver...
magicoder
You are tasked with implementing a version control system for a software project. The system needs to handle the retrieval of remote tags and the checkout of the latest tag if no specific tag is requested. You are given a code snippet that attempts to retrieve remote tags and checkout the latest tag if no specific tag...
magicoder
You are given a function `checkValidity` that takes an integer `r` as input and returns a string "YES" if `r` is equal to 0, and "NO" otherwise. You need to implement a new function `checkNegativity` that takes an integer `n` as input and returns a string "POSITIVE" if `n` is greater than 0, "ZERO" if `n` is equal to 0...
magicoder
You are tasked with implementing a function to send a password reset email in a Django application. The function should take a user object and a request object as input and send a password reset email to the user's registered email address. The function should be tested using the pytest framework with the `@pytest.mark...
magicoder
You are tasked with creating a Python class that manages a collection of questions and their corresponding keys. The class should allow for adding new questions, retrieving questions by their keys, and listing all the keys in the collection. You should also ensure that the keys are unique and that the questions and key...
magicoder
You are tasked with creating a Python script to automate the execution of MrBayes, a popular software for Bayesian inference of phylogeny. MrBayes is typically run using the command `mpirun -np <num_processes> mb <input_file>`, where `<num_processes>` is the number of processes to be used and `<input_file>` is the inpu...
magicoder
You are tasked with creating a Java program to process and analyze address data from a database. The program should retrieve address information from a ResultSet object and perform specific operations on the data. You are given a code snippet that retrieves two long values, `addressId` and `client_id`, from a ResultSe...
magicoder
You are tasked with creating a Django management command that updates the access level and metadata access level for a given schema in a metadata database. The access level and metadata access level are to be provided as command-line arguments when running the management command. You are provided with the following co...
magicoder
You are working on a multilingual application that supports both English and Chinese languages. The application has a set of key-value pairs for various UI elements in both languages. Your task is to write a function that takes a language code and returns the corresponding set of UI elements in that language. You are ...
magicoder
You are tasked with implementing a function to find the next set of waypoints for a vehicle navigation system. The function should take a list of waypoints, a starting waypoint index, and an ending waypoint index as input, and return the next set of waypoints based on a lookahead window size. The provided code snippet ...
magicoder
You are tasked with creating a custom filter for a Django model to filter recordings based on their duration. The `Recordings` model has a field `duration` representing the length of the recording in seconds. You need to implement a custom filter that allows users to filter recordings based on their duration falling wi...
magicoder
You are working on a project to optimize the hyperparameters of a neural network for a machine learning task. The code snippet provided is a function call to train a neural network with the best hyperparameters obtained from a hyperparameter tuning process. Your task is to implement a function that performs hyperparame...
magicoder
You are given a list of integers `nums` and an integer `target`. Your task is to find the maximum length of a contiguous subarray that sums to `target`. If no such subarray exists, return 0. Write a function `maxSubarrayLen(nums, target)` that takes in the list of integers `nums` and the integer `target` as input and ...
magicoder
You are tasked with implementing a simple state management system for a multimedia player. The system should allow the player to pause and resume playback. You are provided with a partial implementation of the `Player` struct and its methods in Rust. Your task is to complete the implementation of the `Player` struct b...
magicoder
You are tasked with implementing a simple iterative algorithm to find the maximum value in a given array. The maximum number of iterations allowed for the algorithm is specified by the "max_iterations" parameter. If the algorithm does not find the maximum value within the specified number of iterations, it should retur...
magicoder
You are working on a project that involves creating various actions using a helper module called `core.helper.creator`. The `create_action` function from this module is used to generate different types of actions based on the input parameters. The function takes in two arguments: `action_type` (a string representing th...
magicoder
You are tasked with creating a validation rule for a user registration form in a web application. The form includes fields for name, email, and an option to change the password. The validation rules are defined in a PHP function as shown below: ```php public function rules() { $rules = [ 'name' => 'requir...
magicoder
You are tasked with creating a Python function that simulates the behavior of a user interacting with a software application using the `oHelper` object. The `oHelper` object provides methods for interacting with the application's user interface. Your task is to implement a function that performs a series of actions usi...
magicoder
You are working as a data analyst for a software development company. Your task is to analyze the usage of different Java versions across various base images used in the company's projects. You have been provided with a DataFrame `df` containing information about the base images and their corresponding Java versions. T...
magicoder
You are working on a data manipulation library and need to implement a method for handling column operations in a table. The method should take a new column as input and either replace an existing column or add the new column to the table. The method should also support in-place modification of the table. Write a Pyth...
magicoder
You are working on a web development project and need to optimize the CSS code for a navigation menu. The given code snippet contains a portion of the CSS styles for the navigation menu. Your task is to complete the CSS code to achieve the desired layout and appearance. The navigation menu should have the following ch...
magicoder
You are tasked with implementing a Python function that calculates the descriptive statistics of a given dataset. The function should accept a list of numerical values and return a dictionary containing the mean, median, mode, range, variance, and standard deviation of the dataset. Your function should be named `calcu...
magicoder
You are tasked with implementing a function to find the common prefix among a list of subscription topics. A subscription topic is a string that represents a topic in a publish-subscribe system, where '#' is used as a wildcard to match any number of levels in the topic hierarchy. The common prefix is the longest common...
magicoder
You are tasked with creating a program to parse and extract information from an XML file. The XML file contains data related to OpenCL kernel parameters and their associated files. Your program needs to read the XML file and extract specific information related to kernel names, xclbin file names, kernel file names, and...
magicoder
You are tasked with implementing a function that processes an array of `SerieCellViewModel` instances and returns a new array containing only the non-nil `title` values along with their corresponding `thumbnailURL` values. If the `thumbnailURL` is also non-nil, it should be converted to a string representation. If eith...
magicoder
You are working on a web application that allows users to participate in quizzes. The application has certain configurations that determine the behavior of the quiz system. Two of these configurations are defined in the code snippet provided: 1. `ALLOW_MULTIPLE_ANSWER`: A boolean variable that determines whether playe...
magicoder
You are tasked with implementing a custom memory management system using C++ smart pointers. Your goal is to create a class that can allocate and deallocate memory for objects of any type, while also ensuring that the objects are properly destructed when the memory is released. You are provided with a code snippet tha...
magicoder
You are tasked with implementing a Python class for a game character that moves within a game map. The class has an `__init__` method that initializes the character's attributes based on the provided parameters. The character's initial position and movement direction are determined by the `moveDir` parameter. The `spee...
magicoder
You are tasked with implementing a function that generates a random geometric graph using NetworkX, a Python library for the creation, manipulation, and study of complex networks. The function should take in the number of nodes and a list of coordinates, and then yield the resulting graph. Write a function `generate_r...
magicoder
You are tasked with implementing a function that calculates the average of a list of integers. The function should take a list of integers as input and return the average as a floating-point number. If the input list is empty, the function should return 0.0. You need to implement the following function: ```rust fn ca...
magicoder
You are tasked with implementing a function to retrieve the status of a player's data. The function `get_player_data_status(player_id)` takes an integer `player_id` as input and should return the status of the player's data. The function should handle the following cases: 1. If the player's data is available, the func...
magicoder
You are tasked with implementing a custom Boolean class in Python that mimics the behavior of the native Boolean class. Your custom Boolean class should have an instance initializer that takes a single argument and initializes the Boolean value based on the truthiness of the argument. If the argument is a non-empty str...
magicoder
You are tasked with creating a Python class method that processes financial data and returns a summary of income within a specified date range. The method should take in a start date and an end date, and then retrieve income data from the accounts. The income data is structured as a dictionary with various income categ...
magicoder
You are tasked with implementing a class that manages configuration changes and allows listeners to be notified when a configuration change occurs. You need to create a `ConfigManager` class that provides methods to add, remove, and notify listeners about configuration changes. Your `ConfigManager` class should have t...
magicoder
You are tasked with creating a web application feature that dynamically populates a dropdown list based on the selection made in another dropdown list. The provided code snippet is a part of the HTML form that is used to achieve this functionality. The form is intended to add a new class-subject-period association in a...
magicoder
You are working on a project that involves managing multiple TypeScript configuration files for different packages. Your task is to write a script that automates the creation of symbolic links for the TypeScript configuration files based on a given directory structure. Given the following directory structure: ``` proj...
magicoder
You are tasked with implementing a custom string manipulation function in C# that checks whether a given string begins with a specific substring. Your task is to complete the implementation of the `BeginsWith` method, which takes two parameters: a `line` of type `string` and a `selector` of type `string`. The method sh...
magicoder
You are tasked with implementing a Python function that filters a list of projects based on certain criteria. The function should take in a list of projects and a set of filters, and return a filtered list of projects based on the given filters. Each project is represented as a dictionary with various attributes. The ...
magicoder
You are tasked with implementing a parser for a custom programming language that supports a FOR_LOOP construct. The given code snippet is a part of the parser implementation for the FOR_LOOP construct. The parser is responsible for converting the source code into an abstract syntax tree (AST) for further processing. T...
magicoder
You are tasked with creating a Python function that manipulates a given string based on a set of rules. The function should take a string as input and perform the following operations: 1. If the input string starts with the letter 'p', remove the first and last characters from the string. 2. If the input string ends wi...
magicoder
You are tasked with implementing a function that validates the parameters of a POST call to a specific endpoint. The function should take in the parameters of the POST call and verify if they match the expected values. The expected parameters are defined within the code snippet provided. Your task is to create a functi...
magicoder
You are tasked with implementing a class to manage client login responses for a web application. The class should provide methods to track and analyze the success and failure rates of client login attempts. The class should have the following functionalities: 1. A method `recordLoginSuccess` to record a successful logi...
magicoder
You are tasked with creating a program to manage user accounts in a system. The program should be able to create user objects with specific attributes and perform operations on these user objects. You are given a class `User` with a method `create` that takes a user data array as a parameter and creates a new user ob...
magicoder
You are given a code snippet that appears to be part of a dynamic programming algorithm. The code processes a vector of pairs `v[i]`, where each pair consists of an integer and a value. The algorithm calculates the maximum possible value that can be obtained by selecting elements from the pairs, subject to certain cons...
magicoder
You are tasked with creating a program to manage user authentication for a multi-system environment. Each user has a unique originating system and an authorization token. The program should allow users to authenticate themselves and access the system based on their originating system and authorization token. You need ...
magicoder
You are tasked with creating a Python class that manages the migration of data between different versions of a database schema. Your class should handle dependencies between different database tables and ensure that the migration process is executed in a controlled and organized manner. Create a Python class called `M...
magicoder
You are tasked with creating a Django migration for a new model called `Issue`. The `Issue` model should have two fields: `title` and `description`, both of which are of type `CharField`. Additionally, the `Issue` model should have a field called `created_at` of type `DateTimeField`, which should automatically set the ...
magicoder
You are tasked with implementing a function that cancels out a selection of moves with any other move in a game. The game framework provides a module and a specific pattern to be located within the module. If the pattern is found, a hook is installed to redirect the execution flow to a detour function. However, if the ...
magicoder
You are tasked with creating a function that processes Vulkan submit information for a graphics application. The Vulkan submit information is represented by a struct `vk::SubmitInfo` and contains various parameters such as wait semaphores, command buffers, signal semaphores, etc. Your task is to implement a function th...
magicoder
You are working as a DevOps engineer for a company that uses Docker and Open vSwitch for network virtualization. Your task is to automate the process of building and packaging Open vSwitch for deployment on Raspberry Pi devices. The provided code snippet is a part of the automation script used for this purpose. The sc...
magicoder
You are working on a web application that allows users to purchase items from an online store. The code snippet provided is a part of the backend PHP script that handles the insertion of selected items into the shopping cart. The script retrieves the quantity, color, and size of the selected item from a form submitted ...
magicoder
You are given a Python code snippet that demonstrates the behavior of Python's dynamic typing. The code snippet uses the `format` method to print the value of a variable and its corresponding data type. The code snippet is as follows: ```python # 2.a # x = 10 print("{:<21}{}".format("x = 10 :", "Datatypen til x er int...
magicoder
You are tasked with creating a Python function that simulates a simple game of rock-paper-scissors. The function should take two arguments: the player's choice and the computer's choice. The function should then determine the winner based on the standard rules of rock-paper-scissors and return the result. The standard...
magicoder
You are working on a strategy game where players control units called "creeps" that can move around the game world. Each creep has a memory object that stores its destination coordinates (x, y) within a specific room. The game world consists of multiple rooms, and each room can contain other creeps. Your task is to im...
magicoder
You are tasked with implementing a function to simplify a 3D mesh representation using the Douglas-Peucker algorithm. The input to the function is a list of vertices and a list of faces, where each face is represented by the indices of its vertices. The function should simplify the mesh by reducing the number of vertic...
magicoder
You are tasked with implementing a web server route that serves the content of a file named "blacklist.txt" in a specific format. The file "blacklist.txt" contains a list of URLs that are to be blacklisted. Your task is to write a function that reads the content of "blacklist.txt" and serves it with the appropriate con...
magicoder
You are tasked with implementing a simple event listener system in Python. The system should allow objects to register as listeners for specific events and receive notifications when those events occur. You are provided with a partial implementation of the `EventDispatcher` class, which is responsible for dispatching ...
magicoder
You are tasked with creating a Python program to manage a Pokémon database using SQLite. The program should allow trainers to add their Pokémon to the database, retrieve Pokémon information, and update Pokémon levels. The database table `pokemon` has the following schema: ``` CREATE TABLE pokemon ( trainer_id TEXT,...
magicoder
You are tasked with creating a URL dispatcher for a web application using Django. The provided code snippet is a part of the URL configuration in a Django project. The `urlpatterns` list contains a single URL pattern, which maps a URL to a view function. The `url` function is used to define the URL pattern, specifying ...
magicoder
You are tasked with implementing a dropdown menu component for a web application. The dropdown menu should display a list of button elements, each representing a specific value. The dropdown menu should have the following functionality: - When a button is clicked, it should trigger an event to handle the selected value...
magicoder
You are working on a web application that communicates with a server through an API. The code snippet provided defines the base URL for the server's API. Your task is to create a function that constructs the complete URL for a specific endpoint by appending the endpoint path to the base URL. Write a function `construc...
magicoder
You are working on a project that involves handling various flags using a Swift enum. The given code snippet defines a Swift enum `FlagsTwo` with three static properties, each representing a different flag. Each flag is defined using bitwise left shift operations to create unique raw values. Your task is to create a f...
magicoder
You are tasked with creating a program that extracts user information from a code comment block and formats it into a structured output. The code snippet provided is a template for such a comment block, containing placeholders for user's name, email, and version. Write a function or program that takes a string input r...
magicoder
You are tasked with implementing a middleware system for a web scraping application. The middleware system should be able to handle various aspects of the scraping process, such as request statistics tracking, response filtering, retrying failed requests, and setting user agents. Your task is to design a Python class-...
magicoder
You are tasked with creating a program to simulate an ATM cash withdrawal process. The program should prompt the user to input the desired withdrawal amount in Brazilian Reais (R$) and then proceed to dispense the cash using the available denominations of banknotes. The available denominations are 100, 50, 20, 10, 5, a...
magicoder
You are tasked with implementing a custom subclass of `UIView` in Swift that includes a `titleLabel` property of type `UILabel`. The `titleLabel` should be connected to an Interface Builder outlet using the `@IBOutlet` attribute. Additionally, you need to override the `awakeFromNib` method to perform any necessary init...
magicoder
You are tasked with implementing a class that manages the layout of views in a user interface. The class contains methods for pinning a view to the bottom of its superview with optional height constraints. The code snippet provided is a part of this class and demonstrates the implementation of these pinning methods. Y...
magicoder
You are working on a cybersecurity tool that performs entropy analysis on files. Entropy is a measure of randomness or unpredictability in a data set. In this problem, you are tasked with implementing a function to calculate the entropy of a given data set. You need to write a Python function `calculate_entropy(data)`...
magicoder
You are tasked with creating a Python program to extract frames from videos and organize them into a specific folder structure. The program should traverse through a source directory containing video files and extract frames from each video, then save the frames into a destination directory following a predefined folde...
magicoder
You are tasked with creating a Python function that retrieves air quality data from a specific monitoring station using the UK Air Quality API. The function should take a station ID as input and return the air quality data for that station. The UK Air Quality API provides access to air quality monitoring data for vari...
magicoder
You are tasked with creating a program that calculates the running total of a series of numbers. Your program should continuously accept input numbers and update the running total accordingly. The program should terminate when a specific termination value is entered. Your task is to implement a function `calculateRun...
magicoder
You are tasked with implementing a function that calculates the total number of ways to reach the top of a staircase. You can climb the staircase by either taking 1 or 2 steps at a time. Write a function `countWaysToTop` that takes an integer `n` as input, representing the total number of steps in the staircase, and re...
magicoder
You are tasked with implementing a program that can analyze the frequency of words in a given text. Your program should take a string of text as input and return a dictionary containing the frequency of each word in the text. For the purpose of this problem, a word is defined as a sequence of characters separated by sp...
magicoder
You are given a file named "data.txt" containing tab-separated values. Each line in the file represents a list of integers. Your task is to write a Python function to find the minimum value in each list and return a list of these minimum values. The code snippet provided reads the data from "data.txt" using the csv mo...
magicoder
You are tasked with implementing a custom XML parser to extract and process data from a specific XML structure. The XML structure consists of nested elements, and your goal is to extract the content within certain tags and perform specific operations on the extracted data. Given the following XML snippet: ``` <Spreads...
magicoder