instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with creating a program that simulates a simplified version of a shell command execution. Your program should take a command as input and execute it, similar to how the `shell_exec` function works in PHP. However, for security reasons, your program should only allow a specific set of commands to be execu...
codefeedback
You are tasked with implementing a tunnel management system for a network proxy. The system should handle starting and stopping tunnel operations and managing completion handlers. The provided code snippet demonstrates the logic for calling the appropriate completion handler based on the current pending tunnel operatio...
codefeedback
You are tasked with implementing a Python class that handles a web services management (WS-Management) protocol. The provided code snippet is a simplified version of the `WsManProtocol` class, which is responsible for initializing the protocol and setting up the necessary headers for communication. Your task is to ext...
codefeedback
You are tasked with creating a command-line interface (CLI) tool using Rust's `structopt` library. The tool will be used to manage a sewing project, allowing users to build and deploy WebAssembly (wasm) files. Your task is to implement the missing parts of the CLI tool based on the given code snippet. You need to comp...
codefeedback
You are tasked with implementing a reinforcement learning algorithm to control the movement of a cart and pole system. The system consists of a cart that can move along a frictionless track and a pole that is attached to the cart. The goal is to keep the pole upright by applying appropriate forces to the cart. The sta...
codefeedback
You are tasked with creating a program that can analyze and manipulate HTML code. Your program should be able to identify the opening and closing tags of HTML elements and determine if they are properly nested. For the purpose of this problem, an HTML element is considered properly nested if every opening tag has a cor...
codefeedback
You are tasked with implementing a GPU-accelerated Discrete Non-uniform Fast Fourier Transform (DNFFT) algorithm for processing large-scale data in a scientific computing application. The provided code snippet is part of a GPU-accelerated DNFFT library and demonstrates the usage of the library's API for accumulation an...
codefeedback
You are working on a package management system for a software repository. The system allows users to specify dependencies for their software packages. Each dependency can have a type, such as "build" or "run", and may have multiple dependencies of its own. Your task is to implement a function that takes a list of depen...
codefeedback
You are tasked with creating a program to calculate the total and grand total of amounts in a financial report. The given code snippet is a part of a web template using a server-side templating language like Blade in Laravel. The snippet iterates through a collection of details and calculates the total amount for each ...
codefeedback
You are tasked with creating a script to manage the launch and execution of multiple processes in a robotics environment. The script should launch three separate processes sequentially and then wait for all of them to complete before exiting. The processes to be launched are as follows: 1. Launch the `turtlebot_teleop`...
codefeedback
You are tasked with testing a Python asynchronous function that interacts with files and patches external dependencies using the `unittest.mock` library. Your goal is to write a test case that ensures the function `get_current_version` correctly reads a file and returns the expected result. The function `get_current_v...
codefeedback
You are tasked with creating a Python class method that updates an alarm in a monitoring system. The method, `update`, takes in the `alarm_id` and a variable number of keyword arguments (`kwargs`) representing the attributes to be updated. The method first constructs the path to the alarm using the `_path` method, then...
codefeedback
You are tasked with creating a program to analyze and manipulate a collection of posts retrieved from a web application. Each post is represented as an associative array with the following structure: ```php $post = [ 'id' => 1, 'title' => 'Sample Post', 'content' => 'This is a sample post content.', 'au...
codefeedback
You are tasked with implementing a k-means clustering algorithm to group senators based on their voting history. The voting history is represented as a dictionary of senators and their corresponding votes. Each senator's voting history is a tuple of vote values. Your goal is to assign each senator to the nearest cluste...
codefeedback
You are given a code snippet that includes a function `C(int n, int k)`. Your task is to implement the `C` function to calculate the number of combinations (n choose k) using the union-find data structure. The union-find data structure is used to efficiently manage disjoint sets. It consists of two main operations: `f...
codefeedback
You are tasked with implementing a program to parse a PCAP (Packet Capture) file and extract specific information from the captured network traffic. The PCAP file contains a series of packets, each representing a unit of data transmitted over the network. Your goal is to extract the source and destination IP addresses ...
codefeedback
You are tasked with implementing a custom string manipulation function in Swift. The function should take a string as input and return a modified version of the string based on specific rules. The rules for modification are as follows: 1. If the input string contains the word "anchor", it should be replaced with "sailo...
codefeedback
You are working on a PHP application for a financial institution's savings and loan system. The application uses a database to store information about members and their transactions. You need to implement a function to insert data into the "simkopsis_simpanan" table and establish a relationship with the "simkopsis_angg...
codefeedback
You are tasked with creating a Python function that processes population data from a given CSV file and generates a line plot for the population trends of specific regions. The function should read the CSV file, filter the data for a specific division, and then create a line plot to visualize the population trends over...
codefeedback
You are tasked with creating a command-line utility for importing guest data from a CSV file into a system. The provided code snippet is a simplified version of a command class in a Python Django application. The `Command` class is a custom management command that takes a filename as an argument and calls the `import_g...
codefeedback
You are tasked with implementing a Tic-Tac-Toe game in C++. The game is played on a 3x3 grid, where two players take turns marking the spaces with their respective symbols (X and O) until one player wins or the game ends in a draw. Your task is to implement the `mark_board` and `game_over` functions for the Tic-Tac-To...
codefeedback
You are working as a data engineer at a tech company, and you have been tasked with creating a program to manage the schema of tables in a Spark environment. Your task is to write a Python function that takes in a table name, a list of new field names, and their corresponding data types, and adds these fields to the ex...
codefeedback
You are tasked with implementing a class for a data loader in Python. The class should support shuffling and batching of data for training machine learning models. Below is a simplified version of the class with some parts of the code omitted for brevity: ```python import numpy as np class CustomDataLoader: def _...
codefeedback
You are working on a data visualization project and need to create a program to generate histogram predictions and plot them using a specific library. The code snippet provided is a part of the program that plots histogram predictions for raw and averaged density data. Your task is to write a Python function that takes...
codefeedback
You are tasked with implementing a data preprocessing class for a time series forecasting model. The class is responsible for preparing input data for an LSTM (Long Short-Term Memory) neural network. The provided code snippet initializes some parameters and attributes of the class. Your task is to complete the class by...
codefeedback
You are tasked with creating a web application that displays a list of files along with their actions using the Yii PHP framework. The application should utilize the `GridView` widget to render the file index. The `GridView` widget is a powerful tool for displaying tabular data in Yii applications. Your task is to imp...
codefeedback
You are tasked with creating a script to process zip files containing CSV files. The script should create a directory for unzipped CSV files, check if the directory exists, and then proceed to unzip all the zip files in a specified directory into the created directory. You are given the following code snippet as a sta...
codefeedback
You are tasked with implementing a navigation system for a web application. The navigation system consists of nodes representing different pages or sections of the website. Each node has a unique key, text to display, and a URL to link to. The navigation system should also support a feature called "tail crumbs," which ...
codefeedback
You are tasked with implementing a function that processes race results and generates a JSON response for a web service. The race results are represented by a list of `RaceResult` objects, each containing information about a race, such as the participant's name, finish time, and race number. The function should convert...
codefeedback
You are tasked with creating a Python function to generate license types and teams for a software product management system. The function `create_license_types` takes in a list of products, a standard output stream, and an optional count parameter. It creates a specified number of license types for each product and wri...
codefeedback
You are tasked with implementing a reinforcement learning algorithm for an autonomous agent to navigate a grid-based environment. The algorithm uses the Advantage Actor-Critic (A2C) method, which involves updating the policy and value function based on the advantage of taking a particular action compared to the average...
codefeedback
You are tasked with implementing a transaction fee pool for a blockchain-based system. The code snippet provided is a part of a test suite for the `update_transaction_fee_pool` function in a Rust-based blockchain framework. The `update_transaction_fee_pool` function is responsible for updating the transaction fee pool ...
codefeedback
You are tasked with implementing a function to calculate the sum of all the elements in a given array that are divisible by a specific number. You are given an array of integers and a divisor. Your task is to write a function that takes the array and the divisor as input and returns the sum of all the elements in the a...
codefeedback
You are tasked with implementing a simplified version of a context registry system in C++. A context registry is a mechanism for managing and accessing various contexts or resources within an application. In this problem, you will create a simplified context registry that allows the registration and retrieval of contex...
codefeedback
You are tasked with implementing a custom exception handling mechanism for a PHP application. The given code snippet is part of a class that handles exceptions in a specific way. The `supportsException` method checks if the given exception is an instance of either `\PHPUnit_Framework_Exception` or `\PHPUnit\Framework\E...
codefeedback
You are tasked with implementing a message sending system that supports multiple message types and recipients. The system should be able to send messages to different types of recipients, such as email addresses, phone numbers, and user IDs. Additionally, the system should support sending different types of messages, s...
codefeedback
You are tasked with implementing a custom namespace management system in C++. Your goal is to create a class that can store and retrieve key-value pairs within a specific namespace. Each namespace should be able to hold multiple key-value pairs, and the system should support the ability to create, retrieve, update, and...
codefeedback
You are working on a project that involves converting raster images in the "rasters" directory to vector shapefiles in the "shapefiles" directory using the GDAL library in Python. The code snippet provided demonstrates a part of this process. Your task is to write a Python function that achieves the same functionality ...
codefeedback
You are tasked with implementing a function to process columns in a dataset and ensure that the returned column names are sorted. The function should take a dataset and a ColumnMapping object as input and return a Columns object containing utility columns and numerical feature names. The code snippet provided includes ...
codefeedback
You are tasked with implementing a function to apply text formatting properties to a control in a user interface. The function takes an `item` object containing various text formatting properties and a `control` object representing the UI control to be formatted. Your task is to write a function that applies the format...
codefeedback
You are tasked with implementing a program that simulates the allocation of threads to physical cores in a multi-core processor using the hardware locality (hwloc) library. The hwloc library provides a hierarchical tree of the machine's topology, allowing the program to discover and manipulate the processor's core stru...
codefeedback
You are tasked with implementing a reinforcement learning algorithm for a robotic arm to learn how to pick up objects. The algorithm uses a custom Python library with the following code snippet: ```python class ReinforcementLearningAgent: def __init__(self): self.epsilon = 0.1 @lab_api def sample(...
codefeedback
You are tasked with implementing a protocol for a collection view in a Swift application. The protocol should include three properties: `indexTitle`, `header`, and `footer`. The `indexTitle` property should be a read-only optional string, while the `header` and `footer` properties should be read-write and of type `Coll...
codefeedback
You are tasked with implementing a perceptron algorithm for binary classification. The perceptron is a simple linear classifier that learns a weight vector to separate two classes. Your goal is to complete the implementation of the `train_perceptron` function, which trains the perceptron using the provided training dat...
codefeedback
You are tasked with implementing a test runner for a series of test cases. The provided code snippet is a part of a test runner class that includes a property `test` representing a test case to be executed. When the `test` property is set, it triggers the execution of the test case and updates the status of the test ru...
codefeedback
You are tasked with creating a script to automate the process of copying files from a source directory to a destination directory. The script should be able to handle the creation of directories if they do not exist and copy files and directories recursively. Your task is to write a shell script that replicates the fu...
codefeedback
You are working on a computer vision project and need to write a Python function to process and annotate images of human figures. The function should take as input a list of dictionaries, where each dictionary represents a human figure detected in an image. Each dictionary contains information about the keypoints of th...
codefeedback
You are given a partial implementation of the merge sort algorithm in C++. Your task is to complete the implementation of the merge sort algorithm and write a function to merge two sorted subarrays. You need to implement the following functions: 1. `mergeSort`: A recursive function that sorts an array using the merge ...
codefeedback
You are tasked with creating a script to automate the update and upgrade process for a Linux system using the `apt` package manager. Your script should perform the following steps: 1. Update the package lists using `apt`. 2. List the available updates. 3. Perform the actual upgrade of the packages. Your script should...
codefeedback
You are tasked with implementing a Python class that manages configuration settings for a software package. The class should provide methods for creating a configuration file and returning the configuration object. Create a class `Configuration` with the following specifications: - The class should have an `__init__` ...
codefeedback
You are tasked with creating a Python function that processes a list of GitHub repository information and returns the total number of stars for repositories that pass a specific check. You are given a list of dictionaries, where each dictionary represents a GitHub repository and contains the following keys: - "name": ...
codefeedback
You are tasked with creating a navigation system for a mobile application. The application has multiple buttons, each corresponding to a different activity that should be launched when the button is clicked. You need to implement the logic to handle the button clicks and launch the appropriate activities based on the b...
codefeedback
You are tasked with creating a Python class that simulates a simple event registration system. The class should include methods for registering new events, validating event details, and providing default values for certain fields. Your task is to implement the `EventForm` class with the following requirements: - The c...
codefeedback
You are tasked with implementing a file parsing function to read and process a specific file format used for storing particle data in a molecular dynamics simulation. The file format consists of a series of hexadecimal numbers representing various properties of particles. Each particle's data is stored in a specific fo...
codefeedback
You are tasked with implementing a generic method that takes a supplier of nullable strings and returns a supplier of non-nullable strings. The method should ensure that if the input supplier returns a non-null string, the output supplier should also return a non-null string. If the input supplier returns a null string...
codefeedback
You are tasked with implementing a function to downscale an image to fit within a specified maximum width and height. You are given a code snippet that creates a directory path and saves an image using the Python Imaging Library (PIL). Your task is to complete the `downscale_image` function, which takes an original ima...
codefeedback
You are tasked with creating a custom query filter setting for a content management system (CMS) that handles content expiry. The system has a `ContentExpiryExtension` class, and you need to implement a query filter setting to handle content expiry based on certain parameters. The code snippet provided includes a test ...
codefeedback
You are tasked with implementing a generic abstract class for managing properties. The abstract class contains a method `Set` that takes an object of type `T` as a parameter. Your goal is to create a concrete subclass of this abstract class and implement the `Set` method to handle specific properties. Your task is to ...
codefeedback
You are tasked with creating a Python function that generates a specified number of elements in a sequence based on a given rule. The function should take in the number of elements to generate and return the resulting sequence. The function signature should be: ```python def generate_sequence(num_elements: int) -> Lis...
codefeedback
You are given a code snippet that performs some mathematical operations using the NumPy library in Python. Your task is to understand the operations being performed and write a function to achieve the same result using NumPy. The given code snippet performs the following operations: 1. Reshapes the array `x` and `y` t...
codefeedback
You are tasked with creating a program to calculate the cost of a speeding ticket based on the driver's velocity. The cost of the ticket is determined by the difference between the driver's velocity and the speed limit, with a fixed rate per unit of excess speed. If the driver's velocity does not exceed the speed limit...
codefeedback
You are given a list of integers and a target sum. Your task is to write a function that finds all unique combinations in the list that sum up to the target. Each number in the list may only be used once in the combination. The solution set must not contain duplicate combinations. For example, given the list [10, 1, 2...
codefeedback
You are tasked with implementing a data encoding and mapping mechanism for a specific type of data. The data consists of a series of key-value pairs, where the keys are strings and the values are integers. Your task is to create a program that can encode this data based on a specified encoding style and map the encoded...
codefeedback
You are tasked with implementing a role-based access control system for a web application. The system should allow different users to have different levels of access to various features based on their roles. You are provided with a code snippet that defines a set of static constants representing different actions that ...
codefeedback
You are given an array `prices` representing the prices of a stock on different days. The `i`-th element of `prices` is the price of a given stock on day `i`. Write a function `maxProfit` to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multip...
codefeedback
You are working on a mapping application that needs to efficiently update and redraw roads and intersections based on changes in the underlying map data. The code snippet provided is a part of the application's logic for handling these updates. The `app.draw_map.draw_all_unzoomed_roads_and_intersections` function is us...
codefeedback
You are given an array of integers. Your task is to find the integer that appears an odd number of times in the array. It is guaranteed that there will always be only one integer that fits this criterion. Write a function `findOdd(arr)` that takes in an array of integers as input and returns the integer that appears a...
codefeedback
You are given a grid representing a map of an asteroid field. Each cell in the grid can either contain an asteroid ('#') or be empty ('.'). Your task is to find the location of the best observation point from which the maximum number of asteroids can be observed. The observation point is defined as the location (x, y)...
codefeedback
You are tasked with creating a PHP function that processes and stores data from a form submission into a database using Laravel's Eloquent ORM. The function should take the form input data and insert it into a table named 'reactcrud' with columns for 'name' and 'email'. The provided code snippet serves as a starting po...
codefeedback
You are tasked with implementing a function to convert a given time in seconds to a string representation of hours, minutes, and seconds. The function should take an integer representing the time in seconds and return a string in the format "hh:mm:ss". For example, given 3665 seconds, the function should return "1:1:5...
codefeedback
You are tasked with implementing a function to validate and process monetary values based on a given currency and its formatting constraints. The function should take a monetary value as input and ensure that it adheres to the specified currency's formatting rules. For this problem, we will focus on the Euro (EUR) curr...
codefeedback
You are tasked with implementing a feature matching algorithm using SIFT (Scale-Invariant Feature Transform) and k-means clustering. SIFT is a method to detect and describe local features in images, while k-means clustering is a popular unsupervised learning algorithm used for clustering data points. Your goal is to de...
codefeedback
You are tasked with implementing a multithreading module in Python to handle concurrent execution of tasks. The module should provide a `Threader` class with the ability to start, pause, resume, and stop threads. Additionally, the `Threader` class should support passing arguments to the target function of the thread. ...
codefeedback
You are tasked with implementing a Python function to simulate the propagation of a wave through a medium using the Fresnel diffraction integral. The function `propIR` takes several parameters: `u` (the input wavefront), `step` (the spatial step size), `L` (the size of the observation plane), `wavel` (the wavelength of...
codefeedback
You are tasked with implementing a content deposit system for a blockchain-based platform. The system should allow users to deposit short content based on titles and topics. The provided code snippet outlines the interface for the content deposit system, which includes two virtual functions `queryByTitle()` and `queryB...
codefeedback
You are tasked with implementing a function that extracts the selector and class name from a given Angular component snippet. The snippet is a simplified representation of an Angular component decorator and template. The function should take the snippet as input and return an object containing the selector and class n...
codefeedback
You are tasked with implementing a version comparison function for a software package manager. The function should compare two version strings and determine if the current version is outdated compared to a remote version. The version strings follow a standard format of major.minor.patch, where each component is an inte...
codefeedback
You are given an array `nums` of distinct integers, which is initially sorted in ascending order and then rotated at an unknown pivot. Your task is to find the index of the pivot element, which is the only element in the array that is smaller than its previous element. If the pivot element does not exist, return -1. W...
codefeedback
You are tasked with implementing a custom collection class in PHP that mimics the behavior of Doctrine's `Collection` class. The custom collection class should support adding, removing, and iterating over elements, as well as checking for the existence of elements within the collection. Your custom collection class sh...
codefeedback
You are tasked with creating a function that extracts the text content within HTML `<a>` tags and returns them as a list of strings. The function should ignore any leading or trailing whitespace and should handle multiple `<a>` tags within the input HTML. Write a function `extract_link_text(html: str) -> List[str]` th...
codefeedback
You are tasked with implementing a custom writer discrimination module using PyTorch. The module should be designed as a subclass of `nn.Module` and should utilize a pre-trained ResNet-18 model as its base. Additionally, the module should have the capability to replace the model's head and freeze the network's layers. ...
codefeedback
You are working on a rendering system that uses a scene graph to represent the objects in a 3D scene. The code snippet provided is a part of a test case for the rendering system. The code snippet sets the transforms for two objects, `c1` and `c2`, and then adds them to a group `g`. The `renderImage` function is called ...
codefeedback
You are working on a project that involves parsing and interpreting a configuration file for a hardware device. The configuration file contains a series of key-value pairs, where the keys represent different registers and the values represent the configuration settings for those registers. Each key-value pair is repres...
codefeedback
You are tasked with creating a function that processes email templates based on certain conditions. The given code snippet is part of a web application's backend written in a PHP framework. It is responsible for rendering a table of email templates with their subjects and activation status. The `email_templates` array ...
codefeedback
You are tasked with implementing a class that represents a geometric transformation in a 2D space. The class should have the following properties and methods: Properties: - `Transform`: A read-only property that returns the transformation matrix associated with the geometric transformation. Methods: - `Apply(Point po...
codefeedback
You are tasked with creating a program that simulates a simple stock trading system. The program should allow users to buy and sell stocks, and display the current portfolio and cash balance. The user should be able to input commands to interact with the system. Your task is to implement the logic for handling the "se...
codefeedback
You are tasked with creating a function that processes a byte array and returns a string. However, the byte array may not always represent valid UTF-8 encoded data. In such cases, the function should return a predefined error message instead of attempting to convert the invalid data to a string. Write a function `proc...
codefeedback
You are tasked with implementing a Python program to solve a simple optimization problem using the Artificial Bee Colony (ABC) algorithm. The ABC algorithm is a metaheuristic optimization technique inspired by the foraging behavior of honey bees. In this problem, you will be required to implement the ABC algorithm to f...
codefeedback
You are given a Python code snippet that imports modules from the standard library. Your task is to write a program that analyzes the imported modules and provides a summary of their functionalities. Write a Python program that takes the imported modules from the given code snippet and generates a report containing th...
codefeedback
You are working on a pipeline sizing optimization problem for a network of interconnected nodes. The goal is to determine the optimal pipeline diameters for efficient fluid flow while minimizing costs. You are given a code snippet that involves various calculations and data structures related to this problem. Your task...
codefeedback
You are tasked with implementing a PictureService class that interacts with a remote server to retrieve and process images. The class should have methods for downloading images, resizing them, and saving them to the local file system. You need to implement the downloadImage, resizeImage, and saveImage methods in the Pi...
codefeedback
You are tasked with creating a Python function that simulates a simple text-based adventure game. The game will involve the player making choices that lead to different outcomes. The game will have a predefined storyline with multiple decision points, and the player's choices will determine the progression of the game....
codefeedback
You are tasked with implementing a custom scatter layout in Python for a graphical user interface (GUI) application. The custom scatter layout should support double-tap functionality, where upon double-tapping, the layout should reset its transformation to the original scale. You are provided with a code snippet that ...
codefeedback
You are given a Rust code snippet that defines a function `both` and a closure `clos`. Your task is to identify and fix the errors in the code to make it compile and run correctly. The `both` function takes a reference to `self` and a reference to a type `Tes` as input parameters and returns a `Result` containing a `S...
codefeedback
You are tasked with creating a logging system for a software application. The system should support colorizing log levels for better readability. You are given a code snippet that demonstrates the setup of a logging system using the XCGLogger library in Swift. Your task is to implement a function that takes a log level...
codefeedback
You are tasked with implementing a function that converts a dictionary of non-list numerical features into a TensorFlow Example object. The function should take the dictionary of features as input, convert them into TensorFlow features, and then create a TensorFlow Example using these features. The function should be ...
codefeedback
You are tasked with creating a Python program that can download a specified number of images from Bing using the `bing-image-downloader` library. Your program should take user input for the search query and the number of images to download. Additionally, the program should handle any potential errors that may occur dur...
codefeedback
You are tasked with implementing a custom value converter in a C# WPF application. The value converter should take an input value and convert it to a specified target type based on certain conditions. Your task is to complete the implementation of the `Convert` method in the provided code snippet. The `Convert` method...
codefeedback
You are working on a web application using the Python web2py framework. The framework provides various modules and tools to simplify web development. In this scenario, you are tasked with implementing user authentication and database access using the web2py framework. Your task is to create a web2py application that i...
codefeedback
You are tasked with creating a Python function that calculates the sum of all even Fibonacci numbers up to a given limit. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. In this problem, the sequence starts with 1 and 2. Your task ...
codefeedback