instruction_seed stringlengths 29 40.5k | source stringclasses 6
values |
|---|---|
You are tasked with implementing a simplified version of a channel affinity manager. The manager is responsible for maintaining a count of affinities associated with different channels and providing methods to increment and decrement these counts.
You are given a partial code snippet for the channel affinity manager c... | magicoder |
You are tasked with implementing a function that calculates the new value of a variable `E` after subtracting a given `ratio` from it. The variable `E` represents a quantity, and `ratio` represents the proportion of `E` to be subtracted. The function should handle both positive and negative values of `E` and `ratio`.
... | magicoder |
You are tasked with implementing a periodic callback mechanism using the given code snippet as a reference. The provided code snippet outlines a class with methods to start and stop a timer that executes a callback at specified intervals on a thread pool thread.
Your task is to create a class `PeriodicCallbackManager`... | magicoder |
You are tasked with creating a simple Angular 4 component that displays a greeting message. Your component should have a selector of "greeting-component" and should use a template file named "greeting.component.html". The component should take a "name" input and display a greeting message using this input. Additionally... | magicoder |
You are tasked with implementing a custom router for a Django REST framework application. The router should handle the registration of viewsets for different URL patterns. The provided code snippet demonstrates the registration of two viewsets with specific URL patterns using the `SimpleRouter` class.
Your task is to ... | magicoder |
You are tasked with creating a script to manage a set of processes using a custom process management file. The file contains a list of process IDs (PIDs) and their associated metadata. Your script should read the process management file, terminate the processes listed in the file, and then remove the file.
The process... | magicoder |
You are tasked with creating a Python package that provides functionality for converting units of measurement. The package structure is as follows:
```
unit_converter/
__init__.py
version.py
convert.py
utils.py
```
The `__init__.py` file contains the following code:
```python
from .version import __ve... | magicoder |
You are tasked with creating a PHP class that manages user access permissions for a web application. The class should have methods to check if a user has access to a specific feature and to generate HTML links based on the user's permissions.
Your task is to implement the `AccessControl` class with the following requi... | magicoder |
You are tasked with implementing a function to calculate the multi-class Area Under the Curve (AUC) for a given set of target labels and corresponding model output probabilities. The AUC is a widely used metric for evaluating the performance of classification models. In this problem, you will need to write a Python fun... | magicoder |
You are tasked with implementing a simple web application using the ASP.NET Core framework. The application is expected to display a title on a web page. The provided code snippet is from the controller action method responsible for setting the title to be displayed on the web page.
Given the code snippet:
```csharp
V... | magicoder |
You are tasked with creating a Python program that utilizes the News API to fetch and display the top headlines from a specific news source. The News API requires an API key for authentication, which can be obtained by registering on their website. Your program should use the provided API key to make a request to the N... | magicoder |
You are tasked with implementing a Python function that processes a list of variables and a dictionary containing question state data. The function should perform specific operations on the variables and the dictionary, as described below.
You are given the following code snippet as a starting point for your function:... | magicoder |
You are tasked with implementing a language translation service using the `transloco` library in a web application. The `transloco` library allows for internationalization and localization of the application's content. The provided code snippet initializes the `transloco` configuration with English as the default langu... | magicoder |
You are given a list of integers representing the scores of a game. The game has a special rule for scoring where the score of each player is the sum of their scores from the previous two rounds. However, the first two rounds are exceptions and have their own scores. Your task is to write a function that calculates the... | magicoder |
You are working on a multidisciplinary analysis framework for engineering design optimization. The framework uses a Python-based optimization library that allows you to define and solve complex optimization problems involving multiple disciplines and constraints. In this context, you need to implement a sensitivity ana... | magicoder |
You are tasked with creating a Python decorator that measures the execution time of a given function and logs the result. The decorator should be applied to the `get_representation` function in a Flask application. The decorator should print the execution time of the function in milliseconds and log this information to... | magicoder |
You are tasked with creating a Python function that simulates a simple database migration process. The function will take a list of migration operations as input and apply them sequentially to the database. Each migration operation is represented as a dictionary with the following keys: "operation" (a string indicating... | magicoder |
You are tasked with implementing a resource management system for a service. The system needs to update the values of various resources based on the service's availability and buffer constraints. You are given a code snippet that demonstrates the usage of a function `update_resource_values` to update the resource value... | magicoder |
You are tasked with creating a script to automate the process of obtaining an authentication token from a REST API. The provided code snippet is a part of the script, and it demonstrates the usage of cURL to send a POST request with JSON data to the API endpoint. The response from the API includes an authentication tok... | magicoder |
You are tasked with implementing a function to add color grading to a list of tweets based on their sentiment scores. The sentiment score of a tweet ranges from -1.0 (negative) to 1.0 (positive). The color grading should be from red for a sentiment score of -1.0 to green for a sentiment score of 1.0. You are required t... | magicoder |
You are tasked with implementing a data management system that handles various data sources. The system is designed to instantiate data sources based on provided configurations and handle exceptions that may occur during the instantiation process. Additionally, the system needs to set a specific data source that define... | magicoder |
You are tasked with implementing a file integrity checker that compares the MD5 hash of a local file with a precomputed MD5 hash stored in a dictionary. Your goal is to write a Python function that takes in the file path, the dictionary of precomputed MD5 hashes, and the filename as input and returns whether the local ... | magicoder |
You are tasked with implementing a Python class that simulates a simple bank account. The class should have methods to deposit funds, withdraw funds, and check the current balance. Additionally, the class should keep track of the total number of transactions (deposits and withdrawals) made on the account.
Your task is... | magicoder |
You are given a Python code snippet that simulates movement in a 2D grid. The code snippet contains a series of conditional statements that determine the direction of movement based on the input `dir` and then updates the current position accordingly. Additionally, the code snippet includes a loop that iterates `steps`... | magicoder |
You are tasked with creating a Python class that represents a World of Warcraft (WoW) account model. The class should inherit from a base class and include specific attributes related to a user's WoW account. Your task is to implement the `WAccountModel` class with the given attributes and their respective data types.
... | magicoder |
You are tasked with creating a bash script that takes two arguments: `SELF_IPV4` and `ALL_SERVERS_IPV4`. The script should perform a specific task using these arguments.
Your task is to write a bash script that extracts the last octet of the `SELF_IPV4` and appends it to each octet of `ALL_SERVERS_IPV4` to form new I... | magicoder |
You are tasked with implementing a function to process HTTP requests and generate appropriate responses. The function will receive an inbound request and an optional propagated error. It should handle the error, if present, and construct a response accordingly.
You are provided with a code snippet that demonstrates pa... | magicoder |
You are tasked with creating a Swift class that handles HTTP responses from a server. Your goal is to implement a method that parses the server's response and data to extract relevant information.
You are provided with the following code snippet as a starting point:
```swift
/// The server's response to the URL reque... | magicoder |
You are working on a Python package called "Featurize" that provides functionality for feature extraction. The package has a module with the following code snippet:
```python
if token is None:
sys.exit('Token is missed')
return FeaturizeClient(token=token, instance_id=instance_id)
__version__ = '0.0.22'
__all__ ... | magicoder |
You are tasked with implementing a class that represents properties for describing a PowerApps Common Data Service (CDS) database language. The class should include properties for the language name, version, and any additional relevant information.
Your task is to create a C# class named `PowerAppsLanguageProperties` ... | magicoder |
You are tasked with creating a simple command-line interface for controlling an ARM (Advanced RISC Machine) device. The user is presented with two options: to start or stop the ARM. The user is prompted to input their choice, and the program will continue to prompt the user until a valid input is received.
Your task i... | magicoder |
You are tasked with implementing a Swift class that handles JSON data for a fictional API endpoint. The class, named `APIDataHandler`, is responsible for parsing JSON data and managing the state of the API request. Your goal is to complete the implementation of the `APIDataHandler` class by adding a method to parse the... | magicoder |
You are working on a backend system for a web application, and you need to implement a function that processes a list of user data. Each user is represented by a dictionary with the following keys: "id" (an integer), "name" (a string), and "age" (an integer). Your task is to write a function that takes a list of user d... | magicoder |
You are tasked with implementing a class hierarchy for an indicator repository system. The `Indicator` class represents a generic indicator, and the `IndicatorRepository` class is a specialized class that extends the `Indicator` class to manage a collection of indicators.
Your task is to complete the implementation of... | magicoder |
You are tasked with implementing a class that represents a deck of playing cards. The class should have methods for shuffling the deck, dealing a card, and resetting the deck to its original order. The following code snippet is a part of the class that represents the deck of cards:
```php
class DeckOfCards
{
priva... | magicoder |
You are tasked with creating a Python function that processes a list of spans and performs various assertions on the attributes of these spans. Each span represents a request in a web application and contains attributes such as service, name, resource, span type, and error status. Your function should validate these at... | magicoder |
You are tasked with implementing a function to balance a string containing various types of grouping symbols. The grouping symbols include parentheses '()', square brackets '[]', and curly braces '{}'. The function should determine if the input string has balanced grouping symbols and return true if it does, and false ... | magicoder |
You are tasked with creating a script to automate the installation of essential web development tools on a Linux system. The script should install Node.js, Apache, and MySQL. Your script should handle the installation process for each tool, including any necessary dependencies and system updates.
Your script should pe... | magicoder |
You are tasked with creating a script that processes a given input file and performs specific operations based on the content of the file. The input file contains a series of commands and their corresponding arguments. Each command is on a new line and is in the format `command argument`. The script should read the inp... | magicoder |
You are given a code snippet written in Rust that calculates the sum of the digits of 100 factorial. Your task is to implement a function that achieves the same result in a different programming language, specifically in Python.
Write a Python function `sum_of_factorial_digits()` that calculates the sum of the digits ... | magicoder |
You are tasked with implementing a trading algorithm for a cryptocurrency exchange. The algorithm is designed to execute buy orders based on a specified price limit. Your task is to write a function that calculates the volume of the cryptocurrency to be bought based on the given price limit.
You are provided with a co... | magicoder |
You are tasked with creating a Python function that processes a given text file and extracts the license information from it. The text file contains a software license agreement in the form of comments, similar to the code snippet provided. Your function should read the file, extract the license information, and return... | magicoder |
You are tasked with creating a Python function that simulates a simple game. The game involves a player trying to reach a target number by incrementing their score. The function should take the target number as an argument and return the sequence of scores the player achieves before reaching or exceeding the target.
T... | magicoder |
You are tasked with creating a simple PHP class that manages a list of tasks. The class should allow adding tasks, marking tasks as completed, and listing all tasks. Additionally, the class should implement the necessary methods to integrate with the given Laravel controller.
Create a PHP class named `TaskManager` wit... | magicoder |
You are tasked with creating a program that calculates the mass of a substance based on its volume and density. The program should prompt the user to input the volume of the substance and then calculate and display the mass using the formula:
\[ \text{mass} = \text{volume} \times \text{density} \]
Where:
- \(\text{vo... | magicoder |
You are working on a job scheduling system that submits tasks to a computing cluster using the `bsub` command. The `bsub` command takes various options and parameters to specify the job's requirements and behavior. Your task is to write a Python function that constructs the `bsub` command and submits the job to the clu... | magicoder |
You are tasked with implementing a function to process data from a file and perform specific operations based on the content. The file contains tab-separated values and the function should load the data and manipulate it according to certain criteria.
You are given a Python code snippet that includes an import stateme... | magicoder |
You are tasked with implementing a Depth-First Search (DFS) algorithm to traverse a graph and find the connected components. The given code snippet provides a partial implementation of a graph class with an `add_edge` method to add edges between vertices and a `dfs` method to perform the depth-first search starting fro... | magicoder |
You are tasked with implementing a module resolution algorithm for a simple JavaScript module system. The system uses the `export` statement to make functions, objects, or primitives available for use in other modules. When a module imports another module using the `import` statement, the module resolution algorithm mu... | magicoder |
You are tasked with creating a script to automate the cleanup of unused packages and old Linux kernel images on a Debian-based system. The script should perform the following tasks:
1. Remove all automatically installed packages that are no longer required by any installed package.
2. Purge all residual configuration ... | magicoder |
You are tasked with creating a Python program that processes a file containing book information and then saves the processed data to another file. The program should take input and output file paths as command-line arguments and log the progress using the `logging` module. Additionally, the program should handle potent... | magicoder |
You are tasked with implementing a class that manages the configuration and staging of sandbox environments for a software deployment system. The class should provide methods for configuring a node, performing a preflight check, generating a unique key, configuring a sandbox, and staging the configured sandbox.
You ne... | magicoder |
You are tasked with implementing a simple VIPER (View, Interactor, Presenter, Entity, Router) architecture for a basic note-taking application. The VIPER architecture is a design pattern used to separate the concerns of an application into distinct layers, promoting better organization and maintainability. Your task is... | magicoder |
You are tasked with creating a scoring system for a game. The game has a player controller object that keeps track of the player's score. You need to implement a method to save the player's score using Unity's PlayerPrefs system. The provided code snippet shows a method that is intended to save the player's score using... | magicoder |
You are working on a web application project and need to organize the file paths for various static resources. The project has a predefined directory structure where static resources such as templates, CSS files, JavaScript files, JSON files, and image files are stored in separate directories. You are given the followi... | magicoder |
You are tasked with implementing a loss function for a machine learning model. The loss function calculates the mean squared difference between the average pixel values of input images and their corresponding labels. The function takes a dictionary `batch` containing input images and their labels, and a target value `t... | magicoder |
You are tasked with creating a Python function that loads a YAML configuration file and extracts specific information from it. The function should take a filename as input and return a dictionary containing the extracted information.
You are provided with the following code snippet as a starting point:
```python
impo... | magicoder |
You are tasked with implementing a custom class in Python that supports the bitwise OR operation with another object. The class should define the `__ror__` method to enable the use of the `|` operator when the custom class object is on the right-hand side of the expression. The `__ror__` method should then apply a spec... | magicoder |
You are tasked with implementing a function that takes a dictionary `dct` and returns a JSON string representation of the dictionary with a specific indentation level. The function should take two parameters: `dct` (the dictionary to be converted to JSON) and `indent` (the number of spaces to use for indentation). The ... | magicoder |
You are tasked with creating a Java class that simulates a simple media player. Your task is to implement the `MediaPlayerHelper` class, which should provide methods for playing audio files. The `play` method should take the application context and the resource ID of the audio file to be played. The method should use t... | magicoder |
You are tasked with creating a Python program that scans a given directory for files and categorizes them based on their file types. The program should utilize the `os` and `mimetypes` modules to achieve this. The program should prompt the user to input a directory path and then display a summary of the file types pres... | magicoder |
You are tasked with creating a Python function that utilizes FastAPI to implement a paginated endpoint for retrieving a subset of entities. The entities are represented by the `UserOut` class, which contains a `name` attribute. The function should accept two parameters: `page` and `page_size`, and return a JSON respons... | magicoder |
You are tasked with creating a Python program to simulate the movement of a turtle using the turtle graphics library. The turtle starts at the center of the screen and moves in a specific pattern based on a sequence of commands. Each command corresponds to a specific movement or action for the turtle.
You are given th... | magicoder |
You are tasked with designing a Swift protocol for an onboarding scroll view and implementing a function to load onboarding pages. The protocol and function are part of an onboarding feature in a mobile app.
The `OnBoardingScrollViewProtocol` is a weakly referenced protocol that defines the requirements for a scroll v... | magicoder |
You are working for a financial data analysis company that uses the Kraken cryptocurrency exchange API to retrieve and store price data. Your task is to create a Python function that interacts with the Kraken API to fetch the latest price of a specified cryptocurrency pair and store it in a MongoDB database using the `... | magicoder |
You are tasked with creating a custom template tag in Django to retrieve the most recent blog posts from a database. Your task is to implement the `get_recent_posts` function, which will be used as a template tag in Django templates. The function should take an optional argument `num` to specify the number of recent po... | magicoder |
You are tasked with creating a data validation system for a company's financial data. The system should enforce specific constraints on the properties of a `Company` class. The properties to be validated are `Description`, `RevenueUSD`, and `CEO`. The validation rules are as follows:
1. `Description` should have a max... | magicoder |
You are tasked with implementing a class that represents a subject with a default value. Your task is to create a class `SubjectWithDefaultValue` with the following specifications:
- The class should have a constructor that takes a string parameter `someValue` and sets the property `SomeValue` to the provided value.
-... | magicoder |
You are tasked with creating a word guessing game in Python. The game will randomly select a word from a predefined list, and the player must guess the letters of the word within a limited number of attempts. The player will be provided with a partially completed word, and they must guess the remaining letters to compl... | magicoder |
You are tasked with creating a program that simulates a simple job scheduler. The program should iterate through a list of directories and for each directory, iterate through a list of files. For each file, the program should print a message indicating that it is processing the file. If the file is a directory, the pro... | magicoder |
You are given two arrays `x` and `w`, representing vectors in a mathematical space. The arrays have the following dimensions:
- `x` has the shape `[batch_size, vector_dimension]`
- `w` has the shape `[vector_dimension, out_planes]`
Your task is to write a function `calculate_similarity(x, w)` that calculates the cosin... | magicoder |
You are tasked with implementing a simple web server in Python. Your server should handle incoming HTTP requests and extract the requested path from the request. The provided code snippet is a part of the server implementation, where `self.path` represents the path requested by the client.
Your task is to complete the... | magicoder |
You are tasked with implementing a simplified version of a tweak management system for startup applications. The system allows users to add and remove startup tweaks, which are represented as objects with a "clicked" event and associated functionality. Additionally, the system provides a group for organizing these twea... | magicoder |
You are tasked with creating a script that will automate the configuration of the `tmux` terminal multiplexer on a Fedora or Red Hat Enterprise Linux 8 system. The script should append a specific configuration line to the `/etc/tmux.conf` file. The configuration line to be added is `set -g lock-command locker`. This li... | magicoder |
You are tasked with implementing a network management system for a QEMU virtualization environment. The system involves allocating and managing network interfaces, generating MAC addresses, and opening a QEMU Monitor Protocol (QMP) socket for communication with QEMU instances.
You are provided with the following funct... | magicoder |
You are tasked with implementing a simple stack data structure in C#. A stack is a Last-In-First-Out (LIFO) data structure that supports two main operations: push, which adds an element to the top of the stack, and pop, which removes the top element from the stack.
Your task is to create a class named `Stack` that sup... | magicoder |
You are tasked with creating a class that manages a list of items with different types. The class should have a method to add items to the list and another method to retrieve all items of a specific type. To achieve this, you need to implement the `ItemManager` class with the following requirements:
1. Create a class ... | magicoder |
You are given a code snippet that involves using cross-validation to evaluate the performance of a machine learning model. Your task is to create a programming problem based on this scenario.
Write a function called `evaluate_model_performance` that takes in the following parameters:
- `model`: an instance of a machin... | magicoder |
You are tasked with implementing a function that simulates a simple asynchronous property-based testing framework. The framework should generate random input values, apply a user-defined predicate function to each input, and verify that the predicate holds true for all generated inputs. Additionally, the framework shou... | magicoder |
You are tasked with implementing a Python class for an InputBlock in a neural network architecture. The InputBlock class is responsible for defining the input layer of the network. The class takes in the number of channels and kernel size as input parameters and initializes the input layer accordingly.
Your task is to... | magicoder |
You are given a list of integers representing the scores of a game. The game has a rule that a player's score is the sum of the scores of the last two turns. However, if the last two scores are the same, the player's score is doubled. Your task is to write a function that calculates the total score for the given list o... | magicoder |
You are tasked with implementing a class for managing academic sessions. The class `SessionManager` is responsible for storing and managing a collection of `Session` objects. Each `Session` object represents a class session and has an associated ID. The `SessionManager` class provides methods for retrieving the stored ... | magicoder |
You are tasked with implementing a dependency injection container in TypeScript. Dependency injection is a design pattern in which a class receives its dependencies from external sources rather than creating them itself. In this problem, you will create a simple dependency injection container using TypeScript.
Your ta... | magicoder |
You are tasked with implementing a simple toggle functionality for a web page element using JavaScript. The provided code snippet is a part of a class that manages the toggling behavior. The `toggle()` method is responsible for toggling the `show` property between `true` and `false. When the `show` property is `true`, ... | magicoder |
You are tasked with creating a script that automates the build process for a software project. The project uses Git for version control and CMake for building. Your script should handle the necessary steps to build the project using the provided code snippet as a starting point.
Your script should perform the followin... | magicoder |
You are tasked with creating a PHP class that handles user authentication for a web application. The class should provide methods for user login, logout, and checking the authentication status. You need to implement the `Auth` class within the `PHPMinds\Action` namespace.
Your task is to complete the `Auth` class with... | magicoder |
You are tasked with creating a program that extracts author information from a given code snippet. The author information is enclosed within a comment block and consists of the author's name and email address. Your program should be able to parse the code snippet and extract the author's name and email.
Create a funct... | magicoder |
You are tasked with implementing a file monitoring system in a macOS application using the NSFilePresenter protocol. The NSFilePresenter protocol is used to monitor changes to files and directories in a coordinated manner. Your goal is to create a class that conforms to the NSFilePresenter protocol and handles the noti... | magicoder |
You are tasked with creating a Python program that processes a given XML file and extracts specific information from it. The XML file contains data related to various methods and their associated attributes. Your program needs to parse the XML file, extract the relevant information, and perform specific operations base... | magicoder |
You are tasked with implementing a user permission system for a web application. The provided code snippet includes a `has_perm` method and a `has_module_perms` method within a class, as well as a `UserData` model with a one-to-one relationship to a `User` model.
Your task is to create a Python class that extends the ... | magicoder |
You are tasked with creating a Python function that can determine if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, disregarding spaces, punctuation, and capitalization. Your function should return True if the input strin... | magicoder |
You are tasked with creating a program that simulates a simple game of dice. The game involves rolling two dice and summing the values. The program should allow the user to input the number of times they want to roll the dice and then simulate the rolls accordingly. After simulating the rolls, the program should displa... | magicoder |
You are tasked with creating a Python function that extracts the DOI (Digital Object Identifier) from a given string. The DOI is a unique alphanumeric string assigned to a digital object, such as an academic paper, and is commonly used for referencing scholarly articles.
Write a function `extract_doi` that takes a str... | magicoder |
You are tasked with developing a build configuration system for a software project. The build configuration system is responsible for setting various options that control the build process. Each option can be either enabled or disabled, and the final build configuration is determined by the combination of these options... | magicoder |
You are tasked with implementing a custom token authentication class in Python. The custom class should inherit from the `TokenAuthentication` class provided by the `rest_framework.authentication` module. Additionally, the custom class should set a specific keyword attribute to "Bearer".
Your task is to complete the i... | magicoder |
You are tasked with creating a Python script to automate the minimization of input files for a binary analysis tool. The script will iterate through a directory of vulnerability output files, extract relevant information from the file names, and then use this information to minimize the input files for each binary.
Th... | magicoder |
You are tasked with creating a Python function that processes a dictionary of setup parameters for a tax calculation system. The function should extract specific parameters and perform calculations based on the given inputs.
You are given a code snippet as a starting point:
```python
setup(name='fio_taxa',
base... | magicoder |
You are given a Bash script that processes an array called `INFO` using a loop. The script iterates through the elements of the array and prints each element to the standard output. However, the script is incomplete and needs to be modified to achieve the desired functionality.
Your task is to complete the Bash script... | magicoder |
You are working on a database migration script for a web application. The script is responsible for modifying the database schema to accommodate changes in the application's data model. One of the tasks involves downgrading the database schema by removing a specific column from a table. The database migration script is... | magicoder |
You are tasked with creating a program that reads a text file and counts the occurrences of each word in the file. Your program should ignore punctuation and consider words with different capitalizations as the same word. The program should then output the word count for each unique word in alphabetical order.
For exa... | magicoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.