instruction_seed stringlengths 29 40.5k | source stringclasses 6
values |
|---|---|
You are tasked with implementing a simplified version of a message passing system using Python's multiprocessing module. The system consists of two processes, a sender and a receiver, communicating through shared queues and a lock. The sender process generates a result using a given function and sends it to the receive... | magicoder |
You are working on a web application that sends emails to users for various purposes, such as password reset. The code snippet provided is a part of the email sending functionality. The snippet is written in PHP and uses the PHPMailer library to send HTML emails. The email contains a message in Portuguese and a link fo... | magicoder |
You are working on a data processing system that involves adding data to a configuration (cfg) using the `add_data` function. The `add_data` function takes three main arguments: the configuration (cfg), the data to be added, and a list specifying the data's location within the configuration. Additionally, the function ... | magicoder |
You are tasked with creating a Python program that interacts with a SOAP web service using the `zeep` library. Your program should handle exceptions that may occur during the interaction with the web service.
Write a function `call_web_service` that takes in a URL and a method name as input parameters. The function s... | magicoder |
You are working on a project that involves processing and manipulating data using PyTorch, a popular machine learning library. As part of your task, you need to implement a function that performs a specific operation on tensor data. The function takes in several input parameters and is responsible for concatenating two... | magicoder |
You are tasked with implementing a class that simulates a warehouse management system. The class, named `Warehouse`, should have a method `check_crate()` that checks the contents of a crate and performs specific actions based on the contents. The crate can contain either "fragile" items or "non-fragile" items. If the c... | magicoder |
You are tasked with implementing a method to process the output of a neural network model. The given code snippet is part of a larger class that handles the processing of the model's output. The method `getMaxResult` is used to find the index of the maximum value in the `result` array, which represents the output proba... | magicoder |
You are working on a project that involves processing data from a neural network. As part of this project, you need to implement a function that extracts specific elements from a tuple. The tuple contains gradients of the output with respect to the input, and you are required to retrieve the first element from this tup... | magicoder |
You are tasked with implementing a Python function that takes in a variable number of keyword arguments and returns a dictionary containing only the keyword arguments whose keys start with a specific prefix. Your function should be able to handle any number of keyword arguments and should return an empty dictionary if ... | magicoder |
You are tasked with creating a Python program that processes a given configuration file and performs specific operations based on the contents of the file. The configuration file is in the SeisComP format, and the program should handle any errors that may occur during the processing.
Your program should read the confi... | magicoder |
You are tasked with implementing a function that takes a list of integers as input and returns a dictionary containing the frequency of each integer in the list. The function should be named `count_frequency` and should take a single parameter `nums`, which is a list of integers. The dictionary returned should have the... | magicoder |
You are tasked with implementing a function to convert a given integer to a byte array using a specified byte order and then converting the byte array back to the original integer.
Write a Python function called `int_to_byte` that takes in three parameters:
- `num` (integer): The integer to be converted to a byte arra... | magicoder |
You are tasked with implementing a utility function in TypeScript that retrieves a value from a Monad or returns a default value if the Monad is undefined or null.
You are provided with the following code snippet as a starting point:
```typescript
import { Monad, MonadType } from "./main";
export function getValueOr<... | magicoder |
You are tasked with creating a Python script that securely sends an email using the Gmail SMTP server. To achieve this, you need to implement a function that takes in the sender's email address, the recipient's email address, the subject of the email, and the body of the email as input parameters. The function should t... | magicoder |
You are tasked with implementing a form data validation system in PHP. The system should include a validator class called `NotEmpty` that checks whether the input data is not empty. The `NotEmpty` class extends a base validator class called `BaseValidator` and overrides its `validate` method. The `validate` method take... | magicoder |
You are tasked with implementing a statistics library in C++ to calculate various statistical measures for a given dataset. Your goal is to implement the `variance` function in the `statistics` namespace, which takes a vector of numbers as input and returns the variance of the dataset. The variance of a dataset is a me... | magicoder |
You are tasked with solving a classic problem in combinatorics - the rabbit pairs problem. In this problem, you are given two positive integers, n and k, where n represents the number of months and k represents the number of offspring produced by each pair of rabbits. The problem involves calculating the total number o... | magicoder |
You are tasked with implementing a performance tracking feature for a firearms inventory management system. The system currently includes a `performanceStackView` that manages the layout of various performance-related views, and a `performanceTableView` that displays performance data for each firearm. Additionally, the... | magicoder |
You are tasked with creating a simple ASP.NET Core Web API that utilizes dependency injection and unit testing. Your goal is to implement a service that calculates the area of a circle based on its radius and then create unit tests to verify the correctness of the service.
Your service should be registered using Micro... | magicoder |
You are tasked with implementing a simple key-value store in Python using a dictionary. The key-value store should support basic operations such as adding a key-value pair, retrieving the value for a given key, and deleting a key-value pair. Additionally, you need to implement a method to retrieve all keys in the store... | magicoder |
You are given a Python class `SampleCollection` that represents a collection of samples. The class has the following attributes and methods:
Attributes:
- `samples`: a list of strings representing the samples
- `max_len`: an integer representing the maximum length allowed for each sample
Methods:
- `__len__(self)`: a... | magicoder |
You are tasked with implementing a function that filters a queryset based on the day of the week. The function should take a queryset and a day of the week as input and return the filtered queryset containing only the records created on the specified day of the week.
You are given the following code snippet as a start... | magicoder |
You are tasked with implementing a dynamic loader class in C++ that can load and execute shared libraries at runtime. The dynamic loader should be able to load a shared library, retrieve a function from it, and execute that function. You are provided with a code snippet for the DynamicLoader class, and you need to comp... | magicoder |
You are tasked with creating a Python function that processes email addresses and extracts the domain name from the recipient's email address. The function should handle potential errors and exceptions that may occur during the domain extraction process.
Write a function `extract_domain` that takes an email address as... | magicoder |
You are tasked with implementing a class that manages a portfolio of AI (Artificial Intelligence) units. The class, named `AIPortfolioManager`, should have a method `reset` that updates the unit type table and resets each AI unit in the portfolio.
The `AIPortfolioManager` class should have the following methods:
1. `r... | magicoder |
You are tasked with implementing a custom error handling system for a PHP web application. The application uses a namespace `app\components` and includes a class `ModelError` that extends the abstract class `BaseModelError`. The `ModelError` class is responsible for storing error messages and the attributes that trigge... | magicoder |
You are tasked with creating a Python function that processes data from a pandas DataFrame and handles missing values. The function should drop any columns with missing values, assign new column names, and then call another function to process the cleaned data. Your task is to implement the function that performs these... | magicoder |
You are tasked with creating a program that simulates a simple text-based user interface for highlighting text with different background and text colors. Your program should provide a method to highlight the input text with the specified background and text colors.
You are given the following code snippet as a startin... | magicoder |
You are tasked with implementing a thread-safe counter in Rust using the provided code snippet as a starting point. The `CounterInner` struct contains a field `count` of type `Cell<usize>`, which provides interior mutability for the counter value. Your goal is to create a public `Counter` struct that encapsulates `Coun... | magicoder |
You are tasked with creating a Python class that simulates a simple GUI application using the tkinter library. Your class should include methods for setting up the GUI components and configuring the window title. Additionally, you need to implement a method for disabling window resizing.
Your task is to complete the i... | magicoder |
You are tasked with implementing a function that processes user information and returns a modified version of the data. The user information is represented as a dictionary with the following structure:
```python
user_info = {
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com",
"status": "act... | magicoder |
You are tasked with implementing a peer validation system for a TCP server to protect against Denial of Service (DoS) and other attacks. The peer validation system will enforce a set of rules before allowing further processing of the peer connection.
Your task is to implement a function `validatePeer` that takes in a ... | magicoder |
You are tasked with implementing a function to calculate the Hamming distance between two DNA strands. The Hamming distance is the number of differences between two equal-length strands of DNA.
You need to create a function `hamming_distance` that takes two parameters, `strand1` and `strand2`, both of type `&str`, and... | magicoder |
You are tasked with creating a Python function that simulates a simplified version of the `azcli` command-line interface tool. The `azcli` function takes a command as input, executes it using the `subprocess` module, captures the output and error streams, and logs them using the `logging` module. If the command executi... | magicoder |
You are tasked with implementing a function to analyze the status of a linear programming problem using the Highs solver library. The given code snippet is part of a larger function that processes the status of the problem. The `dual_infeasibility` variable represents the absolute value of the dual infeasibility, and t... | magicoder |
You are tasked with implementing a function that parses and validates an argument list for a specific command. The argument list is represented as a string, where each argument is enclosed within parentheses and separated by a comma. Each argument can be either a literal string or a variable name followed by a colon an... | 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 in a case-insensitive manner. The program should then output the unique words along with their respective counts in alphabetical order.
For exampl... | magicoder |
You are tasked with creating a custom radio group component in React. The component should allow the user to select a single option from a list of radio buttons. The selected value should be stored in the component's state and updated when the user makes a selection. Additionally, the component should display an error ... | magicoder |
You are tasked with implementing a validation method for the `PayPalCheckoutOrderAddress` class in a PHP application. The class represents an address for a PayPal checkout order and contains properties for the name, street, and city. Your goal is to create a validation method that ensures the address properties meet ce... | magicoder |
You are tasked with implementing a function to enable specific features on a wireless communication module, such as the nRF24L01+. The module has various features that can be enabled, and the function `enable_features()` needs to be implemented to enable these features. The function should take into account the specifi... | magicoder |
You are working on a version control system and need to implement a feature that identifies the most active contributors to a given repository. The repository is represented by a collection of commits, each containing the name of the contributor who made the commit. Your task is to write a function that takes in the co... | magicoder |
You are tasked with implementing a function that parses a given JSON object and extracts specific key-value pairs based on a provided list of keys. The function should return a new object containing only the specified key-value pairs.
You are given the following code snippet as a starting point:
```javascript
const d... | magicoder |
You are tasked with implementing a filter service that processes a list of items based on certain criteria. The `FilterService` class provides methods for filtering a list of items using various conditions. Your task is to implement the `FilterService` class with the following methods:
1. `filter_by_even`: This method... | magicoder |
You are tasked with creating a Python function that generates thumbnail URLs for files based on their file paths. The function should take in the file path, the root directory where the thumbnails are stored, and the root URL for accessing the thumbnails. The function should then construct the thumbnail URL based on th... | magicoder |
You are tasked with creating a Python function that utilizes the NumPy library to perform a specific mathematical operation. The function should take in two NumPy arrays, C and V, and a NumPy array of integers, nums. The function should calculate the result based on the following formula:
result = (C * V) / nums
Wher... | magicoder |
You are tasked with creating a test automation framework for a mobile application using Appium and Serenity BDD. The provided code snippet is a part of the test automation framework and shows the initialization of the AndroidDriver for interacting with mobile elements. Additionally, it includes the usage of Serenity BD... | magicoder |
You are tasked with implementing a function to count the frequency of each word in a given text. A word is defined as a sequence of non-space characters. The function should take a string as input and return a map or dictionary where the keys are the unique words in the text and the values are the frequencies of each w... | magicoder |
You are working on a web application that uses environment variables to store configuration settings. The application uses the `os.environ` dictionary to access these environment variables. Additionally, it uses the `json` module to load JSON data from environment variables.
Given the provided code snippet, you need t... | magicoder |
You are tasked with implementing a graph visualization tool that can display a graph in a graphical user interface (GUI). The graph is represented using an adjacency list. Each node in the graph is represented by a unique integer, and the edges are represented as pairs of integers denoting the connected nodes. You need... | magicoder |
You are tasked with creating a Python class that processes a given line and returns the identifiers of the row and column. The class should have a method that takes a line as input and splits it using a specified separator. The method should then return the values corresponding to the row and column identifiers.
Creat... | magicoder |
You are tasked with creating a Python class that represents a leaderboard for a gaming application. The class should allow for the addition of player scores and provide functionality to retrieve the top N players based on their scores.
Create a Python class called `Leaderboard` with the following requirements:
- The c... | magicoder |
You are tasked with creating a Python function that interacts with the Windows API to retrieve information about the system's disk drives. The function should take no input arguments and return a dictionary containing details about each disk drive present in the system.
Your function should use the provided code snipp... | magicoder |
You are tasked with creating a Python class that manages user authentication information. The class should have a property called `user_auth_pass_date` which represents the date when the user's authentication password was last updated. The class should enforce the following rules:
1. The `user_auth_pass_date` property ... | magicoder |
You are working on an image processing application and need to implement a function to change the colors of an image based on a given number of clusters. The function `changeColors(img, n)` takes an input image `img` and an optional parameter `n` representing the number of color clusters to use. The function first call... | magicoder |
You are tasked with implementing a function to fetch a collection of summoner spells from a game API. The API provides a method `FetchSummonerSpells` that returns a `IReadOnlyCollection<SummonerSpell>`. Each `SummonerSpell` object contains information about a specific summoner spell used in the game.
Your task is to i... | magicoder |
You are working for an e-commerce company that needs to create a new datafeed for its products. The company's system uses a Python function to generate the datafeed in the form of a dictionary. The function takes two parameters: `name` (string) and `overwrites` (dictionary). The `overwrites` parameter contains a set of... | magicoder |
You are tasked with implementing a translation and caching system for a game input service. The provided code snippet is part of a class that manages the translation process and caching of translated game inputs. The `TranslateInBackgroundAndUpdateGameInput` method is responsible for translating game input tiles in the... | magicoder |
You are working on a particle identification (PID) algorithm for a high-energy physics experiment. The code snippet provided is a part of a function that calculates the number of standard deviations (nSigma) a particle's energy loss in the Inner Tracking System (ITS) and Time Projection Chamber (TPC) deviates from the ... | magicoder |
You are tasked with creating a Python function that parses the metadata from a setup configuration file and returns a dictionary containing the relevant information. The setup configuration file is in the format of a Python script and contains metadata for a Python package. The metadata includes the package name, versi... | magicoder |
You are tasked with implementing a Python function that performs a specific operation on a given input. The function should take a list of tuples as input and return a new list containing the sum of the elements in each tuple. However, if the input list contains any elements that are not tuples, the function should rai... | magicoder |
You are tasked with creating a Python function that processes a list of migration operations and executes them in a specific order. Each migration operation is represented as an instance of a class and may perform various tasks such as database schema modifications, data transformations, or other necessary updates.
Yo... | magicoder |
You are tasked with creating a function that processes configuration settings for a software-defined radio (SDR) application. The configuration settings are stored in a file and are accessed using the provided code snippet. Your task is to implement a function that extracts the server URL from the configuration setting... | magicoder |
You are tasked with creating a Bash script that manipulates file paths and extensions. Your script should define a function `init` that initializes several variables based on the file paths and extensions of the script itself and its caller. The script should then output the initialized variables.
The variables to be ... | magicoder |
You are given a list of points representing the coordinates of a 2D shape. Each point is represented as a tuple of two integers, where the first integer is the x-coordinate and the second integer is the y-coordinate. Your task is to implement a function that calculates the distance between consecutive points in the lis... | magicoder |
You are tasked with implementing a function to process a list of tokens used in a computer architecture. The function should add specific bit sequences to the end of the token list based on certain rules. The tokens are represented as strings of binary digits.
You need to implement a Python function `process_tokens(to... | magicoder |
You are tasked with implementing a simple messaging protocol in Java. The protocol consists of a single interface and a class that implements it. Your goal is to create the missing interface and implement the required functionality in the provided class.
Interface:
```java
public interface Protocol {
void sayHello... | magicoder |
You are tasked with implementing a message handling system for a mail server. The system involves a `MessageHandler` class that takes a list of mailers and is responsible for sending messages. Each mailer has a `send_message` method that takes a message object and sends it. Additionally, there are assertions in the cod... | magicoder |
You are tasked with implementing a hash function using the SHA-256 algorithm. The SHA-256 algorithm is a widely used cryptographic hash function that produces a 256-bit (32-byte) hash value. The algorithm operates on a message with a maximum length of 2^64-1 bits and produces a 256-bit hash value. The algorithm consist... | magicoder |
You are tasked with creating a Python program that simulates a simple command-line interface for managing a music library. The program should utilize the `argparse` module to handle command-line arguments and subcommands. Your task is to implement the functionality for adding, listing, and removing songs from the music... | magicoder |
You are tasked with implementing a Swift extension for a custom type that can convert instances of the type to a dictionary. The extension should provide a method to convert the custom type to a dictionary representation. You need to write the code for the extension method that accomplishes this task.
The custom type ... | magicoder |
You are tasked with implementing a more efficient decryption algorithm to crack a substitution cipher. The given code snippet demonstrates a brute-force approach to decrypting a cipher text using random substitution keys. Your goal is to devise a more optimized algorithm to decrypt the cipher text.
You are provided wi... | magicoder |
You are tasked with implementing a neural network for a regression problem using the Keras library in Python. The given code snippet shows the construction of a neural network model and its compilation using the stochastic gradient descent (SGD) optimizer with mean squared error (MSE) as the loss function. Additionally... | magicoder |
You are tasked with implementing a message class that can convert messages to and from a dictionary format. The message class has a payload, a UUID, and metadata. Your goal is to write a method to convert the message to a dictionary and another method to create a message from a dictionary. Additionally, you need to ens... | magicoder |
You are tasked with creating a Python class that simulates a progress bar with a spinner animation. The progress bar should be able to display progress in a graphical user interface (GUI) and include a spinner animation while the progress is being updated. Your task is to implement the `ProgressBarWithSpinner` class wi... | magicoder |
You are working on a database synchronization tool that checks for the existence of tables, performs data synchronization, and splits tables into multiple regions. Your task is to implement a function that checks whether a given table exists in a downstream database, splits the table into a specified number of regions,... | magicoder |
You are tasked with implementing a Python function that searches for a specific file in a given directory using a provided manifest. The function should return the name of the file if it is found in the manifest, or None if it is not found. The manifest is represented as a dictionary where the keys are file names and t... | magicoder |
You are tasked with creating a virtual reality (VR) application that involves adjusting the inter-pupillary distance (IPD) and eye position using hotkeys. The code snippet provided is a part of the VR application's script and includes the declaration of a variable for an ARRaytracer for the right eye, as well as the de... | magicoder |
You are tasked with implementing a custom PyTorch module for matching and shifting image features. The provided code snippet is a partial implementation of the `matchshifted` module, which takes two input tensors `left` and `right`, and a shift value, and produces a concatenated tensor of shifted left and right feature... | magicoder |
You are tasked with implementing a database upgrader for MySql databases using the provided code snippet as a reference. The `MySqlDatabase` method is used to create an upgrader for MySql databases, and it takes an `IConnectionManager` as a parameter. Your task is to create a class that implements the `IConnectionManag... | magicoder |
You are tasked with creating a custom class in PHP to manage data related to a library's book collection. The class should include specific properties and methods to handle the book data effectively.
Create a PHP class called `Book` with the following requirements:
- The class should have a protected property called `... | magicoder |
You are tasked with implementing a base entity class for a quiz application. The base entity class should include properties and methods that are common to all entities in the application. Your task is to create a C# class that fulfills the requirements of a base entity and ensures that all entities in the application ... | magicoder |
You are tasked with creating a Python script that downloads manifest and metadata for a given bundle from the Data Storage System (DSS) and stores them as separate JSON files. The script should accept the bundle UUID as a command-line argument and save the manifest as `$UUID.manifest.json` and the metadata as `$UUID.me... | magicoder |
You are tasked with implementing a simplified version of the `mkcd` shell function in Python. The `mkcd` function is used to create a new directory and then change the current working directory to the newly created directory in a single command. The function takes a variable number of arguments, where each argument rep... | magicoder |
You are tasked with implementing a custom tag handler for a configuration management system. The tag handler, called `GlobHandler`, is responsible for processing glob patterns within configuration files and expanding them into a list of file paths. The `GlobHandler` should support basic glob patterns such as `*`, `?`, ... | magicoder |
You are tasked with creating a Python function that processes an image using the OpenCV library and a pre-trained model from the Detectron2 library. The function should take an image file path as input and return the processed image.
Your task is to complete the Python function `process_image` which takes a string `im... | magicoder |
You are tasked with implementing a class that represents a JSON object for a web page. The class, `PageObjectImpl`, should have methods to retrieve the name of the page and the values of specific variables within the page. Your task is to create the `PageObjectImpl` class with the required methods and ensure that it pa... | magicoder |
You are tasked with creating a Python program to display an image on a canvas and allow users to input coordinates to mark specific points on the image. The program should use the Tkinter library for the GUI and the PIL library for image processing.
Your task is to implement a Python class that achieves the following:... | magicoder |
You are tasked with implementing a Python class that combines the functionality of a themed label frame with features of a text-based Tkinter widget. Your goal is to create a class that inherits from `ttk.LabelFrame`, `BaseTextTkinterWidget`, and `BaseFrameMixin`. The `BaseTextTkinterWidget` and `BaseFrameMixin` are as... | magicoder |
You are working on a financial trading platform that handles signal alerts and trade orders. The platform uses a Python ORM (Object-Relational Mapping) library to interact with a PostgreSQL database. The provided code snippet is a simplified representation of the ORM models for signal alerts and trade orders.
Your tas... | magicoder |
You are working on a Django web application that manages system-wide roles for different user types. The application uses a model called `SystemWideRole` to define these roles. The code snippet provided is a part of a Django migration file that handles the creation and deletion of system-wide roles.
Your task is to im... | magicoder |
You are tasked with implementing a class that simulates a dependency injector for a scene in a video game. The `injectScene` method of the `Injector` class takes two parameters: `scene_id` (an integer) and `scene` (a string representing the scene name). The method should raise a `TypeError` if the `scene_id` is not a s... | magicoder |
You are tasked with creating a Python script to parse and extract information from a configuration file used in a CMS (Compact Muon Solenoid) experiment at CERN. The configuration file contains settings for various components of the experiment, including the XMLGeometryWriter module. Your goal is to extract the XMLFile... | magicoder |
You are tasked with implementing a Python function that performs element-wise addition of two input tensors, which may be None or empty. The function should handle these cases appropriately and return the result as a new tensor.
You are given the following code snippet as a starting point:
```python
def add_ignore_emp... | magicoder |
You are working on a cloud management platform that allows users to interact with virtual machines (VMs) and pods. Your task is to create a function that checks the state of a VM and ensures that it can be stopped only if it is running in an enabled pod.
You are given the following information:
- The `VirtualMachine`... | magicoder |
You are tasked with implementing a Python function to calculate the convolution integrand for either flat or Gaussian beams. The function should take two parameters: `r2` (a numerical value) and `mcmlConv` (an instance of a custom class `mcmlConv`). The `mcmlConv` object contains attributes and methods related to a Mon... | magicoder |
You are tasked with creating a program to compute the average temperature of various regions under different treatments and scenarios. The temperature data is stored in a list of dataframes, `temp_veg_dfs`, and the spatial information is provided in a spatial prefix map, `luts.spatial_prefix_map`. The treatments and sc... | magicoder |
You are tasked with creating a Rust function to parse and extract information from a financial message encoded in the FIX (Financial Information eXchange) protocol. The given code snippet is a part of a Rust struct definition that represents a field in a FIX message. The field is related to the delivery stream cycle de... | magicoder |
You are working on a project that involves downloading pre-trained models for image recognition using Convolutional Neural Networks (CNNs). Your task is to create a Python script that automates the process of downloading these pre-trained models from the given URLs. You need to handle any potential errors that may occu... | magicoder |
You are tasked with creating a custom permission class for a Django REST framework application. The custom permission, named `IsAdminOrReadOnly`, should only allow administrators to edit an object while allowing all other users to view it. Your task is to complete the implementation of the `IsAdminOrReadOnly` class by ... | magicoder |
You are tasked with implementing a class to manage information about courses in a university. The class should have the following attributes:
- `id` (integer): The unique identifier for the course.
- `name` (string): The name of the course.
- `credits` (integer): The number of credits the course is worth.
Additionall... | magicoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.