instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with implementing a Python decorator that applies a color transformation to the output of a function. The decorator will convert the returned numerical value from the function into a color representation using the HSL (Hue, Saturation, Lightness) color model. The transformed color will then be printed to...
magicoder
You are tasked with implementing a graph neural network (GNN) model for semi-supervised node classification using the GraphSage algorithm. GraphSage is a popular GNN model that leverages neighborhood aggregation to learn node representations in a graph. Your goal is to complete the implementation of the `Encoder` class...
magicoder
You are working on a web application that handles payment processing. The code snippet provided is a part of the backend logic for creating and updating payment records in the database. The `Payment` class represents a payment entity, and the methods `create` and `update` are responsible for adding new payment records ...
magicoder
You are tasked with creating a Python plugin for a data management system. The plugin should be designed to check the health and status of various services within the system. To achieve this, you need to implement a function that will interact with the `ckanext.hdx_service_checker` module. The function should be able t...
magicoder
You are working on a water management system for a hydrology company. The system includes a class called `WaterMeter` which is used to monitor water usage. The `WaterMeter` class has the following attributes and methods: Attributes: - `id` (int): A unique identifier for the water meter. - `location` (String): The loca...
magicoder
You are tasked with creating a program that processes a dataset containing information about students' grades. The dataset is represented as a list of tuples, where each tuple contains the student's name and their corresponding grades in various subjects. Your task is to implement a function that calculates the average...
magicoder
You are tasked with creating a layout manager for a custom alert view in an iOS application. The alert view should be positioned within a parent view using Auto Layout constraints. The alert view has properties for its center, leading, and trailing spaces relative to the parent view. Your task is to implement a method ...
magicoder
You are tasked with creating a Rust function that loads Gitlab configuration from environment variables and returns a `GitlabConfig` struct. The `GitlabConfig` struct has two fields: `token` and `api_url`. Your task is to complete the implementation of the `load_from_env` function to load the `GITLAB_TOKEN` and `GITLAB...
magicoder
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...
magicoder
You are tasked with creating a function that processes a list of scenes in a mobile application. Each scene is represented by a unique identifier and a boolean flag indicating whether the scene is connected. Your goal is to implement a function that filters out the disconnected scenes and returns a list of connected sc...
magicoder
You are tasked with creating a Python function that extracts and concatenates the text content of all the HTML anchor tags (`<a>`) with `href` attribute starting with `"/news/show"` from a given URL. You are provided with a code snippet that retrieves the HTML content from the URL and uses BeautifulSoup to parse it. Yo...
magicoder
You are working on a deployment script for a software application. The script is designed to remove a specific directory and all its contents. The directory to be removed is denoted by the `${PREFIX}` variable. Your task is to write a function that takes the `${PREFIX}` as input and removes the specified directory and ...
magicoder
You are tasked with implementing a custom dataset class for a machine learning project. The dataset will be used to train a model for quality assessment of images. The dataset class should be designed to handle image data and associated labels. The labels are categorical and have a predefined count. Your task is to com...
magicoder
You are tasked with implementing a function to calculate the number of days in a given month of a specific year. The function should take an object as input, containing the month and year, and return the number of days in that month. You should consider leap years when calculating the number of days in February. The i...
magicoder
You are tasked with implementing a class that manages a company's employee data. The class should support the addition and removal of employees, as well as the retrieval of employees by their company. You are given a code snippet that demonstrates the removal of an employee from the company's employee list. Your task ...
magicoder
You are tasked with creating a program that simulates a shift pattern for a group of employees. The shift pattern is represented by a list of integers, where each integer corresponds to the shift number for a specific day. Additionally, you need to transcode the shift pattern using a provided library. You are given a ...
magicoder
You are tasked with implementing a 3D thinning algorithm for voxelized point cloud data. Voxelization is a process that converts a continuous 3D space into a discrete grid of voxels, where each voxel represents a small volume element. The input to your algorithm is a voxel set representing a point cloud, and your goal ...
magicoder
You are tasked with implementing a PNCounter data structure, which is a variant of a G-Counter used for tracking the number of positive and negative increments. The PNCounter supports increment and decrement operations, and it can be merged with other PNCounters to obtain a combined count. Your task is to implement th...
magicoder
You are given a 2D grid representing a maze, where each cell can be either empty (denoted by '0') or blocked (denoted by '1'). The maze is represented as a 2D array of integers. You need to find the shortest path from the top-left corner to the bottom-right corner of the maze. You can move in four directions: up, down,...
magicoder
You are tasked with implementing a class method for a Python class called `DataObject`. The method, `from_json`, should take a JSON dictionary as input and return an instance of `DataObject` with its attributes set based on the values in the JSON dictionary. The `DataObject` class has the following attributes: - `type...
magicoder
You are tasked with implementing a C++ program that utilizes serialization libraries to store and retrieve data. The program should be able to handle different serialization libraries and gracefully handle the absence of certain libraries. Your task is to implement a function `serializeData` that takes a string `data`...
magicoder
You are tasked with creating a Python function that processes a list of file paths and extracts the latest version number from each path. The version number is denoted by a leading 'v' character, and the function should return a list of tuples containing the original file path and the extracted version number. The fun...
magicoder
You are tasked with creating a Python function that processes a list of integers and returns the sum of all the even numbers in the list. However, the function should also handle any exceptions that may occur during the processing of the list. If an exception occurs, the function should print the exception and continue...
magicoder
You are tasked with creating a C++ module for a game-saving system. The provided code snippet is a part of the module implementation. The `SaveExtension.h` header file contains necessary declarations and definitions for the module. The `LogSaveExtension` is a logging category, and `FSaveExtension` is the module class b...
magicoder
You are tasked with implementing a function that simulates a simple game involving a player and a box. The game is played on a grid-based environment, and the player can push the box around the grid. The goal is to move the box to a specific target position. The game is turn-based, and the player can move in four direc...
magicoder
You are tasked with creating a script to automate the deployment of a Redisearch instance using Docker. The provided code snippet is a part of a shell script that aims to achieve this automation. The script starts a Docker container running the Redisearch image with specific configuration options. Your task is to comp...
magicoder
You are tasked with creating a function that simulates the behavior of a checkbox and its associated form values in an Angular application. The function should toggle the checkbox state and update the form values accordingly. You are given the following code snippet as a reference: ```typescript const brakeDeclaratio...
magicoder
You are tasked with implementing a function that links values in a lambda calculus expression to a stack of strings. The lambda calculus expression is represented using a custom data structure, and the linking process involves replacing certain values with their corresponding linked values from the stack. You are give...
magicoder
You are tasked with creating a Python program that involves defining a data model for a REST API using the Flask-RESTPlus library. The code snippet provided is a part of this process and demonstrates the usage of the `api.model` method to define a data model for a specific resource. Your task is to complete the progra...
magicoder
You are working on a simulation program for a vehicle's dynamic parameters. The program uses domain parameters to define the range of values for various attributes. One such domain parameter is the `UniformDomainParam`, which represents a uniformly distributed domain parameter with a specified mean and half-span. Your...
magicoder
You are given a list of integers representing the daily stock prices of a company. Your task is to write a function to calculate the maximum profit that can be obtained by buying and selling the stock on different days. However, you are only allowed to complete at most two transactions. Create a function `maxProfitTwo...
magicoder
You are tasked with implementing a file upload service in Swift using RxSwift. The `onUploadImgResp` function is responsible for handling the response after uploading an image file. Your task is to complete the implementation of the `onUploadImgResp` function to process the uploaded image data and return an observable ...
magicoder
You are tasked with creating a Python script that automates the process of organizing files in a directory. Your script should categorize files based on their extensions and move them into separate subdirectories. For example, all ".txt" files should be moved to a "txt_files" subdirectory, all ".jpg" files to a "jpg_fi...
magicoder
You are tasked with creating a Python program that simulates a simple color dictionary. The dictionary will store color names as keys and their corresponding RGB values as tuples. Your program should provide functionality to add new colors, update existing colors, retrieve RGB values for given color names, and remove c...
magicoder
You are tasked with implementing a function that retrieves an element from a data structure based on a given index or key. The function should handle different types of data structures and return the requested element. You are given the following code snippet as a starting point: ```rust pub fn element_reference(inte...
magicoder
You are tasked with implementing a function to normalize a URL scheme. The URL scheme should be converted to lowercase and any trailing colon (`:`) should be removed. The function should return the normalized URL scheme. You are given the following function signature: ```python def normalize_scheme(url: str) -> str: ...
magicoder
You are tasked with implementing a Python class method that coerces a given value into a tuple. The method should handle different types of input and return a tuple based on the input value. Your task is to complete the implementation of the `coerce` method in the given Python class. ```python class DataProcessor: ...
magicoder
You are tasked with implementing a Python class that generates random lists of unsigned 8-bit integers and writing test cases to verify its functionality. The provided code snippet contains a portion of a Python test case for the class `my_item_c`, which is intended to generate random lists of unsigned 8-bit integers. ...
magicoder
You are tasked with implementing a module resolution algorithm for a JavaScript project. The project has a file structure where modules are organized in directories, and each module is represented by a file. The project uses the ES6 module system, and module imports and exports are specified using the `export` and `imp...
magicoder
You are tasked with creating a Python function that processes genetic data using the `allel` library. The function should take in a NumPy array representing genetic variants and perform a specific operation on the data. Write a Python function `process_genetic_data(variants: np.ndarray) -> np.ndarray` that takes a 2D...
magicoder
You are tasked with implementing a custom scheduler protocol in Swift. The protocol, `sr5154_Scheduler`, is designed to handle background tasks and provide a mechanism for executing tasks and handling their results. The protocol `sr5154_Scheduler` has the following requirements: 1. It should have a method `inBackgroun...
magicoder
You are working on a system management tool that handles various tasks related to system services. One of the tasks involves stopping a service called "BACnetd" using a deferred operation. The code snippet provided is a part of the system management tool and is responsible for initiating the stop operation for the "BAC...
magicoder
You are given a code snippet that represents a mapping of integers to their corresponding percentage values as strings. Your task is to write a function that takes an integer as input and returns the percentage value as a string. If the input integer does not have a corresponding percentage value in the given mapping, ...
magicoder
You are tasked with implementing a ChemicalBasis class that represents the basis for chemical calculations. The ChemicalBasis class contains a map of chemical groups, where each chemical group is associated with its bind energy. Your goal is to implement the ChemicalBasis class and its associated methods to retrieve th...
magicoder
You are tasked with creating a BMI calculator program in Rust. The program should prompt the user to input their weight in kilograms and then calculate their BMI (Body Mass Index) based on the weight and a predefined height. The BMI should then be used to determine the classification of the user's weight status. The cl...
magicoder
You are tasked with creating a Python function that validates the authorization header in a given HTTP response. The function should take in the response object and a username-password pair, and return a boolean indicating whether the authorization header matches the provided credentials. The HTTP response object has ...
magicoder
You are tasked with implementing a function that checks whether a given string is a valid UTF-8 encoded sequence. UTF-8 is a variable-width character encoding capable of encoding all 1,112,064 valid code points in Unicode using one to four one-byte (8-bit) code units. The encoding is defined by the Unicode standard and...
magicoder
You are tasked with creating a Python program to manage a photo-sharing server. The program should read configuration settings from a file, initiate a logging system, and then prompt the user to start the photo upload process. Additionally, the program should clear the console before proceeding with the main functional...
magicoder
You are tasked with implementing a function to process user information based on a given username. The function should retrieve the user's details from a data source and handle cases where the user information is not available. You are provided with a code snippet that simulates the retrieval of user information. The...
magicoder
You are tasked with implementing a set data structure in Python without using the built-in set data type. Your set should support the following operations: 1. `add(element)`: Add the element to the set if it is not already present. 2. `remove(element)`: Remove the element from the set if it is present. 3. `contains(ele...
magicoder
You are tasked with implementing a function that checks whether a given string is empty or not. The function should return `false` if the string's content is empty, and `true` otherwise. You are provided with the following code snippet as a starting point: ```java /** * @return {@code false} if this string's content...
magicoder
You are tasked with implementing a class for a paraboloid geometry in a ray tracing library. The paraboloid is defined as a surface of revolution, and the class should provide methods for intersection testing, calculating the normal at a given point, checking if a point is inside the paraboloid, and computing the dista...
magicoder
You are tasked with implementing a function to synchronize the status of articles in a content management system. The function should iterate through a list of articles and update their status based on certain criteria. Each article has an ID, a status, and a last updated timestamp. The function should update the statu...
magicoder
You are tasked with implementing a stock market trend analysis tool using technical indicators. The given code snippet includes the import of functions `isTrendingUp` and `isTrendingDown` from the `technicalindicators` library, as well as an enum `AvailablePatterns` containing various stock market patterns. Your task ...
magicoder
You are tasked with implementing a Python class that represents a reshaping operator for multidimensional arrays. The class should provide methods for reshaping the input array and retrieving information about the input and output dimensions. Your task is to implement the `ReshapeOperator` class with the following spe...
magicoder
You are tasked with implementing a function to parse and process data from different types of Inertial Measurement Units (IMUs). The code snippet provided is a part of a larger program that handles different IMU types. When the program encounters an unsupported IMU, it raises a preprocessor error using `#error`. Your ...
magicoder
You are tasked with implementing a dependency injection framework for a Java application. The framework should support the `@Inject` annotation to automatically inject dependencies into classes. The `@Inject` annotation should be used to inject the `FlowContainer` dependency into the target class. Your task is to creat...
magicoder
You are tasked with implementing a custom dependency injection container in C#. The container should be able to resolve dependencies for various classes and interfaces. The container should support both constructor injection and property injection. Your custom container should have the following functionality: 1. Regi...
magicoder
You are tasked with creating a Python class that simulates a simple HTTP backend server for testing purposes. Your goal is to implement the `TestHttpBackend` class with the following functionalities: 1. Implement a `setUp` method that takes an optional parameter `timeout_seconds` (default value is 5). Inside the `setU...
magicoder
You are tasked with implementing a session-based alert system for a web application using Laravel Livewire. The code snippet provided is a part of a Blade template file and is responsible for displaying a warning alert if there is a 'warning' message in the session. The alert is dismissible and contains an icon, the wa...
magicoder
You are tasked with implementing a graph data structure in Java, called `Graph`, which will be used as the main structure in a system called GreyCat. The `Graph` should support the addition of nodes and edges, as well as the ability to retrieve all nodes and edges in the graph. Your task is to implement the `Graph` cl...
magicoder
You are tasked with implementing a program that processes a given Java Swing GUI code to extract and count the unique GUI components used in the code. The GUI code is represented as a string, and the components are identified by their naming convention. Each component is represented as "javax.swing.<ComponentName>". W...
magicoder
You are tasked with implementing a simple easing function in Rust. An easing function is commonly used in animations to create smooth transitions between values. The easing function takes in a time parameter and returns a value that has been eased based on a specified easing algorithm. You are provided with a struct `...
magicoder
You are tasked with implementing a data grid component for a wine cellar management system. The data grid should display information about different wines stored in the cellar. Each row in the data grid represents a specific wine, and the columns display the wine's ID, name, category, description, and year. Your task ...
magicoder
You are working on a build system for a cross-compilation tool, and you need to write a script to set the compiler flags based on the target architecture. The script should take the target architecture as input and then set the appropriate compiler flags for C, C++, and Fortran compilers. The target architectures and t...
magicoder
You are working on a scientific data analysis project and need to implement a class for fitting a linear model to a set of data points and computing the chi-square statistic to evaluate the goodness of fit. The class should have methods for fitting the model, computing the predicted values, and calculating the chi-squa...
magicoder
You are tasked with creating a Python function that interacts with a model deployment API. The function should take in the model developer's name, model description, and the API endpoint URL as input. It should then construct a JSON payload and make a POST request to the API endpoint using the `requests` library. If th...
magicoder
You are given the definition of a ListNode class as follows: ```python class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next ``` You are required to implement a function `reverseList` that takes the head of a singly linked list as input and returns the head of the r...
magicoder
You are tasked with implementing a simple game where a bird must navigate through a series of obstacles. The game is implemented using the Pygame library in Python. The code snippet provided is a part of the game's logic for handling the bird's movement in relation to the position of the floor. The relevant variables ...
magicoder
You are given a class `Rectangle` representing a rectangle with its width and height. Your task is to implement a method `getArea` that calculates and returns the area of the rectangle. Additionally, you need to implement a method `getPerimeter` that calculates and returns the perimeter of the rectangle. ```cpp #inclu...
magicoder
You are tasked with creating a program that extracts specific information from assembly attributes in a C# project. Assembly attributes are used to provide metadata about the assembly, such as the company, product, copyright, version, and informational version. Your task is to write a function or method that takes a s...
magicoder
You are tasked with creating a program to display a given number on a four-digit seven-segment display. The display consists of four digits, each capable of showing numbers from 0 to 9. The code snippet provided initializes a `FourDigitDisplay` object and sets the variable `n` to 0. Your task is to write a function `d...
magicoder
You are tasked with implementing a function that parses a string representing a remote procedure call (RPC) address and extracts the individual components. An RPC address is typically in the format `protocol://host:port`, where `protocol` is the communication protocol, `host` is the network address of the server, and `...
magicoder
You are tasked with creating a Python class that implements a basic calculator. The class should have the following methods: 1. `add`: This method should take two numbers as input and return their sum. 2. `subtract`: This method should take two numbers as input and return the result of subtracting the second number fr...
magicoder
You are tasked with implementing a sliding window algorithm to process a stream of data. The algorithm should be able to handle multiple input dimensions and provide the flexibility to adjust the window size. Additionally, the algorithm should support verbose logging, monitoring of the experiment, and the option to use...
magicoder
You are tasked with implementing a class that represents a geometric shape. The class should have a method to calculate and return the area of the shape. The shape in question is a rectangle, and the class should have attributes for its width and height. You need to implement the `Rectangle` class with the following sp...
magicoder
You are tasked with implementing a Python unit test for a function that calculates the factorial of a given number. The provided code snippet is a part of a unit test using the `assertTrue` method from the `unittest` module. Your task is to complete the unit test by writing the necessary code to test the factorial func...
magicoder
You are tasked with creating a program to manipulate and display text in a PDF document. Your program should read a string representing a tagline and display it centered at the bottom of the document. The tagline should be displayed using the Helvetica font with a font size of 12. You are given the following code snipp...
magicoder
You are tasked with creating a time tracking system for employees. The system should be able to track when an employee clocks in and out, and also handle any discrepancies in the clock-in and clock-out events. Your task is to implement a function that takes in a list of clock-in and clock-out events and returns the eve...
magicoder
You are working on a web application that handles name requests. The application has a service (svc) that provides functionality to save and update name requests. The code snippet provided is a part of a function that saves a name request and returns the updated name request object. Your task is to implement a functio...
magicoder
You are tasked with creating a Python function that generates a unique identifier for each user in a system. The function should take into account the user's name and age to create the identifier. The identifier should be a combination of the first three letters of the user's name, the last two letters of the user's na...
magicoder
You are tasked with implementing a function to calculate the y-coordinate of a point on a curve given its x-coordinate. The curve is defined by a mathematical function y(x), and the x-coordinate of the point is determined by a loop iterating over a range of values. Your task is to write a function that takes the x-coor...
magicoder
You are tasked with creating a Python class that generates Django tables using the django_tables2 library. Your class should have a method called `generate_table` which takes in the following parameters: - `app`: a string representing the app name - `model`: a string representing the model name for which the table will...
magicoder
You are tasked with creating a Python function that retrieves the Lunch Money API key from the environment variables using the `dotenv` library and then makes a GET request to a specific endpoint using the `requests` library. Your function should handle potential errors and return the response from the API. Your funct...
magicoder
You are tasked with implementing a reshaping function for a tensor data structure. The tensor is represented as a one-dimensional array of elements, and the reshaping operation involves changing the dimensions of the tensor while maintaining the total number of elements. You are given a class `Tensor` with the followi...
magicoder
You are tasked with creating a PHP class that handles user authentication for a web application. The class should be part of a namespace and utilize a form for user login and a service for displaying messages. Your task is to implement the `UserAuthenticator` class with the following requirements: 1. The class should ...
magicoder
You are tasked with implementing a custom iterator class in Python. The iterator should return the next element in a sequence each time it is called. Your task is to complete the implementation of the `CustomIterator` class by filling in the `__next__` method. The `CustomIterator` class should have the following behavi...
magicoder
You are tasked with implementing a filtering mechanism for MIME types in a Python web application. The MIME type consists of a major type and an optional minor type, separated by a forward slash (e.g., "text/html", "image/jpeg", "application/json"). The code snippet provided is a part of a class method used for filteri...
magicoder
You are tasked with creating a Rust program that processes hardware capabilities (HWCAP) values and performs specific actions based on the presence or absence of these values. The HWCAP values are represented as hexadecimal numbers and are encapsulated in an enum called `Hwcap`. The program should implement a function ...
magicoder
You are tasked with implementing a task management system in a mobile application. The system should display a list of tasks, each with a name, description, notification date, background color, favorite status, and completion status. Additionally, each task may have a checklist associated with it. The code snippet prov...
magicoder
You are tasked with creating a Python function that simulates a quiz question feature for a chatbot. The function `add_quiz_question` takes four parameters: `update`, `context`, and `response`. The `update` and `context` parameters are objects used in the Telegram Bot API, and `response` is an object containing informa...
magicoder
You are tasked with implementing a function to calculate the sum of all the 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, typically starting with 0 and 1. The first few numbers in the Fibonacci sequence are 0, 1, 1, 2...
magicoder
You are tasked with creating a TypeScript transformer that optimizes `if` statements by removing always falsy branches. The transformer should be able to detect and cancel out branches that are always false, such as those containing expressions that always evaluate to `false`, `true`, or basic string equality compariso...
magicoder
You are tasked with creating a program that analyzes the distribution of words in a given text file. Your program should read the text file, count the occurrences of each word, and then display the top N most frequently occurring words along with their counts. Additionally, the program should exclude common stop words ...
magicoder
You are tasked with implementing a memory manager for a gaming console. The memory manager is responsible for allocating and deallocating memory for game profiles. Each game profile has a unique identifier and a certain amount of memory associated with it. The memory manager should be able to switch between different g...
magicoder
You are tasked with implementing a custom size policy algorithm for a text browser widget in a graphical user interface (GUI) application. The size policy determines how the widget should be stretched or shrunk in a layout. The provided code snippet initializes the size policy for the text browser widget using the Qt f...
magicoder
You are tasked with creating a Python class that represents an EC2 security group. The class should have two properties, `eC2SecurityGroupName` and `eC2SecurityGroupOwnerId`, which are implemented using the `@property` decorator and the `pulumi.getter` method. The `eC2SecurityGroupName` property should return the name ...
magicoder
You are tasked with implementing a program that processes and displays the results of a series of tests. The program should read the results from an input source, process the data, and then display the results in a specific format. You are given a code snippet from the program that handles the display of the results. ...
magicoder
You are given a Python code snippet that processes a block of text data. Your task is to implement a function that performs similar processing on a given input and returns specific values based on the processed data. You need to implement a Python function `process_data(data: str) -> Tuple[int, int, List[List[str]]]` ...
magicoder
You are tasked with implementing a custom macro for a Rust application that deals with an Internet Relay Chat (IRC) client. The macro is intended to generate code for converting a struct into its owned version and implementing a custom debug trait for the struct. The macro `into_inner_raw!` is used to generate code fo...
magicoder