instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are given a Python code snippet that is part of a program to calculate the rating of branches in a tree structure. The code snippet is responsible for updating the rating of a branch based on the rating of its nodes and a factor. Your task is to implement a function that takes in the necessary inputs and returns th...
magicoder
You are tasked with creating a Python program to automate the generation of Abstract Syntax Tree (AST) visualizations for a given source file. The program should utilize subprocess to execute external commands and handle the generation of AST visualizations. Your program should perform the following steps: 1. Execute ...
magicoder
You are tasked with implementing a custom pagination feature for a book listing application. The provided code snippet is a partial implementation of a `BookMyListView` class, which is a subclass of several mixins and the `ListView` class. The `BookMyListView` class is responsible for displaying a list of books with ce...
magicoder
You are tasked with implementing a simplified version of the Eigenfaces algorithm for face recognition in Python. The Eigenfaces algorithm is a popular technique that uses eigenvalue decomposition and principal component analysis to recognize faces. In this problem, you will need to write a Python class that performs t...
magicoder
You are tasked with implementing a simple dependency injection system for a restaurant management application. The application uses the Swinject framework for dependency injection. The code snippet provided is a part of the application's startup process. The `AboutProtocol` is a protocol representing information about ...
magicoder
You are tasked with creating a script to automate the installation of a specific software package on a Debian-based system. The script should check for the presence of the required command, install the package if it is not available, and then perform some post-installation cleanup. Write a shell script that accomplish...
magicoder
You are tasked with implementing a function to process update requests for a file containing chunks of data. The function will take in the updated information, including an identifier, and update the file's contents accordingly. Additionally, the function will parse the updated file contents and store the chunks for fu...
magicoder
You are tasked with implementing a simple URL routing system for a web application using Python and Django. Your goal is to create a Django app called "blog" and register its URLs using the provided code snippet as a reference. You have been given a list `urls` containing the URL configuration file "blog.urls" and a v...
magicoder
You are tasked with implementing a function to parse and import a cryptographic key from a file. The function should handle the parsing of the key and return the parsed components. Additionally, the function should handle the case where the key file is not found or cannot be parsed, and return appropriate values in suc...
magicoder
You are tasked with implementing a file-saving mechanism for a 3D mapping process in a robotics application. The provided code snippet is part of a larger program responsible for mapping and logging the robot's pose estimation and 3D scene view. The code snippet shows a conditional block that saves the pose log informa...
magicoder
You are tasked with implementing a class for sending notifications to a specific server using a provided SCKEY. The class should have a method for sending a notification and a static method for initializing the SCKEY. You are given the following code snippet as a starting point: ```typescript /** * @static * @type ...
magicoder
You are tasked with creating a function that calculates the average score of a list of student scores. Each student's score is represented as an integer, and the average score should be rounded to the nearest whole number. Write a function `calculateAverageScore` that takes in a list of student scores and returns the ...
magicoder
You are tasked with creating a program that checks for updates in a software system. The system is represented by a series of nested HTML div and table elements, as shown in the code snippet below. Your task is to write a function that will parse the HTML structure and determine if any updates are available. The HTML ...
magicoder
You are tasked with creating a script to automate the setup of a Linux desktop environment. The script should start several background processes for various utilities and services. Your task is to write a Bash script that accomplishes this. Your script should start the following processes in the background: 1. Start t...
magicoder
You are working on a messaging application that communicates with a server to retrieve user information. The server uses encryption and decryption methods to secure the data transmission. Your task is to implement a Python class that handles the encryption and decryption of data sent to and received from the server. Y...
magicoder
You are tasked with creating a Python class that simulates a simple library management system. The class should allow users to add books to the library, borrow books, return books, and display the current inventory of books. Additionally, the class should keep track of the borrowing history for each book. Your task is...
magicoder
You are tasked with implementing a simplified version of the Arduino's `pinMode` and `digitalWrite` functions. The `pinMode` function is used to set the mode of a specific pin (input or output), and the `digitalWrite` function is used to set the digital output value of a pin. You need to create a class `Arduino` with t...
magicoder
You are working on a Python project that involves a system for handling logs and interacting with clients through an agent. The project has the following file structure: ``` project/ │ ├── main.py ├── api/ │ ├── __init__.py │ ├── log_handler.py │ └── client.py └── agent/ └── agent.py ``` The code snippet pr...
magicoder
You are tasked with creating a Python function that validates module and package names according to the PEP 8 naming conventions. The PEP 8 guidelines specify that module and package names should be short, all-lowercase, and not contain underscores. Your task is to implement a function that checks whether a given modul...
magicoder
You are tasked with creating a PHP function that processes an array of transaction data and returns a modified version of the array with specific transformations applied. The transaction data is represented as an array of associative arrays, where each inner array contains information about a single transaction. The t...
magicoder
You are given a Python code snippet that takes two integer inputs `a` and `b`, and then prints the greater of the two numbers if both `a` and `b` are within the range of 1 to 13 (inclusive). If `a` and `b` are not within this range, the code does not produce any output. Your task is to implement a Python function that...
magicoder
You are tasked with creating a Python script that dynamically imports modules based on a given version number. Your script should be able to handle different versions of a hypothetical `netapp` package and import the appropriate module based on the provided version. Write a function `import_netapp_module(version: str)...
magicoder
You are given a Python function `truncate_string` that takes a string `s` as input and returns a modified string. The function is defined as follows: ```python def truncate_string(s): return s[:-2] ``` Your task is to implement a similar function in another programming language, such as JavaScript. Write a functi...
magicoder
You are tasked with creating a Django migration for a model called `Theme`. The `Theme` model has a field named `time_end`, which needs to be altered to use a `DateTimeField` with a verbose name of `结束时间` (Chinese for "end time"). Your task is to write the migration code that achieves this alteration. Assume that the ...
magicoder
You are tasked with implementing a class that processes DICOM (Digital Imaging and Communications in Medicine) data. The DICOM standard defines a Field of View Sequence Item, which contains information about the field of view for a medical imaging study. Your task is to create a method that extracts and processes the f...
magicoder
You are tasked with implementing a simple graphics library for a new programming language. The library should support popups and widgets for creating graphical user interfaces. The library should have the ability to manage and display popups and widgets on the screen. Your task is to design a class structure for the g...
magicoder
You are tasked with creating a program that processes a given HTML file and extracts the content within specific HTML tags. Your program should be able to handle nested tags and output the extracted content in a structured format. Write a Python function called `extract_html_content` that takes two parameters: 1. `htm...
magicoder
You are tasked with implementing a system to manage filters for system calls in a Unix-like operating system. The system provides a `Filter` struct that allows users to define rules for handling system calls. Each rule specifies an action to be taken when a specific system call is made. The `Filter` struct has a method...
magicoder
You are tasked with creating a shell script that sets up the environment for a software development kit (SDK). The script should export the `SDK` variable to the parent directory of the current working directory and add the SDK's `bin` directory to the `PATH` environment variable. Write a shell script named `setup_sdk...
magicoder
You are tasked with creating a word search game generator. The game board is represented as a grid of characters, and the generator must create a word board by populating this grid with random letters. The generator should also be able to spawn new objects in a new window, excluding the old window. Write a function or...
magicoder
You are given two lists, X and Y, both containing integers. Your task is to write a function that calculates the dot product of these two lists. The dot product of two lists is obtained by multiplying each pair of corresponding elements and then summing up these products. For example, if X = [1, 2, 3] and Y = [4, 5, 6]...
magicoder
You are tasked with creating a utility function for a web application that determines the appropriate version number to use for serving static assets (scripts and styles) based on the application environment. The application has separate version numbers for scripts and styles, and it needs to handle both production and...
magicoder
You are tasked with creating a C++ class hierarchy for a game loader system using the SFML library. The game loader system should support different platforms, and the provided code snippet shows the beginning of a WindowsGameLoader class derived from a DesktopGameLoader class. Your task is to extend the class hierarch...
magicoder
You are given a class `ArrayProcessor` with a method `FindMaxSubarray` that takes an array of integers as input and returns the subarray with the maximum sum. Your task is to complete the implementation of the `FindMaxSubarray` method. The `FindMaxSubarray` method should find and return the contiguous subarray within ...
magicoder
You are tasked with creating a script to automate the process of backing up a specific directory to a designated location. The script should take the source directory path and the destination directory path as input and perform the backup operation. Additionally, the script should include error handling to ensure that ...
magicoder
You are tasked with implementing a function that processes a given JavaScript object and returns a JSON response with a specific structure. The function should take an object as input and return a JSON response with a "success" property set to true. You are to write a function named `generateSuccessResponse` that accom...
magicoder
You are tasked with creating a Python function that processes a list of strings representing measurements and calculates the average and standard deviation of these measurements. The measurements are in the format "measurement=value", where "value" is a floating-point number. Your function should return a tuple contain...
magicoder
You are tasked with implementing a Python generator function that processes a series of lines containing volume information and yields a dictionary for each line. The input lines consist of fixed-width fields, and the generator function should parse these fields according to a given list of field names and their corres...
magicoder
You are tasked with implementing a function that determines whether a given circle and rectangle intersect or not. The function should take two parameters: `circle` representing a circle object and `rect` representing a rectangle object. The circle object will have the properties `x` and `y` representing the coordinate...
magicoder
You are tasked with creating a program that simulates a simplified version of a dialog system using asynchronous programming in C#. The program should utilize the provided code snippet as a starting point and implement the necessary logic to handle user input and generate appropriate responses. Your task is to create ...
magicoder
You are tasked with implementing a simple smart pointer class in C++. The smart pointer should manage the memory of a dynamically allocated object and provide functionality for memory management and access to the object. Your task is to complete the implementation of the `SmartPtr` class by adding the necessary constr...
magicoder
You are tasked with implementing a bookmarking feature for a mobile application. The application has a `BookmarkController` class that manages the bookmarking functionality, and a `BookmarkViewController` class that displays the bookmarked content. The `BookmarkController` is initialized with a dependency and a listene...
magicoder
You are tasked with implementing a class selection system for a multiplayer game. The game allows players to choose their character class, but there are certain rules and restrictions that need to be enforced. The game code snippet provided below is a simplified version of the class selection logic. The code snippet is...
magicoder
You are tasked with creating a program that manages a repository of software projects. Each project has a name and a description. Your program should allow users to perform various operations on the repository, such as adding a new project, removing an existing project, and listing all the projects in the repository. ...
magicoder
You are tasked with implementing a simple locking mechanism using C++ classes. The provided code snippet shows a part of a class that includes a `lock()` and `unlock()` method. Your task is to complete the implementation of the `lock()` and `unlock()` methods to ensure proper synchronization and thread safety. Your im...
magicoder
You are tasked with implementing a function that processes a list of integers and returns the maximum sum of a contiguous subarray within the list. The function should have the following signature: ```swift func maxSubarraySum(_ nums: [Int]) -> Int { // Your implementation here } ``` The function should take in a...
magicoder
You are tasked with implementing a function to determine the number of closing curly braces (`}`) that are not preceded by any opening curly brace (`{`) within a given string. The function should take a string as input and return the count of such closing braces. For example, given the input string: ``` }abc}def}ghi}j...
magicoder
You are tasked with creating a Rust module that provides analysis and manipulation of a Federated Byzantine Agreement System (FBAS). The FBAS consists of nodes and quorum sets, where each node has a unique identifier (NodeId) and a set of nodes (QuorumSet) that it trusts. Your goal is to implement a function that filte...
magicoder
You are tasked with implementing a subscription management system for a streaming service. The system should allow users to subscribe to and unsubscribe from various streams. You are given a partial code snippet for the subscription management system. The code includes a test method for unsubscribing from a stream and...
magicoder
You are tasked with implementing a simplified version of the `bitstruct` function, which is similar to Python's `namedtuple` function. The `bitstruct` function takes in a name, size in bits, and a list of fields, and returns a class that represents a bit structure. The `bitstruct` function should create a class with t...
magicoder
You are given a function `fn` that takes an array of numbers `nums` and returns a single number. The function `testCase` is used to test the behavior of `fn` with different input arrays and expected output values. Your task is to implement the function `fn` according to the following specifications: The function `fn`...
magicoder
You are tasked with creating a Python script to fetch and process court calendar data from the Vermont Judiciary website. The script should be able to write the fetched data to a Git repository if the corresponding environment variable is set to true. The script should also be able to handle cases where the environment...
magicoder
You are tasked with implementing a simple caching system for a web application. The caching system should store the responses from HTTP requests and return the cached response if the same request is made again. You are provided with a partial implementation of the caching system in C# using Unity's `UnityEngine` librar...
magicoder
You are tasked with creating a custom migration in a Django project. Your task is to implement a migration that adds a new field to an existing model in the database. The model in question is called `Product` and it represents products in an e-commerce platform. The new field to be added is `stock_quantity`, which will...
magicoder
You are given a C++ class `Threshold` that represents a threshold value and a number associated with it. The class has the following structure: ```cpp class Threshold { public: int m_threshold; int m_number; }; ``` You need to implement a function `findMaxThreshold` that takes a vector of `Threshold` objects ...
magicoder
You are tasked with creating a Python function that checks the existence of a configuration file within a Flask application context. The function should take the file path as an argument and return a boolean value indicating whether the file exists within the application context. You are provided with the following co...
magicoder
You are working on a package management system for a software development company. The system involves a script that synchronizes package information from a central repository to individual project directories. The script, `sync_package_info.sh`, is responsible for copying the `package.json` and `CHANGELOG.md` files fo...
magicoder
You are tasked with creating a Python function that interacts with a web API to retrieve and process JSON data. The function should handle potential exceptions and log any errors that occur. Below is a skeleton of the function with some missing parts: ```python import logging import aiohttp async def fetch_and_proces...
magicoder
You are tasked with creating a Python program that organizes files in a directory and extracts the filenames without their extensions. Your program should perform the following tasks: 1. Create a new directory named `dir` using the `os` module. 2. Extract the filenames of all the files in the directory `mlresume` witho...
magicoder
You are tasked with creating a custom validation rule in Laravel to check if an email address is from a specific domain. The code snippet provided is the beginning of a Laravel job class called `SaveEmail` that will be responsible for saving email addresses to a database. Your task is to implement a custom validation r...
magicoder
You are tasked with implementing a Swift protocol that defines the requirements for a network configuration. The protocol should be designed to be used in conjunction with an existing `HTTPClient` and should include authentication headers and user-specific configuration. Your task is to create the protocol and implemen...
magicoder
You are tasked with implementing a function to manipulate a binary search tree (BST) in C++. The BST is represented using the following structure: ```cpp struct Node { int data; Node* left; Node* right; }; ``` You need to implement a function `void deleteNode(Node* root, int key)` that deletes the node wi...
magicoder
You are tasked with implementing a key-value data transfer mechanism between a mobile device and a smartwatch using Swift programming language. The provided code snippet is a part of a function that is responsible for sending a dictionary of keys and corresponding properties to the watch using `WCSession.default.transf...
magicoder
You are tasked with creating a Python function that simulates a simplified version of a Docker registry. Your function should take in a list of Docker image names and a list of commands, and then execute the commands on the images. The commands can be either "push" to add an image to the registry or "pull" to retrieve ...
magicoder
You are given a string `s`. Your task is to write a Python function `print_substring` that takes `s` as input and prints all the substrings of `s` except the first character. The function signature is: ```python def print_substring(s: str) -> None: # Your implementation ``` For example, if the input string `s` is...
magicoder
You are tasked with implementing a class that simulates a simple heat model using a grid. The model has a method to initialize the grid and two methods to retrieve the temperature values at specific grid points. Your task is to create a Python class `BmiHeat` that fulfills the requirements specified below. The `BmiHea...
magicoder
You are tasked with implementing a system for managing bids in an online auction platform. The provided code snippet shows the constructor of a service class called BidsServices, which is responsible for interacting with the database through repositories for Bid, User, and Auction entities. However, the comment "// TOD...
magicoder
You are tasked with implementing a function that performs a specific data transformation. The function takes three input arrays `x1`, `x2`, and `x3`, and applies a series of operations to produce an output array `a`. The operations involve handling NaN (Not a Number) and infinite values in the intermediate result. The...
magicoder
You are tasked with implementing a function that calculates the output length of an image after applying a series of strided convolutions. The function should take the width and height of the input image and return the resulting width and height after the convolutions. The given code snippet provides a starting point ...
magicoder
You are tasked with creating a Python function that encodes categories and subcategories for a given parent category using a specific encoding method. The function should take a parent category as input and return a list of encoded subcategories. The encoding method is defined by the `encode_category` method within a ...
magicoder
You are tasked with creating a Python function that processes a dictionary containing mirror URLs for different cloud providers and their corresponding mirror addresses. Your function should take this dictionary as input and return a new dictionary containing only the mirror URLs that are associated with the cloud prov...
magicoder
You are tasked with implementing a simple class that manages a view in a mobile application. The class, `ViewManager`, has a method `refreshViewTitle()` that updates the title of the view. However, the method is called using optional chaining, denoted by `self?.refreshViewTitle()`. Your task is to create the `ViewManag...
magicoder
You are tasked with creating a Python class that simulates a simple bot for a messaging platform. The bot will be initialized with a token and will have middleware functionality. Your task is to implement the `Bot` class and the `DefaultValuesMiddleware` class with the given specifications. The `Bot` class should have...
magicoder
You are tasked with implementing a Red-Black Tree data structure in Swift. A Red-Black Tree is a self-balancing binary search tree, where each node has an extra bit representing its color, either red or black. The tree satisfies several properties to ensure balanced and efficient operations. Your task is to implement ...
magicoder
You are given a code snippet that ends abruptly with the token `false`. Your task is to complete the code snippet by writing a function that takes an array of integers as input and returns the sum of all the positive integers in the array. If the input array is empty or does not contain any positive integers, the funct...
magicoder
You are tasked with creating a Python function that processes input parameters and generates a personalized greeting message. The function should take in a dictionary of parameters and return a formatted greeting message based on the provided name and title. If the name and title are not provided in the input dictionar...
magicoder
You are tasked with creating a script to automate the versioning of iOS projects. The script needs to update the CFBundleVersion and CFBundleShortVersionString in the Info.plist file of an iOS project. The CFBundleVersion should be set to the provided $VERSION, and the CFBundleShortVersionString should be set to the fi...
magicoder
You are tasked with implementing a function that calculates the total sum of two different types of values in a given dictionary. The dictionary contains keys representing the type of value and the corresponding values as integers. The keys are "y" and "s", representing "yellow" and "silver" values, respectively. Your ...
magicoder
You are tasked with implementing a graph data structure and its associated methods. The graph should support the addition of nodes and the printing of the graph's nodes. You are given the following code snippet as a starting point: ``` print(transfer) transfer.add_nodes() ``` Your task is to complete the implementa...
magicoder
You are given a code snippet that represents a simple command-line interface (CLI) for a file management system. The code snippet uses a special symbol `$@` which is used to represent the command-line arguments passed to the script. Your task is to write a Python function that processes the command-line arguments and p...
magicoder
You are tasked with creating a quiz application using React components. The application should have a `Quiz` component for displaying the quiz questions and options, and a `Container` component for styling and layout purposes. Your goal is to implement the `Home` component, which will serve as the main entry point for ...
magicoder
You are tasked with implementing a Python class that filters and processes streaming data from the Twitter API. Your goal is to create a class called `MyGeoFilterStreamer` that inherits from the `TwythonStreamer` class. The `TwythonStreamer` class is a part of the Twython library, which provides a convenient way to acc...
magicoder
You are tasked with implementing a Python module dependency resolver. Given a list of Python module dependencies and their relationships, your goal is to create a function that returns the order in which the modules should be imported to satisfy all dependencies. You are provided with a list of module dependencies in ...
magicoder
You are tasked with creating a Python function that interacts with an API to retrieve information about coding challenges and their rewards. The function should take in two parameters: `url` and `headers`. The `url` parameter specifies the type of reward to retrieve, and the `headers` parameter contains the headers req...
magicoder
You are tasked with implementing a simple combat system for a role-playing game. The provided code snippet is part of a larger game engine and contains two private methods: `doDamage()` and `getActer()`. The `doDamage()` method reduces the target's health points (`HP`) based on the attacker's attack strength, and the `...
magicoder
You are given a class named `DataProcessor` with some incomplete methods. Your task is to complete the methods according to the given specifications. The class has a private integer array `data` and a public method `processData` that takes an integer `n` as input. The `processData` method should perform the following o...
magicoder
You are tasked with implementing a Python class that represents a delay. The class should have the following functionalities: 1. A class method `display_name` that returns the string 'Delay'. 2. A class method `type_string` that returns the string 'delay' followed by a period if the argument `trailing_delim` is True, ...
magicoder
You are tasked with creating a Python function that processes a dataset and performs a specific type of data transformation. The dataset consists of a list of integers, and the transformation involves splitting the dataset into two separate lists based on a given threshold value. Your function should take the dataset a...
magicoder
You are tasked with creating a function that processes project data and returns a modified project object based on certain conditions. The function should take in the original project object and an optional `forkOptions` object, and it should return the modified project object according to the following rules: 1. If t...
magicoder
You are tasked with implementing a monitoring system for a web service using the provided configuration settings. The system should periodically poll the service's status and components, send notifications based on the status, and escalate issues if necessary. The configuration settings include various parameters such ...
magicoder
You are tasked with implementing a function to process and store extracted head meta data from a publication. The function should iterate through the keywords in the extracted meta data, normalize each keyword, and store it in the publication's database. If a keyword exceeds 100 characters after normalization, it shoul...
magicoder
You are tasked with creating a script that processes a text file for training a machine learning model. The script takes two inputs: the name of the file and the label to apply. It then performs several text processing operations on the file content. Your task is to complete the script by adding the necessary commands ...
magicoder
You are tasked with creating a function that calculates the height of a web page based on the given input parameters. The function should take into account different scenarios and return the appropriate height value. You are given the following code snippet as a starting point for your function: ```javascript functio...
magicoder
You are tasked with implementing a Python class that models a special effect for LED art installations. The class `Effect` has an `__init__` method that takes in two parameters: `led_art` (representing the LED art installation) and `name` (representing the name of the effect). Your task is to create a subclass of `Effe...
magicoder
You are given a mathematical problem to solve. Given a positive integer `a`, you need to find the highest possible value of `x` such that `2na ≡ x (mod a^2)`, where `n` is a non-negative integer. Write a function `highest_x_mod_a_squared(a)` that takes in a positive integer `a` and returns the highest possible value o...
magicoder
You are tasked with implementing a custom thread pool for executing tasks in a Java application. The thread pool should be capable of handling asynchronous tasks and logging the execution of each task using the Log4j framework. Additionally, the thread pool should be able to serialize the execution results of the tasks...
magicoder
You are tasked with implementing a custom neural network module in PyTorch for multi-task learning. The module, named `MultiTaskDense`, is designed to handle multiple tasks simultaneously and is initialized with the number of features and the number of tasks it will be handling. Additionally, it allows for a customizab...
magicoder
You are tasked with creating a middleware function for a Node.js application that implements basic authentication using the `BasicAuth` middleware and a service called `AppService`. The `BasicAuth` middleware is responsible for authenticating users using basic authentication, while the `AppService` provides various fun...
magicoder
You are working on a project to process data from a simulation and need to implement a clustering algorithm to group coordinates. The goal is to minimize the mean squared error, given the estimated covariances of the volumes and the noise process. You have access to a function `src_wiener_coords` that takes the simulat...
magicoder
You are tasked with implementing a class that represents a timer. The class, named `Timer`, should have the following functionalities: 1. Start the timer. 2. Stop the timer. 3. Get the elapsed time in seconds. You are provided with a partial implementation of the `Timer` class, which includes the `start` and `stop` me...
magicoder