instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with implementing a Redux slice for a cryptocurrency swapping feature. The provided code snippet includes the definition of a Redux slice for handling swapping actions and a reducer function. The slice contains action creators for setting the amount, token, swapping inputs, setting a dialog, and clearing...
codefeedback
You are tasked with implementing a Python class that acts as a rate limiter for making HTTP requests. The rate limiter should prevent making more than a certain number of requests within a specified time frame. If the limit is exceeded, the rate limiter should raise a custom exception. Additionally, the rate limiter sh...
codefeedback
You are tasked with creating a Python function that simulates a random word requester. The function should retrieve a random word and its definition from a MongoDB database and log the timestamp of the access. You are required to implement the function `random_word_requester` that accomplishes the following: - Access ...
codefeedback
You are tasked with implementing a Swift protocol and its associated types and methods. The protocol `P` has an associated type `f` and a nested protocol `A`. Protocol `A` has an associated type `B` and a method `a`. Your goal is to create the protocol `P` and its nested protocol `A`, along with their associated types ...
codefeedback
You are tasked with implementing a Python class to represent a specific type of monoid operation. A monoid is a mathematical structure consisting of a set of elements and an associative binary operation that combines any two elements of the set to produce another element from the same set. In this problem, you will cre...
codefeedback
You are tasked with implementing a priority queue for data creation and removal. The priority queue should be able to manage different data creation actions based on their priority for creation and removal. You are given a code snippet that defines a `DataCreatorAction` class. This class represents an action for creat...
codefeedback
You are tasked with implementing a simplified version of a dependency injection container in C#. The container should be able to resolve and instantiate registered types based on their dependencies. Your task is to create a class called `DependencyContainer` with the following requirements: - The container should be a...
codefeedback
You are tasked with creating a Discord bot that can cycle through different statuses and perform specific actions when it becomes ready. The bot should be able to change its status at regular intervals and execute additional tasks upon initialization. Your goal is to implement the necessary functionality to achieve thi...
codefeedback
You are tasked with creating a program that manages a simple inventory system using Python's `shelve` module. The program should allow users to add, remove, update, and display items in the inventory. Additionally, the program should support command-line arguments using the `argparse` module for specifying the inventor...
codefeedback
You are tasked with implementing a custom data structure called `UniqueStack` that behaves like a stack but only allows unique elements to be stored. The `UniqueStack` should support the following operations: 1. `push(element)`: Add an element to the top of the stack if it is not already present in the stack. 2. `pop()...
codefeedback
You are given a Python code snippet that simulates a process of selecting coins to reach a target sum. Your task is to implement a function that achieves the same functionality as the code snippet. You need to implement a Python function `select_coins(coins, target)` where: - `coins` is a list of objects representing ...
codefeedback
You are given a list of reputation scores of players in a game, represented by the list `reputacoes_dos_jogadores`. The reputation scores are floating-point numbers. The code snippet provided is a part of a program that attempts to round the reputation scores to a certain number of decimal places. However, there seems ...
codefeedback
You are tasked with creating a Python class that represents a political candidate for an election. The class should have attributes to store the candidate's name, party affiliation, and a list of elections they are participating in. Additionally, the class should have a method to add a new election to the candidate's l...
codefeedback
You are tasked with creating a program that simulates a simple game of dice rolling. The game consists of the following rules: - The player starts with a score of 0. - The player rolls a six-sided die, and the number rolled is added to their score. - If the player rolls a 6, they get an extra turn and the score from th...
codefeedback
You are tasked with implementing a Python function that processes data for training a machine learning model. The function takes in several parameters and performs various operations based on the input. Your task is to complete the implementation of the function by filling in the missing parts. The function `process_d...
codefeedback
You are tasked with implementing a simplified version of a data access layer for a social media application. The provided code snippet outlines two methods of an interface for accessing user-related data. The `count` method is used to retrieve the total count of a specific user's data, while the `findPage` method is us...
codefeedback
You are tasked with implementing a class that represents a simple JSON parser. Your class should be able to parse a JSON string and convert it into a corresponding object structure. For this problem, you need to implement the parsing logic for the JSONConstructor attribute, which is used to annotate a constructor to sp...
codefeedback
You are tasked with creating a Python script to automate the generation of data for training a Keras deep learning model. The script should take input parameters and use them to generate the necessary data for training the model. Your task is to write a Python script that takes a list of input parameters and uses them...
codefeedback
You are tasked with creating a Python function that interacts with the Azure API to send requests. Your function should be able to handle different types of requests and return the response from the Azure service. You will need to implement the `azure_request` function, which takes in four parameters: `command` (string...
codefeedback
You are tasked with implementing a swipe actions view for a mobile application. The swipe actions view allows users to perform actions by swiping left or right on a cell in a table or collection view. The provided code snippet includes a partial implementation of the `SwipeCellActionView` class and a protocol `SwipeAct...
codefeedback
You are tasked with implementing a Python function that performs a database migration. The function should handle both the upgrade and downgrade of a database schema. The upgrade_domain function should take in the following parameters: - table_name: A string representing the name of the table to be modified. - old_doma...
codefeedback
You are tasked with creating a custom derive macro for a simple XML serialization library in Rust. The library provides the `XmlRead` and `XmlWrite` traits for deserializing and serializing XML data, and the goal is to implement a custom derive macro for a struct that will automatically generate the necessary XML seria...
codefeedback
You are tasked with creating a script to process a log file and extract specific information from it. The log file contains lines of the format "echo <number> >> <path>", where <number> is a sequence of digits and <path> is a file path. Your script should read the log file and calculate the total sum of all the numbers...
codefeedback
You are tasked with creating a multi-threaded program to process a queue of JSON objects. The program should use Python's `concurrent.futures.ThreadPoolExecutor` to concurrently process the JSON objects in the queue. Each JSON object represents a task that needs to be executed, and the processing involves parsing the J...
codefeedback
You are tasked with creating a message listener function for a ticketing system. The function should update the `userId` of a ticket and acknowledge the message once the update is complete. You are provided with a code snippet that sets up the necessary components for testing the message listener function. Your task i...
codefeedback
You are tasked with creating a Rust function that simulates a simplified file permission adjustment process. The function `chownr` takes an absolute file path as input and attempts to change the ownership of the file and its contents to the current user. The function uses asynchronous programming and relies on external...
codefeedback
You are tasked with creating a Discord bot that periodically updates its status to reflect the number of servers it is active in and the total number of users across all those servers. To achieve this, you need to implement a function that updates the bot's status at regular intervals. Write a Python function `update_...
codefeedback
You are tasked with implementing a function that reshapes a given input array into a specified shape. The function should also handle the case where an output array is provided, ensuring that it has the same shape as the input array. Additionally, the function should raise appropriate exceptions if the provided output ...
codefeedback
You are tasked with creating a program to guide a character through an island to collect gems. The island is represented as a grid, and the character can move forward, turn right, collect gems, and use portals to teleport to different locations on the island. The character starts at a specific location and needs to fol...
codefeedback
You are tasked with creating a Python program that logs the start and end times of a main function, and also optionally logs a message if the program runs in verbose mode. Your program should also be able to profile the main function using Python's built-in profiling module. Your program should have the following feat...
codefeedback
You are tasked with implementing a Python class that handles paginated API responses and enforces a maximum results limit. The class, named `PaginatedAPIHandler`, has the following attributes and methods: Attributes: - `MAX_RESULTS_LIMIT`: An integer representing the maximum number of results allowed. Methods: - `fet...
codefeedback
You are tasked with implementing a function that processes an array of messages and returns the indices of the newly added messages. The function should handle the case when the input array is empty. You are given the following code snippet as a starting point: ```swift /// 数组为空 guard let last = array.last else { ...
codefeedback
You are tasked with creating a program that processes video frames and overlays text onto the frames. The provided code snippet is a part of a larger program that processes video frames and adds the score of an object detection algorithm to the top left corner of each frame. The variable `b` represents an object contai...
codefeedback
You are tasked with implementing a Python class for creating Segregated Witness (SegWit) transactions, a feature introduced in Bitcoin to address scalability and transaction malleability issues. SegWit transactions separate the witness data (signatures) from the transaction data, allowing for more efficient use of bloc...
codefeedback
You are tasked with implementing a file management system that involves cleaning file names to ensure compatibility with Windows-style paths. Your goal is to create a function that takes a file name as input and returns the cleaned version of the name, ensuring that it is compatible with Windows-style paths. You are p...
codefeedback
You are tasked with creating a WebSocket-based multiplayer game server for Connect 4. The provided code snippet is a configuration for the server's routing using Django Channels, a package that extends Django to handle WebSockets, chat protocols, and other asynchronous features. The `application` variable is a Protoco...
codefeedback
You are tasked with creating a function that takes two non-negative integers as arguments and returns their sum in binary form. The binary sum should be a string. Create a function `add_binary` that takes two non-negative integers `a` and `b` as input and returns their sum in binary form. For example: - `add_binary(1...
codefeedback
You are given a string `s` consisting of lowercase English letters. Your task is to find the length of the longest substring that contains at most two distinct characters. Write a function `longestSubstring` that takes in a string `s` and returns the length of the longest substring with at most two distinct characters...
codefeedback
You are tasked with creating a web application for managing subscriptions, subscription types, customers, and projects. The given code snippet is a part of the backend logic for retrieving data from the database based on the user's tenant ID. The code uses a PHP framework with a database abstraction layer, and it seems...
codefeedback
You are tasked with creating a web scraping program to extract data from a website. Your program should utilize Python's Scrapy framework to parse a webpage and extract specific information. In this scenario, you are required to extract the UUID, timestamp, and URL of the webpage. Your task is to complete the `parse` ...
codefeedback
You are tasked with implementing a command-line interface (CLI) function that allows users to choose from a list of examples. The function should display the available examples and prompt the user to select one. If the user chooses an example, the function should return the selected example. If the user chooses to quit...
codefeedback
You are tasked with implementing a Python function that retrieves a list of all available drivers and their details from a transportation management system. The function should handle various scenarios, including cases where no drivers are available. Additionally, you need to write unit tests to ensure the correctness ...
codefeedback
You are tasked with implementing a secure keychain manager for a mobile application. The keychain manager should provide methods for saving and retrieving sensitive data, such as access tokens, securely in the device's keychain. The keychain manager should handle errors gracefully and provide informative messages to th...
codefeedback
You are tasked with implementing a function that manipulates socket options in a networking application. The function will take in a raw socket, a protocol constant, an option constant, and a mutable pointer to an option value, and it will return a boolean indicating whether the operation was successful or not. The fu...
codefeedback
You are tasked with creating a program that utilizes the `SyntacticSimplifier` module to simplify a given syntactic expression. The `SyntacticSimplifier` module provides a method `simplify_expression` that takes a syntactic expression as input and returns the simplified form of the expression. The simplified expression...
codefeedback
You are tasked with simulating a drag-and-drop functionality in a web application using JavaScript. Your goal is to implement the `makeDnd` function, which takes the following parameters: - `mouse`: An object representing the mouse interaction capabilities. - `sourceIndex`: The index of the source element to be dragged...
codefeedback
You are tasked with implementing a dynamic programming solution to find the length of the longest common subsequence (LCS) of two given strings. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. For example, "ace"...
codefeedback
You are tasked with implementing a simple RSA encryption and decryption program. The program should take user input for a message to be encrypted, generate public and private keys, encrypt the message using the public key, and then decrypt the encrypted message using the private key. Your task is to complete the imple...
codefeedback
You are tasked with creating a plugin for a Minecraft server using the Bukkit API. The plugin needs to handle a custom command that allows players to check their in-game currency balance. The currency system is managed by another part of the server and is accessible through an external API. Your plugin should be able t...
codefeedback
You are working on a data visualization project and need to create a program that generates a plot with two subplots. The first subplot will display a line plot of a time series data set, while the second subplot will display a line plot of the Mean Squared Error (MSE) values. The code snippet provided below is a part ...
codefeedback
You are working on a computer vision project and need to convert Bayer-encoded images to grayscale using OpenCV. The Bayer encoding pattern is a popular method for capturing color information in a single sensor array. OpenCV provides constants for converting Bayer-encoded images to grayscale, but the encoding pattern u...
codefeedback
You are tasked with implementing a featurization and correlation analysis tool for a text dataset. The provided code snippet is a part of a Python script that performs featurization, correlation computation, and filtering of top n-grams based on their correlations. Your task is to implement the `Featurizer` class and ...
codefeedback
You are tasked with implementing a Python function that simulates a simplified version of a gradient descent optimization algorithm. The function takes in several parameters and performs a series of operations on the gradients and parameters to update the model weights. Your task is to complete the implementation of th...
codefeedback
You are tasked with creating a Python class that manages user authentication and authorization for a web application. The class should utilize Flask-Login and itsdangerous libraries to handle user sessions and remember me functionality. Additionally, the class should interact with a user service proxy and an organizati...
codefeedback
You are tasked with implementing a function that generates HTML code for a customizable component. The function should take in several parameters to customize the appearance and content of the component. The HTML code should be generated based on the provided parameters. The function signature is as follows: ```javasc...
codefeedback
You are tasked with implementing a class to simulate a simple computer mouse. The class should provide methods to retrieve the current vertical scroll position and the status of the mouse buttons. Your task is to create the `Mouse` class with the specified methods and then use it to solve a given scenario. Create a cl...
codefeedback
You are tasked with implementing a keyboard shortcut manager for a web application. The manager should allow users to define custom keyboard shortcuts and associate them with specific actions within the application. Your task is to create a class `ShortcutManager` with the following functionalities: 1. `addShortcut(k...
codefeedback
You are tasked with implementing a Java method to convert a transit map into a JSON object. The transit map is represented as a graph, where each node represents a location and each edge represents a transit route between two locations. The method should take the transit map as input and produce a JSON object that repr...
codefeedback
You are given a Python code snippet that manipulates a deque `d` and a variable `max`. A deque is a double-ended queue, which is a data structure that allows insertion and deletion at both ends. The code snippet performs a series of operations on the deque `d` and the variable `max` based on certain conditions. Your ta...
codefeedback
You are given an array of integers. For each element in the array, you need to find the count of elements to its right that are smaller than the current element. Your task is to implement a function `mapToTotalSmallerElementToTheRight` that takes in an array of integers and returns a new array where each element repres...
codefeedback
You are tasked with implementing a custom mapper interface for a water station order detail entity in a Java application. The `SsWaterstationOrderDetailMapper` interface extends the `BaseMapper` interface and is responsible for mapping data between the `SsWaterstationOrderDetail` entity and the underlying data storage....
codefeedback
You are tasked with developing a mutation-based fuzzer for testing software. The fuzzer has several configurable parameters that determine its behavior. Your goal is to implement a function that takes these parameters into account and generates mutated test cases for the software under test. You are provided with the ...
codefeedback
You are tasked with implementing a simple command-line utility that simulates a computer reboot process. The utility should prompt the user for confirmation before proceeding with the reboot. If the user confirms, the utility should display a countdown from 3 to 1, simulating the shutdown process, and then display a me...
codefeedback
You are tasked with creating a program that processes a list of exported modules from a TypeScript file and calculates the total number of GitHub stars associated with each module. The TypeScript file contains comments, and the exported modules are listed at the end of the file. Each exported module is preceded by the ...
codefeedback
You are tasked with creating a Python function that processes a list of strings representing measurements and calculates the average and standard deviation of these measurements. The measurements are in the format "measurement=value", where "value" is a floating-point number. Your function should return a tuple contain...
codefeedback
You are tasked with creating a Python program to validate user input for a registration form. The program should prompt the user to enter their first name, last name, email, and password. The input for each field should be validated according to specific criteria. The validation criteria are as follows: 1. First name ...
codefeedback
You are working on a project that involves processing astronomical data stored in HDF5 format. The code snippet provided is part of a Python script that appends columns to an HDF5 file. The `append_column_to_hdf5` function takes four arguments: the input HDF5 file (`infile`), the data to be appended, the group within t...
codefeedback
You are given a directory containing multiple files with the naming convention `scaffoldXXXX:YYYYYYYY-ZZZZZZZZ__stats.txt`, where `XXXX` represents the scaffold number, `YYYYYYYY` represents the start position, and `ZZZZZZZZ` represents the end position. Each file contains statistical data related to genetic analyses. ...
codefeedback
You are given an array of integers representing the positions of crabs on a line. Each integer represents the position of a single crab. Additionally, you are given two integers, `minPos` and `maxPos`, representing the minimum and maximum positions on the line, respectively. Your task is to write a function that calcu...
codefeedback
You are tasked with implementing a function that calculates the factorial of a given non-negative integer. The factorial of a non-negative integer n is the product of all positive integers less than or equal to n. For example, the factorial of 5 (denoted as 5!) is 5 * 4 * 3 * 2 * 1 = 120. Write a function `factorial` ...
codefeedback
You are tasked with implementing a naming context server for a distributed system. The naming context server is responsible for maintaining a mapping of names to object references, allowing clients to look up and access remote objects by their names. Your task is to implement the `BBNamingContextServer` class, which sh...
codefeedback
You are tasked with implementing a function to generate all possible Pauli stabilizer operators for a given number of qubits. Pauli stabilizer operators are tensor products of Pauli matrices (I, X, Y, Z) acting on individual qubits. The stabilizer operators form a basis for the stabilizer group, which is essential in q...
codefeedback
You are tasked with creating a Python function that processes a Django model definition and extracts information about the fields and their relationships. The model definition is provided as a string in the format of a Django migration file, which includes the fields and their relationships. Your task is to implement ...
codefeedback
You are tasked with implementing a data processing function that extracts and processes data from a continuous stream. The function should retrieve a specific portion of the data, convert it from hexadecimal to decimal, and then emit the processed data to a socket for real-time updates. You are given a code snippet th...
codefeedback
You are tasked with implementing a custom data structure in Swift that mimics the behavior of a stack, but with an added feature. The stack should support the usual push and pop operations, but it should also provide a method to retrieve the maximum element in the stack at any given time. Your task is to design and imp...
codefeedback
You are tasked with implementing a custom `Publisher` extension in Swift that provides a method for coalescing the output and failure of a publisher into a single `Result` type. The `Publisher` type is part of the Combine framework, which provides a declarative Swift API for processing values over time. Your task is t...
codefeedback
You are tasked with implementing a thread-safe context manager in Swift using pthread library. The context manager should allow for the creation and management of context objects associated with different threads. The provided code snippet initializes a pthread key for managing the context objects. Your task is to com...
codefeedback
You are tasked with implementing a class that manages asynchronous execution of rules in a rule-based system. The class should handle the execution and validation of rules, as well as the coordination of asynchronous tasks. Your task is to implement the `RuleManager` class with the following requirements: - The class ...
codefeedback
You are tasked with implementing a function to generate an image pyramid from a given input image. An image pyramid is a multi-scale representation of an image, typically used in computer vision and image processing applications. The pyramid is constructed by repeatedly downscaling the original image and storing each s...
codefeedback
You are tasked with implementing a command-line tool for version control in a software development environment. The tool should support the following commands: `bump`, `undo`, and `bump.undo`. The `bump` command is used to increment the version number, the `undo` command is used to revert the last version change, and t...
codefeedback
You are given a list of animals in alphabetical order. Your task is to implement a function that searches for a specific animal in the list using a binary search algorithm. If the animal is found, the function should return its index in the list; otherwise, it should return -1. The function signature is: ```python de...
codefeedback
You are tasked with implementing a custom data structure called `UnionDict` that behaves like a dictionary but also supports attribute-style access for nested dictionaries. The `UnionDict` should allow you to access nested dictionaries using dot notation, similar to accessing attributes of an object in object-oriented ...
codefeedback
You are tasked with implementing a simplified version of a middleware system for handling request context in a web application. The provided code snippet shows a simplified version of a `RequestContextMiddleware` class that is responsible for initializing the request context using a hypothetical `request_context` modul...
codefeedback
You are tasked with implementing a module dependency resolver for a package manager. The package manager uses a custom module system for organizing and managing dependencies of different packages. Each package can have dependencies on other packages, and the resolver needs to determine the correct order in which to ins...
codefeedback
You are tasked with creating a web form validation function for a user registration form. The form contains fields for "Nama Lengkap" (Full Name) and "Nama Pengguna" (Username). The form is processed using PHP, and the form data is sent to the server using the POST method. The form fields are required, and the user sho...
codefeedback
You are tasked with implementing a domain parsing function in Rust. The function should take a byte slice as input and parse out the domain name from the beginning of the slice. The domain name is defined as a sequence of characters ending with a period (.) or a space ( ). If the domain name is followed by a space, the...
codefeedback
You are tasked with creating a Rust library for working with mathematical curves and fields. The library should provide a clean and easy-to-use interface for performing operations on various types of curves and fields. Your task is to implement the necessary modules and structures to support this library. Specifically...
codefeedback
You are tasked with implementing a file caching system in Python. The file caching system should provide a way to store Python objects in files and retrieve them later. You are given a partial implementation of the `FileCacher` class, which includes a `__str__` method and an `object_to_file` method. The `__str__` meth...
codefeedback
You are tasked with creating a program that simulates a simple migration system for a database. The program should be able to execute migration scripts in a specific order and keep track of the executed migrations. You are given a code snippet from a migration file in a PHP framework. The migration file is used to ins...
codefeedback
You are working on a deployment script for a software project. The script needs to perform a series of operations on the built products directory. However, there is a critical bug in the script that needs to be fixed. The bug is causing the script to unintentionally delete a system file. Your task is to identify the bu...
codefeedback
You are tasked with implementing a simplified version of the `cd` command found in Unix-like operating systems. The `cd` command is used to change the current working directory. In this problem, you need to write a function that simulates the behavior of the `cd` command by updating the current working directory based ...
codefeedback
You are given a TypeScript class representing a binary tree node: ```typescript class Node { value: string; depth: number; width: number; left: Node | null; right: Node | null; constructor(value: string) { this.value = value; this.depth = 0; this.width = 0; this...
codefeedback
You are tasked with implementing a Python function that calculates the average of a given list of numbers, excluding the maximum and minimum values. The function should take a list of numbers as input and return the average of the remaining values. You should also write a helper function that collects statistics over a...
codefeedback
You are tasked with creating a Python program that processes audio files from YouTube videos and generates a summary of the video content based on the transcript. The program should utilize various libraries and APIs to achieve this functionality. Your task is to implement a function `generate_video_summary(video_url)...
codefeedback
You are tasked with implementing a chessboard visualization using the provided code snippet as a starting point. The code snippet defines constants for the width and height of the chessboard, the number of rows and columns, and the size of each square on the board. Your task is to write a Python function that takes in...
codefeedback
You are tasked with implementing a simple expression evaluator in Java. Your goal is to create a class `Expr` that can handle basic arithmetic expressions and evaluate them. The `Expr` class should support addition, subtraction, multiplication, and division operations. The expression will be provided as a string in inf...
codefeedback
You are tasked with implementing a function to process requests for a ticket management system. The function should handle various parameters and return the appropriate data based on the request. Your task is to write a function that processes the request and returns the required data. You are given a code snippet tha...
codefeedback
You are tasked with implementing a class method that retrieves references for a given list of items. The method should take an array of item IDs as input and return an array of references for those items. Each item ID corresponds to a list item, and the references for these items need to be retrieved. You are given th...
codefeedback
You are tasked with implementing a multi-threaded message processing system. The system consists of a message queue and a set of worker threads that retrieve messages from the queue and process them. The message queue is a shared resource that can be accessed by multiple threads concurrently. Your goal is to implement ...
codefeedback
You are tasked with implementing a custom template environment for a text processing system. The given code snippet defines certain configuration parameters and filters for the template environment. The `texenv` object is used to set the variable start and end strings, comment start and end strings, and a filter for es...
codefeedback