instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with creating a plugin system for a content management application. The system should allow the creation of stateful plugins and provide a way to define the visual appearance of the plugin editor. The plugin system should be implemented using TypeScript and React. Your task is to create a TypeScript int...
magicoder
You are tasked with creating a simple rock-paper-scissors game in C#. The game should allow the user to play against the computer for a specified number of rounds. The program should keep track of the number of wins for both the user and the computer and display the final results at the end of the game. Your task is t...
magicoder
You are tasked with implementing a custom networking library in C#. The library should support managing connection statuses and handling network events. To achieve this, you need to create an enum representing different connection statuses and a method to handle a network event based on the current connection status. ...
magicoder
You are tasked with implementing a photo editing feature that allows users to crop images within a specified rectangular overlay. The provided code snippet is part of a larger photo editing application and contains methods related to image cropping and manipulation. Your task is to implement the `crop()` method and th...
magicoder
You are tasked with creating a password strength checker function in JavaScript. The function should take a password as input and return a strength score based on the following criteria: - Length: 5 points for a password length of 8 characters or more, 3 points for 6-7 characters, and 1 point for 1-5 characters. - Comp...
magicoder
You are given a directed graph represented as an adjacency list and a starting node. Your task is to implement a depth-first search (DFS) algorithm to find all possible routes from the starting node to all other nodes in the graph. Each route should be represented as a list of nodes visited in sequence. You should imp...
magicoder
You are tasked with creating a script to simulate a simple dice game using the Bash scripting language. The game involves rolling a six-sided die multiple times and keeping track of the outcomes. Your script should generate a sequence of random numbers representing the dice rolls and then calculate the frequency of eac...
magicoder
You are tasked with implementing a simplified version of a web server request forwarding mechanism. The provided code snippet is a part of this mechanism and is responsible for setting the `Content-Type` and `Content-Length` headers for the forwarded request. The `forwardTo` object represents the destination request, ...
magicoder
You are given a dataset containing three-dimensional coordinates and corresponding labels. Your task is to implement a Python function that calculates the Euclidean distance between each pair of points and returns the average distance for each label. The function should take the following inputs: - `X`: A list of x-co...
magicoder
You are tasked with implementing a Java class for representing a comic book in an online comics store. The class should encapsulate the necessary attributes and methods to manage the details of a comic book, such as title, author, price, and availability. Your task is to complete the implementation of the `ComicBook` ...
magicoder
You are tasked with creating a Java program that interacts with a server to predict future events. The server is accessed through a socket connection, and the program sends data to the server for prediction. Your task is to implement a method that sends a prediction request to the server using the provided code snippet...
magicoder
You are tasked with implementing a virtual function in a C++ program that simulates a medieval battle game. The game involves different types of units, such as knights, archers, and mages, each with their own unique abilities and attack strategies. Your goal is to implement the `attack` function for the `Knight` class,...
magicoder
You are working on a project that involves interacting with a gRPC-based API for SpaceX devices. The API provides various functionalities for managing and retrieving data from SpaceX devices. You need to implement a client application to communicate with the gRPC server and perform specific operations. Your task is to...
magicoder
You are tasked with creating a simple application to manage orders using Entity Framework Core in C#. The provided code snippet is a part of the application's data layer and defines a DbContext class named AppDbContext. This class is responsible for interacting with the database and includes a DbSet property for the Or...
magicoder
You are working on a web application that handles user registration. The application uses PHP for server-side scripting. You are tasked with implementing error handling for the user registration process. The code snippet provided is a part of the registration process and shows a try-catch block used to handle exception...
magicoder
You are tasked with implementing a class method that initializes an object from a JSON dictionary. The class `Metric` has a class method `init_from_json` that takes a JSON dictionary as input and returns an instance of the `Metric` class initialized with the values from the dictionary. The `Metric` class has the follo...
magicoder
You are tasked with creating a Python class to represent a pack and its versions in a modpack management system. The class should have the following functionalities: 1. Initialize the Pack class with a name and an empty list of versions. 2. Add a new version to the pack. 3. Get the latest version of the pack. 4. Get t...
magicoder
You are tasked with implementing a Java method that performs bitwise AND operations on different numeric data types. The method should take two parameters of type `Object` and return the result of the bitwise AND operation as an `Object`. The input parameters can be of type `Byte`, `Short`, `Integer`, or `Long`. The me...
magicoder
You are tasked with creating a function to generate a connection string for a SQL database. The function should take in the server name, database name, username, and password as input and return a formatted connection string. You are given the following code snippet as a starting point: ```cpp TStr TSqlConn::GetConnSt...
magicoder
You are tasked with creating a program that utilizes a pre-trained model to perform named entity recognition (NER) on a given text. Named entity recognition is the process of identifying and classifying named entities in unstructured text into predefined categories such as names of persons, organizations, locations, ex...
magicoder
You are tasked with simulating a simple communication system between two devices using channels in Rust. The system consists of a Gameboy device and a local sender, which communicate through a serial channel. The Gameboy device can send data to the local sender, and the local sender can respond with an acknowledgment s...
magicoder
You are tasked with implementing a Python module that provides a function for solving quadratic equations. The module should contain a function called `quad` that takes three arguments representing the coefficients of a quadratic equation in the form of `ax^2 + bx + c = 0`. The function should return a tuple containing...
magicoder
You are tasked with simulating a handshake protocol for data packets. The `PacketDescriptor` struct is used to describe each packet, containing the packet size and a boolean flag indicating whether the packet is encrypted. The `simulate_handshake` function takes in an array of packet descriptors, input data, and an out...
magicoder
You are tasked with implementing a custom data structure called `CustomCollectionView` in Swift. The `CustomCollectionView` is similar to a collection view in iOS and is used to manage and display a collection of `CellModel` objects. The `CustomCollectionView` has a method `insert` that allows inserting an array of `Ce...
magicoder
You are tasked with implementing a generic callback message class in Java. The callback message class should have the following features: 1. It should be a generic class that can hold a message of any type. 2. It should have a boolean flag to indicate the success or failure of the operation. 3. It should provide a sta...
magicoder
You are given a class `full_matrix` representing a 2D matrix of integers. The class has a constructor that takes a 2D initializer list to initialize the matrix. You need to implement a member function `add` that adds two matrices and returns the result as a new `full_matrix` object. The `add` function should perform e...
magicoder
You are tasked with implementing a Python metaclass that enforces a specific naming convention for class attributes. The metaclass should ensure that any attribute name starting with "attr_" must be in all uppercase letters. Any attempt to define an attribute violating this convention should raise a custom exception. ...
magicoder
You are tasked with creating a program that processes a given GitHub repository name and its corresponding number of stars. Your program should take the repository name and the range of stars as input and output the repositories that fall within the specified star range. Write a Python function `filter_repositories` t...
magicoder
You are tasked with creating a Python class that implements a mixin for handling tenant-specific data in a multi-tenant Django application. The mixin should be designed to work with Oracle database schemas. The mixin should provide methods for retrieving and manipulating tenant-specific data within the context of a mul...
magicoder
You are tasked with implementing a function that takes a Unix timestamp as input and returns the day of the week in Coordinated Universal Time (UTC). The function should utilize two helper functions: `conv_unixts_to_utc_hms(ts)` which converts the Unix timestamp to UTC time in hours, minutes, and seconds, and `get_day_...
magicoder
You are tasked with creating a script to automate the process of cloning a GitHub repository and its submodules based on certain conditions. Your script should handle the cloning of the main repository and its submodules, and it should be able to dynamically specify the branch to be used for the main repository. Write...
magicoder
You are tasked with implementing a function that simulates a rainbow color cycle. The function should take an integer `n` as input and return a list of RGB color values that represent a rainbow cycle. The rainbow cycle should smoothly transition through the colors of the rainbow, and the length of the returned list sho...
magicoder
You are tasked with creating a test case for a web application using Python's Django framework. The application includes a view called `user_list` that displays a list of users. Your goal is to write a test that ensures the user is redirected to the login page if they are not logged in when attempting to access the `us...
magicoder
You are tasked with simulating a simple network configuration using Python. Your goal is to create a program that sets up a virtual network interface, assigns IP addresses to the interfaces, and adds a default route within a network namespace. Your program should perform the following steps: 1. Create a network namesp...
magicoder
You are given a code snippet that contains a function with a mysterious behavior and a string `text`. Your task is to write a function that uses the given code snippet and the string `text` to perform a specific operation. The function in the code snippet has the following behavior: - It contains two `return` statemen...
magicoder
You are tasked with creating a Python script to automate the installation of required packages for a project. The script should check for the presence of specific packages and provide appropriate instructions if any of them are missing. Your script should perform the following tasks: 1. Check for the presence of the `...
magicoder
You are tasked with implementing a custom processor management system in C++. The system should allow users to register, unregister, and execute processors. Each processor is identified by a unique ID and can perform a specific task when executed. You need to create a class `ProcessorManager` within the `processors` n...
magicoder
You are working on a data processing pipeline for analyzing brain connectivity data. The given code snippet is part of a Python script that sets up parameters for model fitting and data processing. Your task is to implement a function that processes these parameters and returns a dictionary containing the relevant sett...
magicoder
You are tasked with designing a multi-threaded data processing system. The system consists of a data reading module and a data class that holds the data. The provided code snippet is a simplified representation of the system. The `read2` module contains a function `test` that reads data and updates the `data_class` wit...
magicoder
You are tasked with simulating a simple message queue system using Python. The message queue system consists of a publisher and multiple readers. The publisher sends messages to the queue, and the readers retrieve and process these messages. Your goal is to implement the functionality for the readers to retrieve messag...
magicoder
You are tasked with implementing a document management service that determines the content type of a given document based on its filename and binary URL. The service should support the identification of different document types such as PDF, Word, and others. You are provided with a code snippet from the test suite of ...
magicoder
You are tasked with implementing a program to process a list of tags and their counts. Each tag is represented as a string, and its count is a non-negative integer. Your program should take the list of tags and counts as input and output the tags along with their counts in a specific format. Write a function or method...
magicoder
You are tasked with implementing a class that manages mouse event listeners for a graphical component. The class should allow adding and removing mouse listeners and mouse motion listeners to a specified component. The class should also ensure that the listeners are correctly updated when the component changes. Your t...
magicoder
You are tasked with implementing a file processing system that filters out specific types of data from input files. The system should be able to skip processing of bad files and drop certain data fields from the input files. You are given a code snippet from the configuration file of the file processing system. The sn...
magicoder
You are tasked with creating a simple class in TypeScript to represent a geometric shape. Your task is to define a class `Shape` with the following properties and methods: Properties: - `side: string` - A string representing the type of the shape's sides (e.g., "square", "triangle", "circle"). Methods: - `getArea(): ...
magicoder
You are tasked with implementing a custom handler in an Android application. The handler should be responsible for processing messages on the main thread. Your goal is to create a class that extends the Android `Handler` class and overrides its `handleMessage` method to perform a specific task. Your task is to complet...
magicoder
You are given an array of non-negative integers `A` and an integer `K`. Your task is to add `K` to the array `A` and return the resulting array as a new array. The array `A` does not contain any leading zeros, and `K` is a non-negative integer. Write a function `addToArrayForm` to solve this problem, which takes in th...
magicoder
You are given a positive integer `n`. Your task is to write a function that takes `n` as input and returns the result of reversing the sign of `n` and then reversing the digits of the resulting number. For example, if `n` is 123, the function should return -321. If `n` is -456, the function should return 654. Write a...
magicoder
You are tasked with implementing a program to perform corner detection on a grayscale image using the Harris corner detection algorithm. The Harris corner detection algorithm is a popular method for identifying corners in images by analyzing variations in intensity. Your task is to write a function that takes a graysca...
magicoder
You are tasked with implementing a Python function that processes a list of tuples and returns a modified list based on specific criteria. The function should take in a list of tuples, where each tuple represents the margins of a content box in a graphical user interface. The function should then modify the list by dou...
magicoder
You are tasked with creating a function that calculates the viewport size of a web page. The function should handle scenarios where the viewport size is hard-coded to 0, as is the case with Chrome headless mode. You are given a code snippet that retrieves the viewport size and handles the Chrome headless mode scenario....
magicoder
You are tasked with implementing a stack data structure in C++. The stack should support the following operations: 1. `push(val)`: Add an element to the top of the stack. 2. `pop()`: Remove the element from the top of the stack. 3. `top()`: Return the element at the top of the stack without removing it. 4. `isEmpty()`:...
magicoder
You are tasked with implementing a class `SodaMachine` that simulates a soda vending machine. The class should have the following attributes and methods: Attributes: - `n_cans`: An integer representing the number of soda cans currently in the machine. Methods: - `__init__(self, initial_cans)`: A constructor method th...
magicoder
You are tasked with implementing a function that validates a set of properties for creating an Amazon WorkSpaces workspace. The properties are represented as a dictionary where the keys are the property names and the values are tuples containing the property type, required flag, immutability, and documentation URL. Yo...
magicoder
You are tasked with implementing a function that filters a list of numbers based on certain criteria. The function should take a list of numbers as input and return a new list containing only the numbers that meet the specified criteria. You are given the following code snippet as a starting point: ```python assert n...
magicoder
You are tasked with implementing a program to find the minimum path sum in a triangle. The triangle is represented as a list of lists, where each inner list represents a row of the triangle. The minimum path sum is the sum of the numbers along a path from the top to the bottom of the triangle, moving only to adjacent n...
magicoder
You are tasked with implementing a class that manages the visualization of a data structure. The class has a method `OnVisualizeToggle` that is called whenever the visualization state is toggled. Your task is to complete the implementation of the `OnVisualizeToggle` method to update the visualization based on the provi...
magicoder
You are tasked with implementing a class that manages descriptors for a database system. The given code snippet is part of a method within the descriptor class. The method takes in a dictionary `body` containing information about the descriptor, such as name, description, and fields. It sets these attributes in the des...
magicoder
You are tasked with creating a Python class that processes and analyzes sleep hypnograms. A hypnogram is a graphical representation of the sleep stages experienced by an individual over a period of time. The sleep stages are typically categorized as wakefulness, rapid eye movement (REM) sleep, and non-REM sleep (furthe...
magicoder
You are tasked with implementing a class that calculates the coverage of a given dataset. The coverage is defined as the percentage of non-null values in the dataset. You need to create a method `calculate_coverage` in the class `CoverageCalculator` that takes a dataset as input and returns the coverage percentage. Th...
magicoder
You are tasked with creating a Python function that generates a download link for a specific Sublime Text version based on the user's operating system and architecture. The function should take two parameters: `os_type` (a string representing the operating system) and `architecture` (a string representing the system ar...
magicoder
You are tasked with implementing a class that manages a list of items and provides methods for cleanup and stopping a load process. The class should have the following functionalities: 1. A method `cleanup` that stops the load process and removes items from a list based on a provided name list. 2. A method `stop_load`...
magicoder
You are tasked with creating a program to manage a music library by relating songs to their respective artists. Your program should allow users to add new songs and artists, associate songs with artists, and retrieve a list of songs by a specific artist. To achieve this, you need to implement a class-based solution usi...
magicoder
You are tasked with understanding and debugging a section of code related to a PPI8255 (Programmable Peripheral Interface 8255) in an embedded system. The code snippet provided is part of a larger program that interfaces with the PPI8255 chip to handle input/output operations. Your goal is to identify and fix any issue...
magicoder
You are tasked with implementing a command-line argument parser for a machine learning model training script. The script uses TensorFlow and requires several command-line arguments to be defined. Your task is to create a Python function that parses these command-line arguments and returns a dictionary containing the pa...
magicoder
You are tasked with creating a Python function that processes HTML content generated from Markdown text and extracts specific sections from it. You are given the following code snippet as a starting point: ```python import pypandoc import re def md2html(text): return pypandoc.convert_text(text, to='html5', forma...
magicoder
You are tasked with implementing a custom data structure called `CustomArray` that supports the following operations: 1. `operator[]`: Overloads the square brackets operator to access elements by index. 2. `writeToStream`: Writes the elements of the array to an output stream. The `CustomArray` class has the following...
magicoder
You are tasked with creating a class for an online learning platform that allows users to watch courses in different languages and gain skills. Your task is to implement the methods `watch_course` and `change_language` for the `User` class. The `User` class has the following attributes: - `name`: a string representing...
magicoder
You are tasked with implementing a function to shuffle a deck of cards. The deck consists of 52 cards, represented as integers from 1 to 52. Your task is to create a function `shuffle_deck(deck: &mut [i32; 52])` that shuffles the deck in place using the Fisher-Yates shuffle algorithm. The Fisher-Yates shuffle algorith...
magicoder
You are given a string representing a pattern of braces, brackets, and parentheses. Your task is to determine if the pattern is valid, meaning that every opening brace, bracket, or parenthesis has a corresponding closing one in the correct order. For example, the string "({})[]" is valid, while "({[})" is not. Write ...
magicoder
You are tasked with implementing a command-line tool for processing DNA sequence data. The tool should accept various command-line arguments to specify the input file, minimum identity threshold, and output file. The tool will read a file containing DNA sequence alignments and filter the alignments based on the minimum...
magicoder
You are tasked with implementing a function to retrieve the directory path of a given shader file. The function should take a `std::wstring` representing the shader file name and return the directory path where the shader file is located. You are provided with a partial code snippet for a `Renderer` class, which includ...
magicoder
You are tasked with creating a mock provider for a payment system in AngularJS. The `PayeesMockProvider` needs to be implemented to provide mock data for payees in the payment system. The provider should not have any dependencies injected into it. Your task is to implement the `PayeesMockProvider` in AngularJS, which ...
magicoder
You are tasked with creating a script that extracts a specific property value from a JSON file using different methods and then prints the value. The JSON file is stored in a variable `str` and the property to be extracted is stored in the variable `prop`. Three different methods are attempted to extract the property v...
magicoder
You are tasked with creating a custom tooltip component for a data visualization library. The custom tooltip should be implemented in React using TypeScript. The tooltip component should display information about the data points on a chart and should have customizable colors based on a predefined set of colors. You ar...
magicoder
You are tasked with creating a utility function to parse and process attributes of a custom class in C#. The custom class, `SCLExampleAttribute`, contains two properties: `SCL` of type `int` and `Description` of type `string`. Your task is to implement the `ParseSCLAttribute` function that takes an instance of `SCLExam...
magicoder
You are tasked with creating a Python function that securely handles sensitive information, such as database credentials, by obfuscating the password in a configuration file. Your function should read a configuration file, replace the actual password with a masked version, and then save the updated configuration file. ...
magicoder
You are tasked with creating a Python script to analyze the spread of information in a network using the Independent Cascade (IC) model. The script should take input parameters from the command line and use them to perform the analysis. The input parameters are as follows: - `-i` or `--file_name`: Specifies the name o...
magicoder
You are tasked with implementing a custom layer in Keras for a neural network model. The custom layer will perform a specific mathematical operation on the input data. Your task is to create a custom Keras layer that computes the element-wise product of the input tensor with a constant tensor. You are provided with a ...
magicoder
You are working on a software system that manages members and their properties. Each member has a set of schema properties and corresponding values. Your task is to implement a function that compares two member objects and determines if they are similar based on their properties and values. You are given a class `Memb...
magicoder
You are tasked with creating a Python function that manipulates strings to generate a specific output. Your function should take a string as input and perform the following operations: 1. Convert the input string to lowercase. 2. Replace all underscores ('_') with spaces (' '). 3. Capitalize the first letter of each wo...
magicoder
You are tasked with implementing a UIControlStateConverter class in Swift, which converts a string representation of a control state to the corresponding UIControlState enum value. The UIControlState enum represents the state of a control, such as normal, highlighted, disabled, and selected. The UIControlStateConverte...
magicoder
You are working on a computer vision project that involves processing facial images. You are given a code snippet that performs some operations on facial landmarks and bounding boxes. Your task is to implement a function that calculates the area of the bounding box after a random mirroring operation is applied to the f...
magicoder
You are tasked with creating a Python program that utilizes the `curses` library to handle user input and display an error message if the input is out of a specified range. The program should take an integer input from the user and then call the `out_of_range_error` function from within the `curses` wrapper to display ...
magicoder
You are tasked with implementing a Book class in Python that keeps track of the number of pages read by a reader. The Book class should have the following functionalities: - A constructor that takes the book's title and total page count as parameters and initializes the pages_read to 0. - A read method that takes the n...
magicoder
You are given a Python dictionary `d` containing integer keys and string keys. The dictionary may contain keys of different types. Your task is to write a function `count_keys(d)` that counts the number of keys in the dictionary for each key type and returns the counts as a dictionary. For example, given the following...
magicoder
You are tasked with implementing a simplified version of a callback system in Python. Your goal is to create a class that allows registering callback functions and triggering them with specific arguments. You need to implement a class `CallbackManager` with the following methods: 1. `register_callback(self, callback_f...
magicoder
You are tasked with implementing a custom iterator in Rust that can iterate over a collection of elements in both forward and backward directions. The iterator should be able to return the next element from the front and the back of the collection. Your task is to complete the implementation of the `DoubleEndedIterato...
magicoder
You are tasked with implementing a training unit system for a military simulation game. The system should handle the creation and presentation of new training units. Each training unit has a unique identifier, a name, and a status indicating whether the target is moving or not. The training unit should be presented wit...
magicoder
You are tasked with creating a test automation script for a mobile application using XCTest, a testing framework for iOS applications. The given code snippet is a part of the test script and contains interactions with various UI elements of the application. Your task is to write a function that simulates the tapping o...
magicoder
You are given a code snippet that represents a function in an unspecified programming language. Your task is to reverse engineer the function's behavior and implement a similar function in Python. The given code snippet is as follows: ```javascript function mysteryFunction(arr) { // Your code here } ``` Your tas...
magicoder
You are tasked with creating a Rust program that involves serializing and deserializing data using the `serde` library. The program will handle a struct representing a user entity and will need to serialize the struct into a JSON format for storage and later deserialize it back into the original struct. Your task is t...
magicoder
You are tasked with implementing a class that represents a backend blob and providing a method to deserialize JSON data into an instance of this class. You need to create a class `BackendBlob` with the following properties: - `Id` (string): Represents the unique identifier of the backend blob. - `Data` (string): Repre...
magicoder
You are tasked with creating a Python function that handles database connection errors and returns an appropriate HTTP status code and message. The function should catch specific database connection errors, log the error message, and return an HTTP status code and message based on the error type. You are provided with...
magicoder
You are tasked with implementing a function that saves a plot as an image file and/or displays it on the screen based on the provided parameters. The function `savefig_or_show` takes three optional parameters: - `dpi`: an integer representing the resolution of the saved image (default value is 100) - `save`: a boolean ...
magicoder
You are tasked with implementing a data transfer management system in Rust. The system is responsible for tracking the progress and timing of data transfers. You are provided with a partial code snippet for a `TransferManager` struct, which includes a method to retrieve transfer timings and a method to add a part of th...
magicoder
You are tasked with creating a role-based access control system for a web application. The system should allow users with specific permissions to perform actions on certain resources. In this scenario, you need to implement the authorization logic for deleting a question related to a subject. You are given a code snip...
magicoder
You are tasked with implementing a simple drawing program using the Pygame library in Python. The program should allow the user to draw squares on the screen and display text labels within the squares. The provided code snippet includes a function `fill_square` that draws a small square of a specified color at a given ...
magicoder
You are tasked with creating a notification system for a mobile application using Android's Notification API. The goal is to display a notification to the user when a certain event occurs in the application. You will need to create a class that encapsulates the logic for building and displaying the notification. Your ...
magicoder
You are tasked with creating a reinforcement learning agent to play the "SC2MoveToBeacon" game using the OpenAI Gym environment. The environment provides an observation space and an action space, which are essential for training the agent. Your goal is to implement a function that initializes the environment, prints th...
magicoder