instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are given a partially completed JavaScript function that is intended to find the maximum value in an array of integers. However, the function is incomplete and contains some errors. Your task is to complete the function and fix the errors to ensure that it correctly returns the maximum value from the input array. ...
magicoder
You are tasked with implementing a function to calculate the sum of all prime numbers within a given range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Your function should take two integers, `start` and `end`, as input and return the sum of all prime numbers...
magicoder
You are tasked with implementing a simplified version of a particle simulation algorithm. The algorithm operates on a list of particles, each represented by a position and velocity. The algorithm updates the position of each particle based on its current position and velocity. The provided code snippet is a part of the...
magicoder
You are tasked with creating a program that processes data from a file called "myouji". The "myouji" file contains a list of last names, each on a separate line. Your program needs to read the contents of the "myouji" file, process the last names, and then perform specific operations based on the data. Your task is t...
magicoder
You are working on a project that involves low-level memory manipulation in Swift. You need to understand and utilize pointer conversions to achieve the desired functionality. In Swift, pointers are used to interact with C APIs or perform low-level memory operations. The code snippet provided demonstrates the usage of ...
magicoder
You are tasked with creating a custom exception handler for a web automation framework. The framework uses Selenium WebDriver to interact with web elements and perform actions. The provided code snippet is a part of the exception handling mechanism for a specific WebDriverException. Your task is to implement a custom ...
magicoder
You are tasked with implementing a function that processes a list of strings representing different sections of a document. The function should rearrange the sections in a specific order and return the modified list. The desired order is as follows: "Introduction", "Methods", "Results", "Discussion", "Conclusion", "Ref...
magicoder
You are given a Python code snippet that is intended to perform a specific operation. However, the code contains a logical error that needs to be identified and fixed. Your task is to analyze the code, identify the issue, and correct it to ensure the intended operation is performed correctly. The given code snippet is...
magicoder
You are tasked with implementing a Python function that calculates the duration between two given timestamps. The function should take two parameters, `start` and `end`, representing the start and end timestamps, and return the duration between them in seconds. The timestamps will be provided in the format of Python's...
magicoder
You are tasked with implementing a Redux reducer function that manages the state of selected mages in a fantasy-themed application. The state is represented as an object with a `mageIds` array, and the reducer should handle actions to toggle the selection of mages. Additionally, the reducer should return a model and a ...
magicoder
You are given a Python code snippet that imports various libraries and reads a CSV file named "diabetes_csv.csv" using the pandas library. The code snippet also replaces the values 'tested_negative' with 0 and 'tested_positive' with 1 in the DataFrame. However, the code snippet contains commented lines and does not uti...
magicoder
You are tasked with creating a unit testing framework for a software project. As part of this framework, you need to implement a method that creates a mock object for a given type `T` and a specified behavior. The method should return the mock object and also store it in a variable for further usage. Write a method `C...
magicoder
You are tasked with implementing a simple animation system for a social media platform. The platform has a component called `PostCardComponent` responsible for displaying individual posts. Your goal is to create a fade-in animation for the `PostCardComponent` using Angular animations. The `PostCardComponent` class is ...
magicoder
You are tasked with implementing a simple React component that simulates a Mac-style window with traffic light buttons. The component should accept a `darkMode` prop to determine the color scheme and should render the children components within the window. Your task is to complete the implementation of the `MacWindow`...
magicoder
You are tasked with creating a test case for a PHP Laravel application. The application includes a class `Ouvidoria` that is responsible for handling feedback and complaints. The test case is aimed at ensuring that the `Ouvidoria` class can retrieve feedback based on a correct protocol number. Your task is to implemen...
magicoder
You are tasked with implementing a simple configuration system for a chat bot used in a gaming guild. The configuration system should allow guild members to customize certain settings, such as the bot's command prefix and log filters. You are provided with a partial implementation of the `GuildConfig` struct and its d...
magicoder
You are tasked with implementing a program that simulates a simple ASCII art animation of a bouncing ball. The ball will move up and down within a defined space, and the animation will continue for a specified number of iterations. The ball will be represented by the character 'O', and the space will be represented by...
magicoder
You are tasked with creating a Django migration for a new model in a web application. The model represents a simple online store product, with fields for the product's name, price, and quantity in stock. Your goal is to write the migration file that will create the corresponding database table for this model. The mode...
magicoder
You are tasked with implementing a function that processes a given path and returns the concatenated subpaths in the correct order. The input path is represented as a list of tuples, where each tuple contains a move and a position. The moves can be either `Path.LINETO` or another move type, and the positions are repres...
magicoder
You are tasked with creating a program that reads a text file and counts the occurrences of each word in the file. Your program should ignore punctuation and consider words with different capitalization as the same word. You should then output the unique words along with their respective counts in alphabetical order. ...
magicoder
You are tasked with creating a program that extracts the domain name from a given URL. The domain name is the sequence of characters between the first double forward slash ("//") and the next single forward slash ("/") or the end of the URL. For example, in the URL "http://www.example.com/index.html", the domain name i...
magicoder
You are tasked with implementing a Python function that simulates the behavior of the `setns` function from the `butter.clone` module. The `setns` function is used to associate the calling process with the namespaces of another process. The function takes an integer file descriptor `fd` as its argument. Your task is t...
magicoder
You are tasked with implementing a function that calculates the total area of rectangles in a given list. Each rectangle is represented by an object with the following properties: `x`, `y`, `width`, and `height`. The function should return the sum of the areas of all the rectangles in the list. Function Signature: `fu...
magicoder
You are tasked with implementing a custom slider component in a web application. The slider component should have the following properties and methods: Properties: - `thumpPadding`: A private property representing the padding around the slider thumb. - `thumbColor`: A private property representing the color of the sli...
magicoder
You are tasked with implementing a network traffic monitoring system. The system should track the start times of connections between network ports and capture snapshots of the traffic for different services. You are given a code snippet that connects network ports and records the event of a connection being built. You...
magicoder
You are tasked with implementing a function to determine the number of occurrences of a given word in a given text. The function should be case-insensitive and should consider only whole word matches. A word is defined as a sequence of alphanumeric characters or underscores, delimited by non-alphanumeric characters or ...
magicoder
You are tasked with implementing a Python class that performs table operations and generates a Markdown representation of the table. The class should have methods to add columns, add rows, and generate the Markdown representation of the table. Your task is to implement the `Table` class with the following specificatio...
magicoder
You are tasked with implementing a paging algorithm for a collection of user data. The given code snippet is a part of a method that retrieves a paged list of users from a data source. The method chains several LINQ operations to order the users by name and surname, then applies paging and finally retrieves the paged r...
magicoder
You are tasked with implementing a feature for a mobile advertising plugin called `nend_plugin`. The feature involves creating a class called `UserFeature` in the file `UserFeature.swift`. The `UserFeature` class should have a method `fetchUserDetails` that makes a network request to retrieve user details from a remote...
magicoder
You are working on a multilingual web application that needs to support language localization. You have been given a PHP array containing key-value pairs for translating English words or phrases into Vietnamese. Your task is to write a function that takes an English word or phrase as input and returns its Vietnamese tr...
magicoder
You are tasked with creating a script to manage the configuration of a custom prompt for a shell environment. The script should allow users to define and modify various settings for the prompt, such as directory classes, prefix, and version control system (VCS) colors. Your task is to implement a function `updatePromp...
magicoder
You are tasked with implementing a function that processes a given string to extract and return all the sentences present in the string. A sentence is defined as a sequence of words ending with a punctuation mark (., !, or ?). The function should ignore any punctuation marks within the words and should not consider abb...
magicoder
You are tasked with creating a program that reads input data from a file, processes it, and then writes the processed data to an output file. The input data is in the form of command-line arguments, where the first argument is the input file name and the second argument is the output file name. The program should handl...
magicoder
You are tasked with creating a program that fetches real-time cryptocurrency price data from different API endpoints and extracts specific information from the responses. The program should be able to handle multiple API endpoints and extract the required data based on the provided keys. You are given a list of API en...
magicoder
You are tasked with creating a web application that displays a list of accounting records in a table format. The application uses the Laravel framework and the Blade templating engine. The provided code snippet is a part of the Blade template file that generates the HTML for displaying the accounting records. The `acc...
magicoder
You are tasked with implementing a simple Node class in Python to represent nodes in a tree data structure. The class should have the following properties and methods: Properties: 1. `node_name`: A read-only property that returns the name of the node. 2. `node_id`: A read-only property that returns the unique identifi...
magicoder
You are tasked with creating a custom collection class in PHP that extends a provided abstract collection class. Your custom collection class should implement a method to filter the collection based on a specific condition. Your custom collection class should extend the abstract collection class `\Magento\Framework\Mo...
magicoder
You are tasked with creating a custom token type for a multi-token standard library in Rust. The provided code snippet declares a public type alias `MTTokenType` for the `multi_token_standard` crate's `TokenType`. Your task is to implement a custom token type that extends the functionality of the existing `multi_token_...
magicoder
You are tasked with creating a Django model for a school's student database. The model should include information about students, their respective generations, and their email addresses. Your task is to define the necessary Django model classes and fields to represent this data structure. Define the following Django m...
magicoder
You are tasked with creating a program that processes a series of log messages and extracts specific information from them. Each log message is a string containing various pieces of information, and your program needs to extract a particular substring from each message. The log messages have the following format: ``` ...
magicoder
You are tasked with implementing a mock object for testing a form builder class in a PHP application. The form builder class allows setting and getting form actions. The provided code snippet is a part of the test case for the form builder class using the Mockery library. Your task is to write a method that creates a ...
magicoder
You are tasked with designing a Python decorator that logs the HTTP methods and the endpoint of a Flask route. The decorator should be able to handle both routes with and without a specified account ID. The decorator should also require normal permission to access the route. Design a Python decorator function `route_l...
magicoder
You are tasked with creating a Python program that simulates a simple game of rock-paper-scissors. The program should allow a user to play against the computer and keep track of the score. The game should continue until the user decides to quit. Your program should follow these rules: - The computer should randomly se...
magicoder
You are tasked with implementing a function to generate a slugified label for a given section and label. The slugified label should be in the format "sec:word", where "sec" is the section and "word" is the label, both converted to lowercase and with spaces replaced by underscores. Additionally, any non-alphanumeric cha...
magicoder
You are tasked with designing a file download manager in Android that utilizes OkHttp for downloading files. Your goal is to implement a solution that ensures the file downloads occur in a background thread to prevent blocking the main UI thread. Your task is to create a class that manages file downloads using OkHttp ...
magicoder
You are tasked with creating a program to manage student data. The program should provide a menu with options to add, edit, view student data, and exit. When the user selects the "Add student data" option, they are prompted to input the number of students' data they want to enter. Then, for each student, the program sh...
magicoder
You are given the definition of a binary tree node and a method to calculate the sum of all nodes in the tree. Your task is to implement the `sumOfNode` method and then modify the `sumOfNode` method to calculate the sum of all nodes in the tree and store the result in the variable `ans`. Finally, return the value of `a...
magicoder
You are tasked with implementing a reward system for a game. The `reward_spec` method is used to retrieve the specifications for the rewards. The `rewards_spec` variable is assigned the result of calling the `reward_spec` method. Your task is to create a class that manages the reward system and implements the `reward_s...
magicoder
You are tasked with implementing a method to bind data to a `GroupedRecordListItemViewHolder` in an Android application. The `GroupedRecordListItemViewHolder` class is responsible for displaying a single item in a grouped record list. The class contains a `TextView` member variable `mTitleTextView` that represents the ...
magicoder
You are tasked with creating a Django REST framework view for managing the stock of raw materials in a manufacturing plant. Your task is to implement a custom view that allows for the creation, retrieval, updating, and deletion of raw material stock data. The view should be designed to handle HTTP methods such as GET, ...
magicoder
You are tasked with creating a PHP script that processes a list of awards and displays them in a visually appealing manner. The awards should be displayed in a container with a fixed height, and any overflow should be truncated with an ellipsis. Additionally, the awards should be displayed in a single line, and if ther...
magicoder
You are given a C++ code snippet that involves parsing a value from an XML attribute and using it to set parameters for a transformation. Your task is to write a function that performs a similar operation in a more generalized context. Write a function `parseAndSetParameters` that takes in a string `attributeValue` an...
magicoder
You are tasked with implementing a custom comparator function in JavaScript to sort an array of objects based on a specific property. The custom comparator should be concatenated into the array and used to sort the objects based on the specified property. You are given an array of objects, where each object represents...
magicoder
You are working on a data processing script that involves writing data to a CSV file. The script uses the `csv` module in Python to write a dictionary of data to a CSV file. However, you notice that the script seems to be taking longer than expected to complete the writing process. You suspect that the `csv.DictWriter`...
magicoder
You are tasked with implementing a simple data binding mechanism in a C# application. The application has a view model (`Vm`) with a property `Name`, a text box `_myEdit`, and a button `_myButton`. Your goal is to create the necessary code to bind the `Name` property to the text box in a two-way binding mode and to set...
magicoder
You are given an array A of integers. Your task is to write a function that finds the maximum value in the array using a specific approach. Write a Python function called `find_max_value` that takes in a list of integers A and returns the maximum value in the array using the following approach: - Use a generator expre...
magicoder
You are tasked with implementing a custom table view cell for a shopping app called ClosedMart. The cell should display the user's favorite item, including the item's name, price, and an image. You are provided with a starter code for the `FavoriteTableViewCell.swift` file, which you need to complete. Your task is to ...
magicoder
You are tasked with implementing a simple task scheduler for a mobile application. The scheduler should allow users to schedule tasks to be executed when the application becomes active and to cancel scheduled tasks when the application resigns its active state. You are provided with a Swift class `TaskScheduler` that ...
magicoder
You are tasked with implementing a generic archiving function in Swift that can archive any encodable data and then call a callback function with a report object upon successful archiving. Your task is to complete the implementation of the `archive` function and ensure that the callback is invoked with the appropriate ...
magicoder
You are tasked with implementing a custom gated recurrent neural network (GRU) cell in TensorFlow for a natural language processing task. The GRU cell will incorporate a Simple Recurrent Neural Network (SCRN) architecture, which involves the use of specific parameters and operations. The code snippet provided outlines...
magicoder
You are tasked with implementing a text processing function that cleans and manipulates input strings according to specific rules. The function should perform two operations: `cleartext` and `clean`. The `cleartext` function takes a string as input and removes any text after the first occurrence of the '/' character, ...
magicoder
You are tasked with implementing a JSON parser that can handle parsing and extracting values from a JSON string. Your parser should be able to handle parsing boolean values and floating-point numbers, and provide methods to access these values from the parsed JSON object. Write a class `JSONParser` with the following ...
magicoder
You are working on a project to develop a groundwater model using the GSFLOW model. The GSFLOW model is a coupled groundwater and surface-water flow model based on the integration of the Precipitation-Runoff Modeling System (PRMS) and the Modular Groundwater Flow Model (MODFLOW). As part of this project, you need to im...
magicoder
You are tasked with creating a Bash script that retrieves information about GitHub repositories and displays the top repositories based on the number of stars they have. The script should utilize the GitHub API to fetch the data and then process it to present the desired output. Your task is to complete the Bash scrip...
magicoder
You are tasked with creating a Python function that generates a multiworld preset for a video game tournament. The function should be asynchronous and take in several parameters to customize the preset. The function should also fetch the preset details from an external source using the `fetch_preset` function, which is...
magicoder
You are working on a deployment automation script for a containerized application. The script is responsible for setting up the necessary environment variables and paths for the application's Docker container. You need to implement a function that takes in various details and generates a configuration dictionary for th...
magicoder
You are tasked with implementing a text translation service using PHP. The `TextRepository` class provides methods for managing and retrieving translations. Your goal is to create a method that retrieves the translation of a given brief in a specified language. If the brief does not exist, an empty string should be ret...
magicoder
You are tasked with creating a logging system for a software application. The application needs to log different types of errors to separate log files based on their severity. You have been provided with a Python code snippet that initializes a logger for logging errors related to the Sentry client. Your task is to ext...
magicoder
You are tasked with creating a class that manages AI services and their deployment plans. The class should provide methods to retrieve information about AI services and their deployment plans. You need to implement a class called `AIServiceManager` with the following methods: 1. `GetAllAsync`: This method should take...
magicoder
You are tasked with creating a Node.js module that initializes an Algolia search client using environment variables for the API key and application ID. Additionally, the module should have a default setting for the "lite" option. Your task is to complete the implementation of the module by setting the "lite" option to ...
magicoder
You are given a matrix `M` representing the friend relationships between students in a class. If `M[i][j] = 1`, then student `i` and student `j` are friends. The matrix is symmetric, meaning if `M[i][j] = 1`, then `M[j][i] = 1`. Your task is to implement a function `findCircleNum` to find the total number of friend ci...
magicoder
You are tasked with developing a data processing pipeline for creating shards of data samples for a machine learning project. The code snippet provided contains assertions and variable assignments related to the configuration of the data processing pipeline. Your task is to implement a function that validates the confi...
magicoder
You are tasked with implementing a game management system using Python and Django. The system includes a function that retrieves a game object based on the provided game ID. However, the function needs to perform certain checks before returning the game object. Below is the code snippet for the function: ```python if ...
magicoder
You are given a string `S` consisting of lowercase English letters. Your task is to find the number of distinct non-empty subsequences of `S`. A subsequence of a string is a new string that is formed from the original string by deleting some (or none) of the characters without changing the relative order of the remain...
magicoder
You are tasked with creating a Python class that manages connections to MongoDB using the Mongoengine library. Your class should provide methods for establishing connections and retrieving connection details in a secure manner. Create a Python class called `MongoDBManager` with the following requirements: - The class ...
magicoder
You are tasked with implementing a function that calculates the total cost of shipping packages based on their weight and destination. The function should take in three parameters: a list of package weights, a list of destination codes, and a dictionary of shipping rates. The shipping rates dictionary contains destinat...
magicoder
You are working on a computer vision project and have been tasked with analyzing the performance of different models on a specific dataset. The performance metrics are provided in a tabular format as shown below: | Model | Dataset | Input Size | Precision (mAP) | Recall (mAR) | F1 Score | Accuracy (mACC...
magicoder
You are tasked with creating a program that analyzes a given source code file to count the occurrences of specific license-related comments. In this problem, you are to focus on counting the occurrences of the phrases "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE" and "GNU General Public License" within the comm...
magicoder
You are tasked with creating a PHP class that interacts with a database to retrieve system configuration information. The provided code snippet is a partial implementation of the `System` class, which extends the `Commons` class and is located in the `app\common\model` namespace. The class contains a method `systemBase...
magicoder
You are tasked with creating a program that can determine the specificity of CSS selectors. In CSS, specificity is a weight that is applied to a given CSS declaration, determining which styles are ultimately applied to an element. The specificity is calculated based on the components of a selector. The components are r...
magicoder
You are working on a web application that includes a module for managing equity token offerings (ETOs). The code snippet provided is from the backend of the application, written in TypeScript. The snippet includes imports for specific modules and functions related to ETOs. Your task is to implement a function that retr...
magicoder
You are tasked with implementing a function that takes an array of React Native component names and returns a new array containing only the unique component names in alphabetical order. You should ignore case sensitivity when comparing component names. The function signature is: ```javascript function uniqueComponentN...
magicoder
You are working on a web scraping project to extract information about products from an e-commerce website. The given code snippet is a part of the web scraping script and is responsible for extracting specific details about each product. Your task is to complete the script by implementing the missing functionality to ...
magicoder
You are tasked with implementing a custom dataset class for a computer vision project. The dataset is called "StandfordBackgroundDataset" and is a subclass of "CustomDataset". The dataset contains images with segmentation maps, and it has three classes: "background", "stone", and "border". The palette for the segmentat...
magicoder
You are working on a data analysis project and need to process a tab-delimited data file using Python. The file contains several columns, but you are only interested in columns 0, 1, 2, and 4. You have a class method that reads the data from the file and returns a pandas DataFrame with the specified columns. Additional...
magicoder
You are tasked with creating a Vue.js component for a customer portal that handles the registration process for a business internet service called "BiznetWifi". The component is intended to be included in a larger Vue.js application and will be used to facilitate the registration process for customers. The provided co...
magicoder
You are tasked with implementing a function that calculates the new position of an object in 3D space based on user input from sliders. The function takes the current position of the object (`m_vecPosBackup`) and the values obtained from three sliders (`m_pSliderPosX`, `m_pSliderPosY`, `m_pSliderPosZ`). Each slider's v...
magicoder
You are tasked with creating a Django view that handles the upload of images and videos to a web application. The view should validate the uploaded files and save them to the appropriate models in the database. The `Gallery` model is used to store images, while the `Video` model is used to store videos. You need to imp...
magicoder
You are tasked with implementing a generic memory-mapped I/O (MMIO) structure in Rust. The MMIO structure should support reading and writing to a memory-mapped register. Additionally, you need to implement the `Debug` trait for the MMIO structure to allow for debugging and visualization of the register's value. Your t...
magicoder
You are tasked with creating a script to automate the validation and publishing process of a CocoaPod. The script should perform the following tasks: 1. Run the command `pod spec lint ./AzureNotificationHubs-iOS.podspec` to validate the CocoaPod specification file `AzureNotificationHubs-iOS.podspec`. 2. Capture the ou...
magicoder
You are tasked with creating a script that automates the process of updating a GitHub pull request (PR) with the output of a Terraform plan as a comment. The script will take a JSON payload as input and use the `jq` command-line tool to extract specific data from it. The extracted data will then be used to form a reque...
magicoder
You are tasked with implementing a custom base58 encoding function in JavaScript. Base58 encoding is commonly used in cryptocurrency addresses and other applications where a compact human-readable representation of large numbers is required. The base58 encoding scheme is similar to base64 encoding but excludes characte...
magicoder
You are tasked with implementing a function that simulates a simplified version of the game "Rock, Paper, Scissors". The function should take two arguments representing the choices of two players and determine the winner based on the following rules: - Rock beats Scissors - Scissors beats Paper - Paper beats Rock The ...
magicoder
You are tasked with implementing a function that processes a list of enrollees and updates their contact information based on a set of rules. Each enrollee is represented as an object with properties for their given names, date of birth, verified address, phone, and email. The function should update the phone and email...
magicoder
You are tasked with implementing a custom button class in Swift that includes a feature to display an unread message count label. The custom button class should have the following requirements: - It should be a subclass of `UIButton`. - It should have a private property `unreadLabel` of type `UILabel` to display the un...
magicoder
You are tasked with implementing a web scraping utility that can navigate through paginated results on a website. The utility provides a method `SetNextLinkXPath` to set the XPath expression for locating the link to the next page of results. The XPath expression should return the string URL of the next page, and it sho...
magicoder
You are tasked with implementing a simplified version of a message processing system. The system receives messages containing various attributes such as `bodyVariable`, `headers`, `method`, `queryParams`, and `path`. Your goal is to write a function that processes these messages according to the following rules: 1. If...
magicoder
You are tasked with implementing a function that decodes a hash value to retrieve a category ID for an allegation view in a web application. The hash value is encoded using a custom utility class `MobileUrlHashUtil` and is passed as a parameter to the `get_redirect_url` method of the `AllegationView` class. Your task i...
magicoder
You are given a function `reverseString` that takes a string `s` as input and returns the reversed version of the string. However, the implementation of the function is missing. Your task is to complete the `reverseString` function using any programming language of your choice. Complete the `reverseString` function to...
magicoder
You are tasked with implementing a simplified version of a task management system in Python. The system consists of a Task class and an Assistant class. The Task class represents a specific task with a name, reward, and completion status. The Assistant class represents an assistant that can perform tasks and receive re...
magicoder