instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with implementing a class for managing financial instruments, specifically a Floating Rate Bond. The given code snippet is a part of a Python class that deals with encoding and decoding Floating Rate Bond objects using the FlatBuffers library. Your task is to create a method within the FloatingRateBond c...
codefeedback
You are given a list of strings, where each string represents a fragment of a larger string. Your task is to find the shortest superstring that contains all the given fragments. A superstring is a string that contains all the given strings as substrings. Write a function `shortestSuperstring` to find the shortest supe...
codefeedback
You are given an array `buffer` of length `n`, initially filled with zeros. You need to fill the array with the minimum number of operations required to transform each element `i` into a specific value. The operation allowed is to increment the value of an element by 1. However, if the index `i` is divisible by 2, you ...
codefeedback
You are tasked with implementing a function to resize an image based on certain constraints. The function should take an input image and resize it to fit within specified dimensions, while also returning additional information about the resizing process. Write a function `resize_image` that takes the following paramet...
codefeedback
You are tasked with implementing a graph data structure and performing various operations on it. The graph will be represented using an adjacency list. You need to implement the following operations for the graph: 1. Add a vertex to the graph. 2. Add an edge between two vertices. 3. Remove a vertex and all its associa...
codefeedback
You are tasked with implementing a CSS class parser that can extract and count the number of unique CSS classes used in a given CSS file. A CSS class is defined as any string that follows the period (.) character and is immediately followed by a valid class name. The parser should ignore any pseudo-classes or pseudo-el...
codefeedback
You are given a list of integers representing the scores of a game. The game has a rule that a player can only score if the previous two scores are both even. If the player's score is even, it is added to the total score; otherwise, it is ignored. Write a function `calculate_total_score(scores)` that takes in the list ...
codefeedback
You are tasked with implementing a function that constructs a binary search tree (BST) from a given list of prices. Each node in the BST represents a price, and the left child of a node contains prices lower than the node's price, while the right child contains prices higher than the node's price. The function should r...
codefeedback
You are tasked with creating a Python function that generates a recurrent neural network (RNN) model for a given sequence length and set of parameters. The function should be able to create both unidirectional and bidirectional RNN models using the Keras library. The function should take the following inputs: - `seq_l...
codefeedback
You are tasked with implementing a Monte Carlo Tree Search (MCTS) algorithm for a game-playing AI. The MCTS algorithm is used to make decisions in a game by simulating multiple possible moves and selecting the best one based on the simulation results. Your goal is to complete the implementation of the MCTS algorithm by...
codefeedback
You are tasked with implementing a function to build a URL query string from a dictionary of parameters. The function should take a dictionary of parameters and an optional convention string as input and return a URL query string. The function signature should be: ```python def http_build_query(params: dict, conventio...
codefeedback
You are tasked with implementing a function that validates the client's IP address based on a given HTTP request. The function should extract the real IP address from the request's metadata and compare it with a list of allowed IP addresses for a specific group. If the extracted IP address is found in the list of allow...
codefeedback
You are tasked with implementing a function to calculate the SHA-256 hash of a file using Python. The SHA-256 algorithm is a widely used cryptographic hash function that produces a 256-bit (32-byte) hash value. Your task is to create a Python function that takes a filename as input, reads the file in blocks, and then c...
codefeedback
You are tasked with implementing a statistical summary function for a dataset. The function should calculate various statistical measures such as count, mean, standard deviation, minimum value, and specified percentiles. You are given a code snippet that initializes the percentiles and headers for the summary. Your ta...
codefeedback
You are tasked with implementing a function to parse and process a network socket's received data. The function should extract and process the received data to determine if it meets specific criteria. You are given a code snippet of a PHP function `check_socket()` that initializes a variable `$rx_buffer` to store the...
codefeedback
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...
codefeedback
You are tasked with creating a parallel rendering algorithm for a graphics processing unit (GPU). The algorithm should render an image by accumulating multiple samples on top of each other. The provided code snippet is a part of the existing rendering framework and contains a method `render` that is responsible for ren...
codefeedback
You are tasked with creating a C# wrapper for a native library that provides access to key-related functionalities in a UI framework. The given code snippet contains C# declarations for three external functions that interface with the native library using PInvoke. Your goal is to implement the corresponding C# wrapper ...
codefeedback
You are tasked with creating a Python module for a robotics simulation system. The module should include functions for reading instrument and detector descriptions, as well as for simulating a robotic sequence. Your task is to implement the necessary functions to achieve this. You are provided with a code snippet that...
codefeedback
You are tasked with implementing a Python class that represents a URL object. The class should have methods to parse the URL and extract its components such as the protocol, domain, path, query parameters, and fragment. Your task is to complete the implementation of the `URLParser` class by adding the necessary method...
codefeedback
You are tasked with creating a Python function that simulates the behavior of the `shutil.rmtree()` function, which recursively removes a directory and its contents. Your function should handle potential errors that may occur during the deletion process. Write a Python function called `safe_remove_directory(path)` tha...
codefeedback
You are tasked with implementing a permission filter for a system that lists ATBDs (Algorithm Theoretical Basis Documents) along with their summary version information. The system should only display versions with status "Published" if the user is not logged in. Additionally, if a user is logged in and has a specific r...
codefeedback
You are tasked with creating a function that processes file names and paths based on a given directory and file name string. The function should handle the scenario where a file with the same name already exists in the directory. Write a function `processFileNameAndPath` that takes in three parameters: - `log_dir`: A...
codefeedback
You are given a PHP array `$input` that contains a nested structure of keys and values. The keys are strings, and the values can be either integers or arrays with the same structure. Your task is to write a function `flattenArray($input)` that takes this nested array as input and returns a flattened array where the key...
codefeedback
You are tasked with creating a Python function that processes linguistic features of words in a text. The function should take a word object as input and extract relevant morphological features from it. The morphological features are represented as a string in the format "key1=value1|key2=value2|...|keyN=valueN". The f...
codefeedback
You are tasked with implementing a custom neural network layer in PyTorch. The layer, named `CustomLayer`, consists of the following components: - `split_token`: a learnable parameter initialized with Xavier uniform distribution, represented as a 1x`h_dim` tensor. - `operation_mix`: an instance of the `OperationMix` cl...
codefeedback
You are working on a healthcare data processing system that deals with blood pressure measurements. Your task is to write a Python function that calculates the standard deviation and variability of diastolic blood pressure readings from a given dataset. You are given the following code snippet as a starting point: ``...
codefeedback
You are tasked with creating a Python program that processes files within a specified directory. The program should perform the following tasks: 1. List all the files in the specified directory. 2. For each file, determine its size in bytes and the date and time it was last modified. 3. Print the file name, size, and ...
codefeedback
You are tasked with creating a Python function that processes data from a file bundle and performs specific operations on the data. The file bundle contains multiple data files, each with a specific format and content. Your function should be able to read the data from these files, process it according to certain rules...
codefeedback
You are tasked with creating a Python package management system that can dynamically load and instantiate frontend modules for various components of a multimedia application. The package structure follows a specific naming convention, and the system should be able to identify and load these modules at runtime. Your ta...
codefeedback
You are tasked with creating a Python function that simulates a simple card game. The game involves drawing cards from a standard 52-card deck and comparing the drawn cards to determine the winner. The function should take two arguments: `player1` and `player2`, each representing a list of cards drawn by the respective...
codefeedback
You are tasked with implementing a Java interface for handling Base64-encoded CSV files. The interface, `Base64SpiConstants`, contains two constants related to the Base64-encoded CSV file format. The constant `BASE64_CSV_FILE_TYPE` represents the file type, and `DEFAULT_CSV_CELL_SEPARATOR` represents the default separa...
codefeedback
You are tasked with creating a custom tag helper for a Razor Pages application. Tag helpers are a feature in ASP.NET Core that enables server-side code to participate in creating and rendering HTML elements in Razor files. In this problem, you will be implementing a custom tag helper to enhance the functionality of a R...
codefeedback
You are tasked with implementing a function that processes execution blocks and methods. An execution block is a unit of code that needs to be executed, and a method is a set of instructions for processing execution blocks. Your goal is to create a function that takes in two lists of execution blocks, along with a set ...
codefeedback
You are tasked with implementing a circular buffer data structure to store health entries in a health monitoring system. The circular buffer should have a maximum capacity of 50 entries, and when the buffer is full, adding a new entry should replace the oldest entry in the buffer. Your task is to implement the `Circula...
codefeedback
You are tasked with creating a Python function that processes a list of file paths and extracts specific information from each file. The function should take in three parameters: `save_dir` (string), `wsi_patch_info_dir` (string), and `extract_info` (function). The `wsi_patch_info_dir` contains multiple text files, eac...
codefeedback
You are tasked with implementing a Python function that removes items from a given set that are also present in another set. You need to write a function `remove_items` that takes two sets, `setA` and `setB`, as input and returns a new set containing the elements from `setA` that are not present in `setB`. The functio...
codefeedback
You are tasked with implementing a function to process log data and calculate statistical values for visualization. The function takes a list of log data as input and performs the following operations: 1. Prepends a 0 to each log_info array in the list. 2. Determines the minimum length among all log_info arrays. 3. Tru...
codefeedback
You are tasked with implementing a text-based inventory management system for a game. The system should allow the player to add, remove, and display items in their inventory. The player should also be able to consume items from their inventory. You are given a partial code snippet for the inventory management system. ...
codefeedback
You are tasked with implementing a concrete subclass of the `TransactionCreator` abstract class in Python. The `TransactionCreator` class has two abstract methods: `estimate_cost_for_certificate_batch` and `create_transaction`. Your task is to create a subclass called `CertificateTransactionCreator` that implements the...
codefeedback
You are tasked with creating a Python function that processes a string containing information about authors and their emails. The input string follows a specific format where author names and emails are listed in a comma-separated format. Your task is to extract the author names and their corresponding emails and retur...
codefeedback
You are tasked with implementing a function that validates the format of an email address. The function should take a string as input and return a boolean value indicating whether the input string is a valid email address or not. For the purpose of this problem, a valid email address should adhere to the following rule...
codefeedback
You are given a string `S` containing alphanumeric and non-alphanumeric characters. Your task is to implement a function that rearranges the string such that all the non-alphabetic characters are moved to the end of the string, while maintaining the relative order of the alphabetic characters. The function should retur...
codefeedback
You are tasked with implementing a file validation system for a data processing application. The system should validate the data types and lengths of headers and control information in a file before adding a batch of data to it. You are provided with a `FileValidator` class that contains methods for validating data typ...
codefeedback
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. The game should consist of a series of rounds, and the winner of each round should be determined based on the classic rules of rock-paper-scissors: rock beats ...
codefeedback
You are tasked with creating a Python function that interacts with a PostgreSQL database using asynchronous programming techniques. The function should connect to the database, execute a query to retrieve the count of records from a specified table in a given schema, and then return the count as a result. If an error o...
codefeedback
You are tasked with implementing a generic method for performing conditional computation in Java. The method `computeIfMatch` takes three parameters: `target`, `predicate`, and `mapping`. The `target` represents the input value, the `predicate` is a condition that the `target` must satisfy, and the `mapping` is a funct...
codefeedback
You are tasked with implementing a simplified version of a web-based drawing game. The provided code snippet is part of the server-side logic for handling drawing submissions from players. The game involves two players, and each player takes turns drawing an image based on a prompt. The code snippet checks if the curr...
codefeedback
You are tasked with creating a program that processes a simplified version of Markdown text. Your program should be able to recognize and convert a specific subset of Markdown syntax into HTML. The subset of Markdown syntax to be supported includes: 1. Headers: Lines starting with one or more `#` characters followed b...
codefeedback
You are tasked with creating a Python class that represents a database table using SQLAlchemy. The table will store information about books, including their title, author, and genres. Your task is to define the SQLAlchemy model for this table and implement a method to query the database for books based on their genres....
codefeedback
You are tasked with implementing a custom hook in React that manages the visibility of a component based on the user's scroll position. The hook should accept a reference to the component, as well as optional styles and additional props to be spread onto the component. When the component is scrolled into view, it shoul...
codefeedback
You are tasked with creating a program that simulates a simple shell environment. The shell should support executing commands and changing the shell prompt. The supported shells are zsh and bash. When changing the shell, the prompt should reflect the change, and the available commands may differ based on the selected s...
codefeedback
You are tasked with implementing a generic expression interface for a simple expression tree in C#. The interface should define three properties and a generic method. The properties are: 1. `Cast` of type `BaseType`, representing the base type of the expression. 2. `DataType` of type `DataType`, representing the data ...
codefeedback
You are tasked with implementing a feedforward neural network using the provided `Network` class. The network will have a variable number of layers and neurons per layer. Your goal is to complete the implementation by adding the functionality to initialize the weights between the layers. The `Network` class has an `__...
codefeedback
You are tasked with implementing a simplified version of a state management library in TypeScript. The library should support defining a model with initial state, reducers, effects, and a method to reset the state. Your task is to complete the implementation of the `BasicDva` class by adding the necessary methods and p...
codefeedback
You are working on a blockchain implementation and need to create a function to handle block creation and validation. The function `get_skips_and_block_making_time` returns the number of blocks to skip and the timestamp for block making. The `make_block` function is used to create a new block, and the `Transaction` cla...
codefeedback
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...
codefeedback
You are tasked with creating a layout manager for a user interface in a mobile application. The layout manager should be able to position and size UI elements based on a set of constraints. Each constraint is defined by a pair of UI elements and optional constants for positioning. The constraints are represented as met...
codefeedback
You are tasked with implementing a DAO (Data Access Object) for managing AttachmentType objects in a Java application. The AttachmentType class represents different types of attachments that can be associated with other entities in the application. Your goal is to create a DAO interface and its implementation using Goo...
codefeedback
You are tasked with implementing a function that will take in a list of integers and return the median of the list. The median of a list of numbers is the middle number when the list is sorted in ascending order. If the list has an odd number of elements, the median is the middle number. If the list has an even number ...
codefeedback
You are tasked with implementing a message consumer for a pub/sub system using Python's asyncio library. The provided code snippet is a part of the consumer logic, which is responsible for pulling messages from different channels. Your task is to complete the implementation of the `pull_message` method in the `PubSubCo...
codefeedback
You are tasked with implementing a function that can retrieve a value from a JSON object using an array of integers and/or strings as a path. The JSON object may contain complex nested structures, and the path array will specify the sequence of keys or indices to traverse in order to reach the desired value. You need ...
codefeedback
You are tasked with simulating a biochemical reaction using a Python package called `tellurium`. The code snippet provided initializes some variables and then uses the `tellurium` package to simulate a biochemical model. Your task is to write a Python function that takes the initialized variables and simulates the bioc...
codefeedback
You are tasked with designing a Swift protocol for a Moonbeam bonus service. The protocol should define the required methods for interacting with the Moonbeam bonus service. The service is responsible for managing bonus rewards for participants in a crowdloan campaign on the Moonbeam network. The protocol should includ...
codefeedback
You are tasked with implementing a Python function that processes historical data from a machine learning model and visualizes the loss over epochs using matplotlib. The function should take the historical data as input and generate a plot showing the validation loss and training loss over the epochs. The function sig...
codefeedback
You are tasked with implementing a function to validate transaction pool statistics in a blockchain system. The provided code snippet is part of a blockchain node's codebase and contains a method for asserting transaction pool statistics. The `assert_tx_pool_statics` method is responsible for validating the total size...
codefeedback
You are tasked with creating a Python function to process weather data stored in NetCDF files using the xarray library. The function should read multiple NetCDF files, extract specific weather data variables, and calculate the average value of these variables over a specified time period. Write a Python function `calc...
codefeedback
You are given a list of strings representing file paths. Each file path consists of a sequence of directories separated by slashes ("/"). Your task is to write a function that returns the longest common prefix among all the file paths. If there is no common prefix, the function should return an empty string. For examp...
codefeedback
You are tasked with creating a command-line tool that emulates the functionality of the `alias` command in Unix-like operating systems. The `alias` command allows users to create custom shortcuts for other commands or command sequences. Your tool should support creating, listing, and removing aliases for shell commands...
codefeedback
You are tasked with implementing a histogram matching algorithm to modify the pixel values of an input image based on the cumulative distribution functions (CDFs) of the input and a template image. The CDF of an image represents the cumulative distribution of pixel intensities, and histogram matching aims to transform ...
codefeedback
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...
codefeedback
You are tasked with creating a simple image processing application. The application should allow users to load an image, apply a specified filter, and display the filtered image. To achieve this, you need to implement the following functionalities: 1. Load an image: Create a function that allows the user to select an ...
codefeedback
You are tasked with creating a program that analyzes the frequency of words in a given text file. Your program should read the contents of the text file, tokenize the words, and then count the frequency of each word. For the purpose of this problem, a word is defined as a sequence of characters separated by spaces or p...
codefeedback
You are tasked with implementing a simplified version of the `MoCoV2` class, which is used for contrastive learning in deep learning models. The provided code snippet is a partial implementation of the `MoCoV2` class in Python using PyTorch. Your task is to complete the implementation by adding a method to calculate th...
codefeedback
You are tasked with creating a plugin for a simulation environment using Gazebo, a popular robotics simulator. Your goal is to develop a plugin that loads a maze world and a robot model into the simulation environment. The provided code snippet is a part of the plugin that loads the maze world and a robot model. Your ...
codefeedback
You are tasked with creating a script to automate the deployment of a dashboard application using npm. The dashboard application is built using various front-end technologies such as React, Vue, or Angular. Your script should handle the deployment process, including building the application and starting the server. Yo...
codefeedback
You are tasked with implementing a lemmatization and stemming function for text preprocessing. Lemmatization involves reducing words to their base or dictionary form, while stemming involves reducing words to their root form. Your task is to create a Python function that takes a list of reviews as input, performs lemma...
codefeedback
You are tasked with implementing a function to swap the byte order of a given command header structure in a C++ program. The command header structure is defined as follows: ```cpp struct CommandHeader { USHORT CommandId; BYTE DestMachineId[MACHINE_ID_SIZE]; BYTE SrcMachineId[MACHINE_ID_SIZE]; }; ``` The f...
codefeedback
You are tasked with implementing a C++ function that generates an output stream for a deep tiled output part. The function signature is provided as follows: ```cpp void abi_gen_imf_deeptiledoutputpart(std::ostream& os); ``` Your task is to create a function `abi_gen_imf_deeptiledoutputpart` that takes an `std::ostrea...
codefeedback
You are tasked with implementing a Java method to extract and format error messages from an exception as JSON. The method should take an exception object and a class name as input and return a JSON object containing the error message details. You are given the following method signature to implement: ```java public st...
codefeedback
You are given a Python code snippet that seems to be incomplete. Your task is to complete the code by implementing a function that calculates the length of the longest consecutive subsequence of a given list of integers. The given code snippet is as follows: ```python <gh_stars>0 def length(t1, n): # Your implemen...
codefeedback
You are tasked with implementing a file handling utility in Python. Your task is to create a program that allows users to copy the contents of one file to another, with the option to specify whether the destination file should be overwritten if it already exists. The program should provide a command-line interface for ...
codefeedback
You are tasked with implementing a function to calculate the volume of water that can be trapped in a series of connected vertical pillars. Each pillar has a specific height, and the distance between each pillar is uniform. The pillars are represented by an array of non-negative integers, where each integer represents ...
codefeedback
You are tasked with implementing a class called `SortedStack` that represents a stack data structure with the following methods: 1. `push(value)`: Adds a new element `value` to the stack. 2. `pop()`: Removes and returns the top element from the stack. 3. `peek(index)`: Returns the element at the specified `index` from...
codefeedback
You are tasked with implementing a URL routing system for a web server. The server receives HTTP requests and needs to map the requested URL paths to corresponding handler functions based on predefined URL patterns. You are given a code snippet that iterates through a collection of URL patterns and checks if the curre...
codefeedback
You are tasked with implementing a control system for a Brushless DC Motor (BLDCM) using the given code snippet as a starting point. The code snippet initializes hall sensors and a timer for the BLDCM control. Your task is to complete the implementation by writing the necessary functions to control the BLDCM based on t...
codefeedback
You are tasked with implementing a function to find the range of a specific tag within a given tweet. The tag is represented by a string and is enclosed within "#" symbols. The function should return the start and end indices of the tag within the tweet. If the tag is not found, the function should return (-1, -1). Fu...
codefeedback
You are tasked with creating a Python class that simulates a simple configuration manager. The class should allow users to define configuration settings and retrieve them using attribute access. Additionally, the class should support a special mode called `orm_mode`, which, when enabled, should convert attribute access...
codefeedback
You are tasked with implementing a class `ToFloat` that converts a given string to a floating-point number. The class should have a method `convert` that takes a string as input and returns the corresponding floating-point number. The conversion should handle both integer and decimal strings, and should also consider s...
codefeedback
You are working on a project that involves analyzing text data within a SQL Server environment. Your task is to create a Python script that connects to a local SQL Server database, installs the "textblob" package using the `sqlmlutils` library, and then performs sentiment analysis on a specific table within the databas...
codefeedback
You are tasked with implementing a Python function to compute the R2T pulse shape for nuclear magnetic resonance (NMR) experiments. The R2T pulse shape is determined by a match condition equation: [1 or 2]*wr - W_I_eff - W_S_eff = 0, where wr is a variable, and W_I_eff and W_S_eff are effective widths. Your function sh...
codefeedback
You are tasked with implementing a function that takes an array of integers as input and returns the maximum sum of a subarray within that array. A subarray is defined as a contiguous block of elements within the original array. The function should return 0 if the array is empty or contains only negative numbers. You ...
codefeedback
You are tasked with creating a script to automate the installation of OpenSSL on a Windows system using the MinGW cross-compiler. Your script should download the OpenSSL source code, verify its integrity using SHA256, extract the files, configure the build options based on the architecture, and then compile and install...
codefeedback
You are given a list `nk` containing three positive integers. Your task is to write a function `calculate_combinations(nk)` that calculates the number of combinations possible for a given set of items. The first integer `n` represents the total number of items, and the second integer `k` represents the number of items ...
codefeedback
You are tasked with implementing a Python class that facilitates the download of medical image datasets for research purposes. The provided code snippet includes imports and a data class for download parameters. Your task is to create a class called `MedicalImageDownloader` that encapsulates the functionality to downlo...
codefeedback
You are tasked with implementing a custom dictionary class in Python that supports default values for keys that are not present in the dictionary. The class should be able to accept a default value during initialization and return this default value for any key that is not present in the dictionary. If a key is explici...
codefeedback
You are tasked with creating a program to determine the winner of a game of Connect Five, a variant of the classic game Connect Four. In Connect Five, players take turns placing their pieces on a grid, aiming to connect five of their pieces in a row, column, or diagonal before their opponent does. Your task is to impl...
codefeedback
You are tasked with developing a data access layer for a payment processing system. The system needs to connect to a database to retrieve and store payment-related information. The code snippet provided defines a class `DataAccessConstants` with an internal constant string `ConnectionStringName` set to "Payments". This...
codefeedback
You are tasked with implementing a settings management system for a web application. The system should allow for dynamic reloading of settings when they are changed. You are provided with a code snippet that handles the reloading of settings when a specific setting is changed. Your task is to implement the `reload_api_...
codefeedback
You are tasked with implementing a resource consumption control mechanism for a web server application. The given code snippet is a part of this mechanism and is responsible for handling the response from a client request. The code snippet includes the initialization of variables and the processing of the response enti...
codefeedback