instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
You are given a code snippet that is part of a function to deserialize a binary tree from a string representation. The function takes a string `data` as input and returns the root of the deserialized binary tree. The input string `data` represents the level order traversal of the binary tree, where each node's value is... | codefeedback |
You are tasked with creating a SwiftUI view for managing user permissions within a messaging app. The view should display a list of user permissions for a specific channel and allow the user to toggle each permission on or off. The permissions include "Read Messages," "Send Messages," and "Manage Channel."
Your task i... | codefeedback |
You are tasked with implementing a function that calculates the total number of valid paths from the top-left corner to the bottom-right corner of a grid. The grid is represented as a 2D array, where each cell contains a non-negative integer representing the cost to traverse that cell. You can only move right or down a... | codefeedback |
You are tasked with simulating a customer service system using a discrete event simulation approach. The system consists of a single counter where customers arrive, spend some time discussing their needs, and then leave. Your goal is to implement a simulation that models the behavior of customers arriving at the counte... | codefeedback |
You are given a string `str` containing only lowercase English letters. Your task is to write a function that takes the string as input and returns the count of each distinct character in the string, along with the character itself. The function should output the counts and characters in the order they appear in the st... | codefeedback |
You are tasked with implementing a simplified version of an online shopping system. The system consists of three classes: `Order`, `OrderItem`, and `Customer`. The `Order` class represents a customer's order and contains a unique `orderId`, a `couponCode` (if applicable), and a list of `OrderItem` objects. The `OrderIt... | codefeedback |
You are tasked with implementing a custom serialization and deserialization process for a specific data structure. The data structure in question is a vector of unsigned messages, and you are required to create a custom serializer and deserializer for this data structure using the Serde library in Rust.
Your task is t... | codefeedback |
You are tasked with creating a class that manages the storage and broadcasting of parameters in a web application. The class should handle the saving of parameters and the broadcasting of a new parameter event to the application's listeners.
You are provided with a code snippet that represents a method within a PHP cl... | codefeedback |
You are tasked with creating a Rust program to manage a connection pool for a MySQL database. The program should utilize the `mysql` and `r2d2` crates to establish a connection pool and execute a query on the database.
Your task is to complete the `main` function by implementing the following steps:
1. Create a struct... | codefeedback |
You are tasked with creating a neural network model using PyTorch to classify images of handwritten digits from the MNIST dataset. The goal is to build a simple feedforward neural network and train it to achieve high accuracy in classifying the digits. The MNIST dataset consists of 28x28 pixel grayscale images of handw... | codefeedback |
You are tasked with creating a Python class that represents a media part in a database. The class should inherit from the `Model` class and define the necessary attributes to interact with a database using the `peewee` ORM.
Your task is to complete the `MediaPart` class by adding the required attributes and methods to... | codefeedback |
You are tasked with creating a Python function that processes a given directory and returns a list of all the Python files present in that directory and its subdirectories. You should use the `os` module to navigate the file system and the `ntpath` module to handle file paths. Additionally, you need to import the `Coll... | codefeedback |
You are tasked with simulating a simplified event handling mechanism in a multi-threaded environment. The provided code snippet is a part of this simulation.
The `assert!(event.0 != 0);` statement ensures that the event handle `event` is valid and not null. The `SetEvent(event).ok()?;` line sets the event object `eve... | codefeedback |
You are tasked with implementing a function to parse a given license file and extract the license information from it. The license file is in the format of a comment block at the beginning of a source code file, similar to the provided code snippet. The license information is enclosed within the comment block and conta... | codefeedback |
You are tasked with creating a Python function that reads longitude and latitude coordinates from a Keyhole Markup Language (KML) file containing a single path. The function should utilize the `fastkml` library to parse the KML file and extract the coordinates.
Write a function `kml2latlon(ifile)` that takes a single ... | codefeedback |
You are tasked with creating a Python script to monitor the status of a Mosquitto MQTT broker and send an alert if the broker goes offline. Mosquitto is an open-source message broker that implements the MQTT protocol. The code snippet provided is a command to start the Mosquitto broker using a specific configuration fi... | codefeedback |
You are tasked with creating a Python program to manage a quiz application. The program should allow users to register and manage quizzes, questions, answers, labels, and submissions. Your task is to implement the necessary classes and methods to achieve this functionality.
You need to create the following classes:
1.... | codefeedback |
You are tasked with implementing a Python function that constructs a specific geometric shape based on the given input. The function should be able to construct either a hollow square or a diamond based on the input parameters. The shape construction should be done using the asterisk (*) character. The function should ... | codefeedback |
You are given a list of integers representing the scores of participants in a competition. The task is to determine the minimum number of participants who scored at least the k-th highest score. Write a function `min_participants_scored_kth_highest` that takes in the number of participants `n`, the value of `k`, and th... | codefeedback |
You are tasked with implementing a function that takes a list of file paths and returns the longest common prefix among them. The function should handle both absolute and relative paths, and should return an empty string if there is no common prefix.
You are given the following code snippet as a starting point:
```py... | codefeedback |
You are tasked with implementing a custom error handling mechanism for a Rust application. The provided code snippet showcases a macro for defining custom error types and their corresponding error messages. Your goal is to create a similar macro and use it to define custom error types for a hypothetical web server appl... | codefeedback |
You are tasked with creating a function that retrieves item data for a specific user from a datasource and returns it in a specific format. The function uses asynchronous operations and middleware for handling API responses and errors.
Write a function `getItemData` that takes two parameters:
1. `userId` (string) - th... | codefeedback |
You are tasked with implementing a class that handles the export of image data to the EXR format, a high-dynamic-range (HDR) image file format. The EXR format supports various compression types, and your class should provide the flexibility to choose the compression method when exporting the image data.
You are provid... | codefeedback |
You are tasked with creating a program to manage a library's book inventory. The program should allow users to add new books, remove existing books, and display the current list of books. Each book will have a title, author, and unique identification number. Additionally, the program should be able to search for a book... | codefeedback |
You are tasked with implementing a function to draw pixels to an SDL_Texture and then render the texture using SDL. The function should take a PSF (PC Screen Font) file, load it, draw the pixels to an SDL_Texture, and return the texture. Additionally, the function should handle scaling the texture as needed before rend... | codefeedback |
You are tasked with implementing a Java class that filters issues based on keywords. The class `IssueContainsKeywordsPredicate` takes a list of keywords and checks if an issue contains all the keywords in the list. Your task is to complete the implementation of the `IssueContainsKeywordsPredicate` class and write a met... | codefeedback |
You are working on a satellite data processing system that processes files with specific naming conventions. Each file name contains information about the data it holds. The file name format is as follows: "MOD13Q1.AYYYYDDD.hHV.VVV.YYYYMMDDHHMMSS.hdf", where:
- "MOD13Q1" is the product name.
- "A" is a constant charact... | codefeedback |
You are tasked with designing a system for managing tables in a database. The provided code snippet is a simplified representation of an asynchronous function in Rust, which adds a table to the database and triggers a compaction process. Your task is to create a function that simulates the behavior of the `add_table` f... | codefeedback |
You are tasked with creating a Python program to detect and count the number of objects in a series of grayscale images using a pre-trained Haar cascade classifier. The program should load the cascade classifier from a file, iterate through a directory of sample images, and for each image, detect the objects using the ... | codefeedback |
You are working on a project that involves interfacing with a C library from Rust. The C library provides functions for managing a client connection. You need to create a Rust wrapper around these C functions to manage the client connection in a safe and idiomatic way.
You are given the following C code snippet that d... | codefeedback |
You are tasked with creating a script to manage AWS IAM instance profiles and roles. Your script should include functions to create, delete, and manage instance profiles and roles. The script should interact with the AWS CLI to perform these operations.
Your script should include the following functions:
1. `create_in... | codefeedback |
You are tasked with creating a program to analyze and manipulate fields within a Java class using reflection. Reflection is a powerful feature in Java that allows programs to inspect and modify classes, interfaces, fields, and methods at runtime. Your task is to implement a Java program that utilizes reflection to retr... | codefeedback |
You are tasked with creating a priority management system for a task management application using NestJS and Mongoose. The system should allow users to define and manage different priority levels for their tasks.
Your task is to implement the PriorityService class, which will be responsible for interacting with the da... | codefeedback |
You are tasked with implementing a program to parse and process a JSON file containing information about different environment variants. Each variant is represented as a JSON object with the following structure:
```json
{
"env-variant": "No-op start",
"score": 15177.10
}
```
The "env-variant" field represents... | codefeedback |
You are tasked with implementing a function to find the nearest neighbor of a given image file within a set of reference images. The function should take the image file, a reference path containing the reference images, and a list of reference file names as input. The goal is to compare the given image with the referen... | codefeedback |
You are working on a research project involving statistical simulations, and you need to create visualizations for the results. The code snippet provided includes calls to three functions: `make_power_figures`, `make_null_figures`, and `make_EW_figures`. These functions are responsible for generating different types of... | codefeedback |
You are tasked with creating a Python program that processes a text file containing a list of student names and their corresponding test scores. Each line in the file represents a student's name followed by their test score, separated by a comma. Your program needs to read this file, calculate the average test score fo... | codefeedback |
You are tasked with creating a script to automate the process of retrieving access tokens and material counts from the WeChat API. The provided code snippet is a part of this automation process. Your task is to complete the script by writing a Bash function that takes the WeChat app ID and app secret as input and retur... | codefeedback |
You are tasked with creating a Python module that manages datasets for a machine learning project. The module should include classes for specific datasets and a backend for data processing. Your task is to design the module structure and ensure that it adheres to best practices for Python package organization.
Your mo... | codefeedback |
You are tasked with analyzing and refactoring a set of Laravel routes to ensure proper resource nesting and route naming conventions. The given code snippet contains a set of routes defined in a Laravel application. Your goal is to identify any issues with the route definitions and refactor them to adhere to best pract... | codefeedback |
You are given a list `postorder` containing the postorder traversal of a binary tree. Your task is to construct the binary tree and return its root node. The postorder traversal of a binary tree follows the order: left, right, root.
You need to implement the following function:
```python
class TreeNode:
def __ini... | codefeedback |
You are tasked with implementing a function that simulates a basic stack data structure. The stack should support the following operations: push, pop, and peek. The push operation adds an element to the top of the stack, the pop operation removes the top element from the stack and returns it, and the peek operation ret... | codefeedback |
You are tasked with implementing a builder pattern for a forecasting application. The provided code snippet is a part of the builder pattern implementation for configuring forecast parameters. Your task is to complete the implementation of the `ForecastBuilder` struct by adding methods to set the start date and end dat... | codefeedback |
You are tasked with creating a program that simulates a simple banking system. The program should be able to handle multiple accounts, allowing users to deposit, withdraw, and check their balance. Each account should have a unique account number and be associated with the account holder's name. The program should also ... | codefeedback |
You are tasked with implementing a Time-Based One-Time Password (TOTP) generator in Rust. TOTP is a type of two-factor authentication that uses a time-based algorithm to generate a one-time password. The code snippet provided includes module declarations for `totp` and `hotp`, and re-exports the `HOTP` and `TOTP` struc... | codefeedback |
You are tasked with creating a custom UIAlertController subclass in Swift. Your custom alert controller should have the following features:
- It should have a designated initializer that takes a title, message, preferredStyle, action button title, cancel button title, and action procedures as parameters.
- The action b... | codefeedback |
You are tasked with implementing a function to generate a secure invoice key using the given input parameters. The function should take in a keychain mask, invoice transaction arguments, and a boolean flag indicating whether to use a test random number generator (RNG). The keychain mask is an optional reference to a se... | codefeedback |
You are tasked with creating a unit test for a simple function that calculates the factorial of a given positive integer. The function should be tested using the XCTest framework in Swift. The code snippet provided is a part of a test case class and includes the tearDown method and a placeholder testExample method.
Yo... | codefeedback |
You are tasked with implementing a function that processes a linked list and returns the last node with a specific value. The linked list is represented by the following structure:
```c
struct ListNode {
int val;
struct ListNode *next;
};
```
You need to implement the following function:
```c
struct ListNode... | codefeedback |
You are tasked with implementing a Python class that encodes data and writes it to the file system. The class should inherit from two existing classes and provide a specific functionality for writing content to a file system.
Implement a Python class called `FileSystemContentEncoder` that inherits from `AmendmentNodeE... | codefeedback |
You are tasked with creating a program that simulates the behavior of a simplified shell command execution. Your program should take a list of commands and their arguments, along with the current working directory, and execute the commands sequentially, updating the working directory as necessary.
You are given the f... | codefeedback |
You are tasked with creating a Python script to automate the installation of required packages on a Linux system. Your script should read a list of packages from a file and execute the installation commands for each package using the `apt-get` package manager. Additionally, the script should handle potential errors tha... | codefeedback |
You are tasked with implementing a token management system for a web application. The system should handle the creation and deletion of personal access tokens for users. You are provided with a code snippet from a PHP class that demonstrates the deletion of a user's current access token and the generation of a response... | codefeedback |
You are tasked with implementing a Python function that performs a character rotation on a given string. The rotation involves shifting each character in the string by a specified number of positions in the alphabet. For instance, rotating 'abc' by 1 position results in 'bcd', and rotating 'abc' by -1 position results ... | codefeedback |
You are tasked with implementing a simplified version of a future-based asynchronous task executor in Rust. The provided code snippet is a part of the implementation of the `poll` method for a custom `Executor` struct. The `poll` method is used to drive the execution of asynchronous tasks to completion.
Your task is t... | codefeedback |
You are tasked with creating a Python function that processes video data to identify matching attributes between two video objects. The function should take in two arguments: `self` representing the first video object and `video` representing the second video object. The function should return a set of matching attribu... | codefeedback |
You are tasked with implementing a Swift data structure for managing user sessions within a travel app. The provided code snippet outlines the initialization of a session state object, which encapsulates various properties related to the user's interaction with the app. Your goal is to design and implement the `Session... | codefeedback |
You are tasked with creating a custom button component for a web application using React and styled-components. The button component should have the ability to adjust its opacity based on a `disabled` prop and display text with specific styling.
Your task is to implement the `Button` and `ButtonText` styled-components... | codefeedback |
You are tasked with implementing a priority queue using a custom class called `CustomPriorityQueue`. The `CustomPriorityQueue` class should support the following operations:
1. `put(item, priority)`: Add an item to the queue with a specified priority.
2. `get()`: Remove and return the item with the highest priority.
3.... | codefeedback |
You are tasked with implementing a file upload handler class in PHP. The class should support multiple drivers for handling file uploads, such as local storage, cloud storage, or custom handlers. Your goal is to complete the implementation of the `UploadHandler` class by adding the necessary methods to support differen... | codefeedback |
You are tasked with implementing a Python class that simulates a simple banking system. The class should allow for the creation of multiple bank accounts, as well as the ability to deposit and withdraw funds from these accounts.
Your task is to create a `BankAccount` class with the following specifications:
- The clas... | codefeedback |
You are tasked with implementing a custom enumerable type in C#. Your custom enumerable type should mimic the behavior of the built-in `IEnumerable` interface and provide the ability to iterate over a collection of elements. Your task is to create a class that satisfies the requirements of the `IEnumerable` interface a... | codefeedback |
You are tasked with implementing a Python class method that calculates the node weights for initializing the use of the Personalized PageRank algorithm. The Personalized PageRank algorithm is a variant of the classic PageRank algorithm, but it allows for personalized preferences to influence the ranking of nodes in a g... | codefeedback |
You are tasked with implementing a neural network layer using the given code snippet as a reference. The code snippet represents the `forward` method of a neural network class, which takes an input tensor `x` and passes it through a series of layers, including convolutional and fully connected layers. Your task is to e... | codefeedback |
You are tasked with implementing a function to calculate ratios for the overview or aggregated results for a middle view. The function, `get_ratios`, takes several parameters: `id1`, `id2`, `direction`, `ops`, `bins`, `bins_col`, and `jsonit`. It also calls two other functions, `create_hashname` and `get_diff_cache`, a... | codefeedback |
You are tasked with implementing a function that counts the number of occurrences of a specific substring within a given string. The function should be case-insensitive and should consider overlapping occurrences of the substring. For example, in the string "in_residence", the substring "res" occurs twice (at index 3 a... | codefeedback |
You are tasked with creating a program that processes GitHub repository data and performs specific operations based on the information provided. The program will read input from a file containing lines of data in the following format:
```
<reponame>rishabmenon/PyNimbus<filename>PyNimbus/nhcoutlooks.py<gh_stars>0
#!/usr... | codefeedback |
You are tasked with implementing a function that processes HTTP requests for a project management system. The function should handle different types of requests and their corresponding actions. The requests are related to retrieving project documents with specific routing parameters. Your task is to design a function t... | codefeedback |
You are tasked with implementing a hierarchical tree structure using Python. The tree will be used to represent a hierarchy of nodes, with each node potentially having child nodes. Your task is to create a class that can build and manage this hierarchical tree structure.
You are provided with a code snippet that inclu... | codefeedback |
You are tasked with implementing a function that processes a given SVG (Scalable Vector Graphics) file and extracts information about the rectangles defined within it. Each rectangle is represented by a `<rect>` tag in the SVG file, and its attributes specify the position and dimensions of the rectangle.
Write a funct... | codefeedback |
You are working on a data analysis tool that processes metrics from various services. The tool has a method `_get_minimal_resolution` that calculates the minimal resolution of the metrics for different services. The minimal resolution is the smallest time difference between consecutive data points in the metrics.
The ... | codefeedback |
You are tasked with creating a Python package for a reservation exchange system. The package should include an app configuration that specifies the default app configuration for the reservation exchange system. The provided code snippet sets the `default_app_config` variable to `'respa_exchange.apps.RespaExchangeAppCon... | codefeedback |
You are tasked with implementing a user association manager for an external login system. The manager will handle the association of external user accounts with local user accounts in a forum application. The code snippet provided is the beginning of the `UserAssociationManager` class, which takes three dependencies: `... | codefeedback |
You are working on a data analysis project and need to create a Python function to calculate the mean of a list of incorrect vector values and visualize the data using a scatter plot. The incorrect vector values represent errors in a machine learning model's predictions. Your task is to write a function that takes a li... | codefeedback |
You are tasked with implementing a class that manages the preparation and execution of a series of tasks. The class, named `TaskManager`, has an internal method `_prepare` that is called to set up the necessary parameters before executing the tasks. The `_prepare` method checks if the parameters are already set and if ... | codefeedback |
You are tasked with implementing a simple moving average calculation for a given set of data points. The moving average is calculated by taking a window of a specified size and computing the average of the values within that window as it moves through the data. Your task is to write a function that takes a list of data... | codefeedback |
You are tasked with creating a Rust function that simulates the behavior of the `fs::create_dir_all` function. The `fs::create_dir_all` function creates a new directory and all its parent components if they are missing. Your task is to implement a similar function called `custom_create_dir_all` that takes a path as an ... | codefeedback |
You are tasked with creating a form validation function for a user registration page. The function should validate various input fields based on the provided rules. The rules are defined in an object format, where each key represents a field name and its corresponding value is an array of validation rules. The validati... | codefeedback |
You are tasked with implementing a custom decoding process for a data structure using Swift. The given code snippet is part of a larger Swift program that involves decoding data from a container using a custom decoder. The `innerDecoder` is obtained from the `container` using the `superDecoder(forKey:)` method, and the... | codefeedback |
You are working on a data visualization application that displays density matrices for different quantum states. The code snippet provided is a part of the application's user interface, where users can select different parameters to filter and visualize the density matrices. Your task is to implement a function that ta... | codefeedback |
You are tasked with implementing a Python function that simulates a simple game of rock-paper-scissors. The game should allow a user to input their choice (rock, paper, or scissors) and then randomly generate a computer's choice. The function should then determine the winner based on the standard rules of the game: roc... | codefeedback |
You are tasked with implementing a Python function that extracts a list of classes and functions from a given module and its submodules. The module structure is organized as follows:
- The main module is named `train`, and it contains a class `Trainer`.
- The submodule `model` contains a function `get_model`.
- The ma... | codefeedback |
You are tasked with implementing a thread-safe timestamp formatter using Java's `ThreadLocal` class. The provided code snippet initializes a `ThreadLocal` variable `TIMESTAMP_FORMAT` with a `SimpleDateFormat` object that formats timestamps in the "yyyy-MM-dd HH:mm:ss.SSS" format and uses the UTC time zone.
Your task i... | codefeedback |
You are given an array of integers `arr`. Your task is to write a function `lis_dp(arr)` to find the length of the longest increasing subsequence (LIS) in the given array using dynamic programming.
A subsequence of an array is a sequence that can be derived from the array by deleting some or no elements without changi... | codefeedback |
You are tasked with implementing a respawn system for a game character in Unity. The provided code snippet is a part of the respawn system script. The script includes a reference to the character's health, the initial position, and the respawn duration. The `Awake` method initializes the health component, and the `OnEn... | codefeedback |
You are tasked with creating a program that parses and extracts information from a configuration file in a specific format. The configuration file contains XML-like tags and attributes, and your program needs to extract the values of certain attributes based on given criteria.
Given the following code snippet as an ex... | codefeedback |
You are tasked with creating a program that simulates a simple text-based adventure game. The game will involve a series of rooms, each with its own description and potential actions that the player can take. The player will navigate through the rooms by choosing different actions, and the game will respond accordingly... | codefeedback |
You are tasked with creating a custom Angular directive that dynamically loads and displays content based on a specified condition. Your directive should be able to handle both eager and lazy loading of components and ensure that the content is displayed securely.
Your directive should have the following requirements:... | codefeedback |
You are tasked with implementing a class that manages command fields within a command scope. The class should provide methods for extracting specific command fields based on their group and name. You are given a partial code snippet for the implementation of this class, and your task is to complete the implementation o... | codefeedback |
You are tasked with implementing a retry mechanism for a network client that makes HTTP requests. The client should automatically retry the request if it times out, up to a specified maximum number of retries. You are given a partial implementation of the client and the test case for the retry functionality.
The `CSRC... | codefeedback |
You are tasked with implementing a function that processes a resolution and returns a specific value based on certain conditions. The resolution is represented using the following Rust code snippet:
```rust
let (is_unit, unit) = if resolution.target().module(0).is_unit() {
(true, Arc::clone(&resolution))
} else {
... | codefeedback |
You are tasked with implementing a function that reverses the order of elements within a given sequence. The sequence is represented as an array of integers, and the reversal operation should be performed based on a specified axis. The axis indicates the dimension along which the reversal should occur. For example, if ... | codefeedback |
You are working on a deployment script for a Linux system and need to automate the setup of user-specific configurations for the XFCE desktop environment. Your task is to write a shell script that performs the following actions:
1. Copy the file "archlogo-full.svg" to the "/usr/share/icons/" directory using sudo privi... | codefeedback |
You are tasked with implementing a validation function for Bank Identifier Code (BIC) and International Bank Account Number (IBAN) in Swift. The BIC is used to identify a specific financial institution, while the IBAN is used to identify an individual account involved in international transactions. Your task is to crea... | codefeedback |
You are tasked with creating a Python class that manages a file system. The class should provide methods for creating, deleting, and listing files and directories, as well as for navigating through the file system.
Your task is to implement the `FileManager` class with the following methods:
1. `create_file(file_name:... | codefeedback |
You are tasked with implementing a permission-checking function for a web application. The function should determine whether a user has the necessary permissions to access a specific feature based on their user type and role permissions.
You are given a code snippet from a Laravel Blade template, which checks if a use... | codefeedback |
You are tasked with creating a Python program that processes a list of integers and performs specific operations on them. Your program should define a function `process_numbers` that takes in a list of integers and performs the following operations:
1. Calculate the square of each number in the list.
2. Sum all the squ... | codefeedback |
You are tasked with creating a program that can extract the name of a player mentioned in a given text. The text will contain a placeholder "<NAME>" which needs to be replaced with the actual name of the player. The player's name will be surrounded by a "#" symbol on both sides. Your program should be able to identify ... | codefeedback |
You are tasked with creating a Python program that processes a list of metadata entries and extracts specific information from them. Each metadata entry is represented as a string in the format "key :: value". The keys and values are separated by the string " :: ".
Your program should extract the unique programming la... | codefeedback |
You are tasked with creating a Django model for an IP address management (IPAM) system. The IPAM system needs to store information about hosts and their associated IP addresses. Each host can have multiple IP addresses, and each IP address can be associated with only one host. You need to define the Django model to rep... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.