instruction_seed stringlengths 29 40.5k | source stringclasses 6
values |
|---|---|
You are tasked with creating a custom error handling system for a new programming language. The system should allow developers to define foreign links to external error types and provide a mechanism for handling these errors within the language.
Your task is to implement a data structure and associated methods to mana... | magicoder |
You are tasked with creating a program that parses and extracts relevant information from a copyright header in a source code file. The copyright header follows a specific format and contains details such as the author's name, last modification date, modified by, and copyright notice. Your program should be able to ext... | magicoder |
You are tasked with implementing a function that retrieves configuration data from a server and processes it to update a local access object. The provided code snippet is a part of a TypeScript class that handles authentication and configuration retrieval. Your task is to complete the implementation of the `GetConfig` ... | magicoder |
You are given a class `Tree` that represents a binary tree. The `Tree` class has a method `find_sum_idx(idx)` which takes an integer `idx` as input and returns the index of the node in the tree that contains the sum of values from the root to the `idx`-th node. The tree is represented as an array where the root is at i... | magicoder |
You are tasked with implementing a class hierarchy to represent mathematical operations on complex numbers. The complex number is represented as `C(x)` where `x` is a real number, and the derivative of a complex number is represented as `D(c)` where `c` is a complex number. The following operations need to be supported... | magicoder |
You are given a code snippet that seems to contain some encrypted messages. Your task is to decipher the messages and extract the meaningful information from the given data.
The code snippet provided contains a series of characters and some placeholder text denoted by `<KEY>`. The encrypted messages are interspersed w... | magicoder |
You are tasked with implementing a custom data structure called `UnionDict` that behaves like a dictionary but also supports attribute-style access for nested dictionaries. The `UnionDict` should allow you to access nested dictionaries using dot notation, similar to accessing attributes of an object in object-oriented ... | magicoder |
You are tasked with implementing a Point class in JavaScript that represents a point on a 2D plane. The class should have the following properties and methods:
Properties:
- x: A number representing the x-coordinate of the point.
- y: A number representing the y-coordinate of the point.
- key: A string representing a ... | magicoder |
You are working on a RESTful API for managing a database of characters in a role-playing game. The provided code snippet is a part of a PHP-based API endpoint for deleting a character. The `index_delete` method is responsible for handling the deletion request. It first checks the validity of the `id` parameter and then... | magicoder |
You are given a list of integers representing the scores of a game. Your task is to write a function that calculates the highest possible score by choosing a subset of the scores such that no two chosen scores are adjacent in the original list.
Write a function `maxNonAdjacentSum` that takes in a list of integers and ... | magicoder |
You are working on a natural language processing (NLP) project that involves processing question-answer pairs. In this project, you have two arrays: `ques_ans_feat` and `ques_ans_att`. The `ques_ans_feat` array contains word embeddings for question-answer pairs, and the `ques_ans_att` array contains attention weights f... | magicoder |
You are tasked with creating a Python function that processes and validates data from a Halo Catalog. The Halo Catalog is a data structure used in astrophysics to store information about dark matter halos in a simulation. The function should perform several tasks, including querying IDs and loading group data.
Your t... | magicoder |
You are tasked with implementing a function that calculates the total distance traveled by a sprite in a 2D game. The sprite's movement is determined by the product of its current position, a movement factor, and the number of coins collected. The movement factor is multiplied by the number of coins collected and then ... | magicoder |
You are tasked with implementing a simple touch event handling system for a mobile application. The system should allow for custom touch event handling logic to be incorporated into the existing touch event flow.
You are provided with a Swift code snippet that represents a part of the touch event handling logic in a c... | magicoder |
You are tasked with implementing a function that processes a list of file paths and extracts the unique file extensions present in the list. The function should return a set of unique file extensions found in the input list.
You are given the following code snippet as a starting point:
```cpp
#include <iostream>
#inc... | magicoder |
You are given a list of integers representing the results of a series of submissions in a programming contest. Each integer represents the result of a submission, where 1 indicates a correct answer and 0 indicates a wrong answer. Your task is to find the index of the first incorrect submission (0) in the list. If there... | magicoder |
You are tasked with implementing a simple monitoring system for a set of objects in a Python program. The system should track the number of times certain methods are called on these objects and provide assertions to verify their behavior.
You are given the following code snippet as a starting point:
```python
assert ... | magicoder |
You are tasked with implementing a class that interacts with Amazon DynamoDB using the provided `AmazonDynamoDbService` module. Your goal is to create a class called `DynamoDBManager` that encapsulates the functionality to perform basic operations such as adding an item, getting an item, updating an item, and deleting ... | magicoder |
You are working on a web application that needs to make HTTP requests to various endpoints. You have a class `Curl` that provides a simple interface for making HTTP requests using cURL. The code snippet provided is part of a method in a class responsible for handling these HTTP requests.
The `$url` variable is a strin... | magicoder |
You are tasked with creating a Python class that interacts with a database to perform basic CRUD (Create, Read, Update, Delete) operations on a specific table. The database connection and table schema are provided through the `common` module. Your task is to implement the methods of the `DatabaseHandler` class to achie... | magicoder |
You are tasked with creating a Python function that simulates a simple game of rock-paper-scissors. The function should take a player's choice as input and randomly generate the computer's choice. It should then determine the winner based on the classic rules of the game.
Your task is to implement the `rock_paper_scis... | magicoder |
You are tasked with creating a Python class that manages configuration settings for a bot application. The class should read environment variables for API credentials and other configuration parameters. Your task is to complete the implementation of the `Config` class by adding a method that validates the configuration... | magicoder |
You are tasked with implementing a function that retrieves a table from a database based on a given table name. The function should raise an exception if the provided table name does not match the expected table name.
Write a Python function `retrieve_table` that takes two parameters:
1. `table`: A table object repres... | magicoder |
You are tasked with implementing a class to calculate performance metrics for a binary classification model. The class should have a method `add_value` that takes in two parameters: `true` and `predicted`, representing the true label and the predicted label for a single instance, respectively. The method should update ... | magicoder |
You are tasked with implementing a set of subroutines for a text processing system. The system will handle various operations on strings, such as reversing, capitalizing, and counting characters. Your task is to implement the following subroutines:
1. `reverse_string`: This subroutine takes a string as input and retur... | magicoder |
You are tasked with implementing a text wrapping algorithm to format a given string into a paragraph with a specified maximum line width. The algorithm should wrap the text at word boundaries, ensuring that no word is split across two lines. If a word is longer than the maximum line width, it should be hyphenated and s... | magicoder |
You are tasked with creating a program that simulates a simple hosting service for rendezvous servers. The program should read environment variables to obtain the port number and then start the hosting service using the obtained port number and a rendezvous server.
Your task is to implement the `get_rendezvous_server`... | magicoder |
You are tasked with creating a Django web application for an online book platform. The application should have a view to display a list of chapters for a specific book. The URL pattern for this view is already defined in the `urls.py` file as follows:
```python
path('chapters/', views.ChapterListView.as_view(), name='... | magicoder |
You are tasked with creating a function that retrieves the paths of log files for analysis. The function should take a directory path as input and return a list of paths to all log files within that directory and its subdirectories. You are provided with a code snippet that sets up a test suite for this function.
Writ... | magicoder |
You are tasked with implementing a simple graphics rendering system using the OpenGL library. The code snippet provided initializes the OpenGL context, sets the application to exit when the escape key is pressed, and builds the rendering window. Your task is to extend this code to render a simple 2D shape, such as a tr... | magicoder |
You are tasked with implementing a simple client-server communication system using Python's socket library. The client and server will exchange messages using TCP/IP sockets. Your goal is to create a client program that connects to a server and sends a message.
Your task is to complete the `client.py` program by imple... | magicoder |
You are tasked with creating a Python function that processes a document upload form and returns a dictionary containing information about the uploaded document. The form saves the document, and the function needs to extract relevant details and construct a dictionary with the following keys: 'is_valid', 'name', and 'u... | magicoder |
You are tasked with creating a script to automate the cleanup of specific directories in a game server setup. The script should remove certain files and directories within the game server's data directory.
Your task is to write a Bash script that performs the following actions:
1. Execute a script named `down.sh` loca... | magicoder |
You are tasked with simulating a USB bulk transfer process in Python. You are given a code snippet that uses the `ctypes` library to interact with a USB device. Your goal is to implement a function that simulates the bulk transfer process and handles potential errors.
You need to create a Python function `simulate_bul... | magicoder |
You are tasked with implementing a custom wrapper class for a binary tree node. The wrapper class should provide additional functionality to the standard binary tree node, such as tracking the number of times a node is accessed or modified. Additionally, the wrapper class should be able to work with a party class to pe... | magicoder |
You are tasked with implementing a simple class in C# that represents a web request. The class should have a property `request` that returns the request data. Your task is to complete the implementation of the `WebRequest` class by adding the necessary code to the provided snippet.
```csharp
using System;
public clas... | magicoder |
You are working on a computer vision project and need to implement a custom normalization layer for a neural network model. The provided code snippet is a part of the normalization layer implementation using PyTorch. Your task is to understand the code and design a problem related to the concepts of normalization layer... | magicoder |
You are tasked with implementing a cooldown system for a game character's abilities. The character has three abilities: normal, toxic, and default. Each ability has its own cooldown period. When an ability is used, it triggers its respective cooldown period. During the cooldown period, the ability cannot be used again.... | magicoder |
You are tasked with implementing a program to calculate the areas of multiple triangles and print the results. The program should include functions to calculate the areas of the triangles and to print a given matrix.
You are given the following code snippet as a starting point:
```cpp
#define LINHAS 2
#define COLUNAS... | magicoder |
You are tasked with creating a program that processes images by resizing them using a specific resampling method. The program should take an input image file and resize it to the specified dimensions using the BILINEAR resampling method. Your task is to implement a function that accomplishes this image processing task.... | magicoder |
You are tasked with creating a module loader for a JavaScript application. The module loader should be able to import and export modules using the ES6 module syntax. Your task is to implement a function that can parse and load the modules based on the provided code snippet.
You are given a code snippet that demonstrat... | magicoder |
You are tasked with implementing a Java class that represents a simple bank account. The class should have the following functionalities:
1. A constructor that initializes the account balance to zero.
2. A method to deposit a specified amount into the account.
3. A method to withdraw a specified amount from the accoun... | magicoder |
You are given a list of floating-point numbers. Your task is to write a function to count the number of real numbers in the list that are not whole numbers (i.e., they have a non-zero fractional part).
Write a function called `count_non_whole_numbers` that takes a list of floating-point numbers as input and returns th... | magicoder |
You are tasked with implementing a custom view in Swift called `ReadenView`. This view should display a given text in a visually appealing manner. The `ReadenView` should have the following features:
- Ability to set the text content to be displayed.
- Customizable text color and font.
- Adjustable line spacing.
- Supp... | magicoder |
You are tasked with creating a Python class that manages test cases for a bioinformatics tool. The class should handle setting up test cases and managing temporary directories for the test data. Your task is to implement the `TestCase` class with the following requirements:
1. The `TestCase` class should inherit from ... | magicoder |
You are tasked with implementing a Python class that represents a segment of values. The class should have the following functionalities:
- Initialize the segment with a segment type (either AS_SEQUENCE or AS_SET) and a list of values.
- If the segment type is not valid (i.e., not AS_SEQUENCE or AS_SET), it should rais... | magicoder |
You are tasked with implementing a dependency resolution algorithm for a build system. The build system has a set of rules, each with its own dependencies. Your goal is to write a function that determines whether a given rule can be fulfilled based on its dependencies and the current state of the build system.
You are... | magicoder |
You are working on a virtual reality game where players navigate through a series of interconnected rooms and hallways. The game is represented as a graph, with rooms as nodes and hallways as edges. Each room is identified by a unique integer from 1 to 4, and each hallway is identified by a unique integer from 0 to 6. ... | magicoder |
You are tasked with creating a TypeScript class that implements a specific interface and handles the creation of quote items for a quote management system. The system relies on a repository to store and retrieve quote items. Your task is to create a class that implements the `CreateQuoteItemsCommand` interface and inte... | magicoder |
You are given a list of commands and an initial energy level. Your task is to simulate a journey through a rabbit hole by following the given commands and updating the energy level accordingly. The journey ends when a specific condition is met.
You are provided with a list of commands in the format "command|value", wh... | magicoder |
You are tasked with creating a Python program to automate the configuration of network interfaces on a Linux system. Your program should read a list of commands from a file and execute them in sequence using the `subprocess` module. The commands will configure the network interface with a specific IP address, set a def... | magicoder |
You are tasked with creating a file monitoring application in C#. The application should allow users to select a directory and start monitoring it for any file changes. When a file is created, modified, or deleted within the monitored directory, the application should display a message indicating the type of change and... | magicoder |
You are tasked with implementing a Python class that processes PprzMessages and invokes a callback function. The class, named `PprzMessageProcessor`, has the following requirements:
1. The class should have an `__init__` method that initializes the message class and callback function.
2. It should have a method named ... | magicoder |
You are tasked with implementing a context manager for reading and writing data to an HDF5 file using the `h5py` library in Python. The context manager should handle the opening and closing of the HDF5 file and provide a convenient way to interact with the file's contents.
Your task is to complete the implementation o... | magicoder |
You are working on a Python script that interacts with SharePoint using the SharePoint REST API. Your task is to implement a class method for creating a new SharePoint Team site and another method for deleting an existing site. The provided code snippet is part of the existing class, and you need to complete the implem... | magicoder |
You are tasked with creating a program that analyzes the commit history of a Git repository to identify the most active contributor for a specific file. Your program should take the repository path and the file name as command-line arguments and then output the name of the contributor who has made the most commits to t... | magicoder |
You are tasked with implementing a file manipulation class in Python. The class should have an `__init__` method that takes a source file as input and opens it for reading. Additionally, the class should have a `replace` method that takes a dictionary as input and replaces all occurrences of keys in the source file wit... | magicoder |
You are tasked with implementing a function to calculate the rotation matrix between two given matrices and then determining the indices of non-zero elements in the resulting rotation matrix.
You are given the following code snippet as a starting point:
```python
R = utils.rotation_matrix(A_prime, A)
# Check order.
... | magicoder |
You are tasked with implementing a function that calculates the height of a binary tree. The binary tree is represented using a standard node structure with left and right pointers. The height of a binary tree is the number of edges on the longest path from the root node to a leaf node.
You are given the following nod... | magicoder |
You are tasked with implementing a Java class that interacts with a Java Message Service (JMS) API to send and receive messages from a queue. The JMS API provides a set of interfaces and classes for producing, consuming, and processing messages in a loosely coupled, reliable, and asynchronous manner.
Your task is to c... | magicoder |
You are tasked with implementing a web scraping program to extract information from a series of web pages. The provided code snippet is a part of the program that handles the extraction of content from a novel website. The snippet sets the last chapter link, next chapter link, and book name for the extracted content, a... | magicoder |
You are given a text file containing a software license agreement. Your task is to write a Python program to count the occurrences of each unique word in the file, ignoring case and punctuation. The program should then display the top N most frequently occurring words along with their counts.
For example, given the fo... | magicoder |
You are tasked with creating a Python program that interacts with a database using the SQLAlchemy library. Your program should reflect the database schema, establish a connection to the database, and perform a specific query.
Your database contains a table named "employees" with the following columns:
- id (integer, p... | magicoder |
You are tasked with creating a program that simulates a simple voting system for a small election. The program should allow users to vote for a candidate of their choice and then display the results of the election. To achieve this, you need to implement a class called `Election` with the following specifications:
Cla... | magicoder |
You are tasked with implementing a simple data visualization application using the Rust programming language. The application should render a chart using the `tui` (Text User Interface) library, which provides a set of widgets for creating terminal-based user interfaces.
Your task is to complete the implementation of ... | magicoder |
You are given a text file containing a software license agreement. Your task is to write a program that reads the file and extracts the warranty information from the license agreement. The warranty information is located between the lines containing "WITHOUT WARRANTY OF ANY KIND" and "EXPRESS OR IMPLIED". You need to e... | magicoder |
You are tasked with creating a Python function that processes permissions for form handler views. The function should take a list of permissions and return a filtered list containing only the permissions related to form data entries.
The permissions are represented as strings and follow the format 'app_label.permissio... | magicoder |
You are tasked with implementing a function that constructs a filename from a string template and a mapping of values. The function should extract values from the file name or path and use them to safely format a new filename. The function should also handle default mappings if provided.
You are given the following co... | magicoder |
You are tasked with implementing a Rust function to retrieve data from a non-volatile random access memory (NVRAM) area based on a given index. The NVRAM area is accessed through a provided context and the index of the data to be retrieved. The context is obtained using a utility function `open_context_from_env()` from... | magicoder |
You are working on a healthcare management system and need to implement a method to handle the result of a medical appointment booking. The system uses a custom `Result` class from the `com.xiaowangzi.yygh.common.result` package to encapsulate the outcome of the booking process. The `Result` class has the following str... | magicoder |
You are tasked with implementing a class in TypeScript to manage a collection of unique items. The class should have the following functionalities:
1. Add a new item to the collection.
2. Remove an item from the collection.
3. Check if a specific item is present in the collection.
4. Get the total count of items in the... | magicoder |
You are tasked with implementing a Python class that simulates a simple animation system. The class, named `Animation`, has an internal method `_anim_update` that is responsible for updating the animation state. The class also has a method `update` that is used to trigger the animation update. The `update` method can t... | magicoder |
You are tasked with implementing a function that processes a message and redirects it to a specified destination. The function should handle two cases: one where the message is successfully sent and another where it is not. The function should return a redirect response with a success or error message based on the outc... | magicoder |
You are tasked with implementing a Python class that simulates a proxy object. The class should have three methods: `is_proxy`, `is_chaperone`, and `is_impersonator`. The `is_proxy` method should return `True` if the object is acting as a proxy, and `False` otherwise. The `is_chaperone` and `is_impersonator` methods sh... | magicoder |
You are tasked with implementing a Python class for managing messages in a healthcare system using the FHIR (Fast Healthcare Interoperability Resources) standard. The class should have attributes for message recipient, sender, sent timestamp, and status. Your task is to complete the implementation of the `FHIRMessage` ... | magicoder |
You are tasked with implementing a simple class in C# to manage the state of various UI elements in a macOS application. The class should have properties representing different UI elements, and it should provide methods to manipulate their states.
Create a C# class named `UIManager` with the following properties:
- `s... | magicoder |
You are tasked with creating a Python class to manage time-related data for a car tracking system. The class should include methods to capture and display the time spent in the car, as well as the timestamp when the car was captured. Your task is to implement the `CarTimeTracker` class with the following requirements:
... | magicoder |
You are tasked with implementing a location tracking feature in an Android application. The application has a class called `LocationSource` that provides methods for managing location updates. The `onResume` method of the activity needs to call the `onResume` method of the `LocationSource` to ensure that location updat... | magicoder |
You are tasked with implementing a Python decorator that performs parameter validation and default value assignment for a given function. The decorator should take a dictionary of parameter annotations and default values, and use them to validate and assign values to the function's parameters. If a parameter is missing... | magicoder |
You are tasked with implementing a simple WebSocket server in C#. The server should be able to handle incoming HTTP connections with the "Upgrade: websocket" header data and establish WebSocket connections with clients.
Your task is to complete the implementation of the `UseWebSockets` extension method for the `IHorse... | magicoder |
You are given a code snippet that manipulates a StringBuilder object. Your task is to implement a function that replicates the behavior of the code snippet.
The code snippet is part of a larger program that processes a StringBuilder object named `sbStr1`. The program iterates through the characters of `sbStr1` and pe... | magicoder |
You are tasked with creating a Python function that filters and processes a list of enrollments based on various criteria. The function should take in the following parameters:
- `external_key` (string): The external key to filter enrollments by.
- `enrollment_type` (string): The type of enrollment to filter by.
- `sta... | magicoder |
You are tasked with creating a Python function that simulates parallel execution of a long-running task using multiprocessing. Your function should take a list of input values and a function to be executed in parallel. The function should return a list of results corresponding to the input values after the parallel exe... | magicoder |
You are given a list of integers representing the scores of a game at different stages. Each stage has a unique score, and the list is guaranteed to be non-empty. Your task is to write a function that returns the highest score achieved after a specific stage. The specific stage is represented by the index in the list, ... | magicoder |
You are tasked with creating a script to automate the stopping of slave processes on a set of hosts. The script should iterate through a list of hosts and stop the slave process on each host, with the exception of a specific host named 'host-0'.
You are given a code snippet as a starting point:
```bash
for h in $HOST... | magicoder |
You are tasked with creating a program that processes a list of attribute labels and their corresponding values. The attribute labels are represented as keys in an associative array, and the values are the corresponding descriptions. Your task is to implement a function that takes this associative array as input and re... | magicoder |
You are tasked with implementing a simple text editor that supports a subset of keyboard commands. The editor should handle specific control characters to perform various operations. Your task is to write a function that processes the input characters and performs the corresponding actions based on the control characte... | magicoder |
You are tasked with implementing a Python class that manages a collection of words and their associated tags. The class should provide methods for adding words with tags, retrieving all words with a specific tag, and removing words from the collection.
You are given a partial implementation of the `WordTagManager` cla... | magicoder |
You are tasked with implementing a circular dependency detection algorithm for a system that manages configuration sets. A configuration set is a collection of configuration parameters used by a software system. The goal is to identify circular dependencies within the configuration sets to prevent potential runtime iss... | magicoder |
You are tasked with implementing a parser for a simple expression language. The language consists of binary operations, such as addition, subtraction, multiplication, and division, as well as parentheses for grouping. The expressions are represented using a custom abstract syntax tree (AST) format.
The AST nodes have ... | magicoder |
You are tasked with creating a GUI application using PyQt5 in Python. The application should consist of a main window with a vertical splitter containing two widgets: a widget for buttons (wbuts) and a widget for horizontal splitter (hspl). Additionally, the main window should have a box layout (mbox) that incorporates... | magicoder |
You are tasked with implementing a feature for an enhanced table component in a web application. The table has a toolbar with the ability to select rows using checkboxes. The table's state is managed by the following interfaces:
```typescript
interface HeadCell {
id: string;
label: string;
}
interface Enhance... | magicoder |
You are tasked with creating a Rust function that generates a Tezos encoding for a given data type. Tezos is a blockchain platform that utilizes a specific encoding scheme for data serialization. Your task is to implement a function that takes a data type and its size, and then generates the corresponding Tezos encodin... | magicoder |
You are tasked with implementing a function to determine the winner of a game represented by a 3x3 boolean array. The array represents a tic-tac-toe board, where `True` indicates a player's move and `False` indicates an empty space. The function `isWin(board)` should return `True` if there is a winner and `False` if th... | magicoder |
You are tasked with creating a Python program that processes and sends email messages using the `EmailMessage` class from the `email.message` module. Your program should read a list of recipient email addresses from a file, construct an email message with a specified subject and body, and then send the email to each re... | magicoder |
You are tasked with implementing a simple game strategy manager in Python. The game has different strategies that can be applied, and the manager should allow setting and executing these strategies. The `set_strategy` method is used to set the current strategy for the game manager. The `Strategy` class is already defin... | magicoder |
You are tasked with implementing a function to process and manipulate data from a file. The file contains pairs of values separated by whitespace, with each pair representing a specific data point. However, some lines in the file may not conform to this pattern and should be skipped. Additionally, a function `canon(var... | magicoder |
You are tasked with creating a file upload validation system for a web application. The system should restrict the file types to only allow JPG, PNG, and JPEG formats. Additionally, the uploaded file should be renamed using the SKU (stock keeping unit) provided in the form. The system should also check if the total num... | magicoder |
You are given a Python code snippet that processes a buffer containing binary data. The code snippet is as follows:
```python
s = e + 1
e = _buffer.find(b"\n", s)
```
The variables `s` and `e` are used to track the start and end positions of a line within the buffer. The variable `_buffer` contains binary data, and t... | magicoder |
You are tasked with creating a Python script that reads a YAML configuration file and sets up logging based on the configuration. The script should accept a command-line argument specifying the path to the configuration file. The configuration file will contain settings for the logging module, including the log level a... | magicoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.