instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with creating a Python class that handles connections to a remote server. Your class should be able to log any connection errors that occur using a logger object. The provided code snippet is a part of the error handling mechanism in the class. Your task is to complete the implementation of the class by ...
magicoder
You are tasked with creating a program that generates a simple HTML template for a webpage. Your program should take in the title of the webpage and a list of CSS file names as input. It should then generate the HTML code for the webpage, including the specified title and linking the CSS files. Your program should out...
magicoder
You are working on a machine learning framework and need to implement a function for materialization trace information. The materialization trace information is used to track the operations and inputs involved in the lazy evaluation of tensors. You are given a code snippet that includes a part of the implementation for...
magicoder
You are tasked with implementing a function that unserializes pairs of data from a given input string. The input string contains a series of key-value pairs in a specific format, and your function should parse and return these pairs as a dictionary. You are given the following code snippet as a starting point for your...
magicoder
You are tasked with creating a multilingual support system for a web application. Your goal is to implement a function that takes a language code and a key, and returns the corresponding translation for that key in the specified language. The translations will be stored in a nested dictionary structure, where the outer...
magicoder
You are tasked with implementing a program that simulates a simple game of rock-paper-scissors. The program should prompt the user to input their choice (rock, paper, or scissors), generate a random choice for the computer, compare the choices, and declare the winner. The program should then ask the user if they want t...
magicoder
You are tasked with creating a function that handles the deletion of a user and their associated profile image in a web application. The function should first delete the user's profile image file from the server, and then proceed to delete the user from the database. Below is a simplified representation of the function...
magicoder
You are tasked with optimizing the performance of a web server by configuring the number of worker processes based on the available CPU cores. The server uses the 'gevent' worker class for handling concurrent requests. The current configuration sets the number of workers to be twice the number of CPU cores plus one. Yo...
magicoder
You are tasked with creating a web application that displays a breadcrumb navigation bar based on the given HTML code snippet. The breadcrumb navigation bar should dynamically display the path to the current page based on the URL and the structure of the website. Your task is to implement a function or method that tak...
magicoder
You are tasked with creating a function that parses a given HTML code and extracts all the external CSS file URLs used in the `<link>` tags. The function should return a list of these URLs. Write a function `extractCSSUrls(html)` that takes a string `html` representing the HTML code as input and returns a list of exte...
magicoder
You are tasked with implementing a Python class that manages a simple database system. The class, `Consoler`, is a subclass of `doing.Doer` and is responsible for handling command console operations. The class has an `__init__` method that takes in optional parameters `db` and `console`, along with any additional keywo...
magicoder
You are tasked with creating a custom serializer for a Django model in a web application. The model, `BoardProfile`, represents user profiles on a discussion board. The serializer needs to include two read-only fields, `rendered_username` and `rendered_rank`, which are not directly present in the model. Your task is to...
magicoder
You are given a Python function that takes in a list `x`, an integer `percentile`, and a string `s_len`. The function is intended to calculate the percentile value of the given list `x` based on the specified percentile. However, the code snippet provided is incomplete and lacks the necessary logic to achieve this. You...
magicoder
You are tasked with implementing a virtual machine (VM) that can execute a set of instructions. The VM is responsible for interpreting and executing the instructions provided to it. The instructions are represented as a sequence of opcodes and operands. Each opcode represents a specific operation, and the operands prov...
magicoder
You are given a code snippet from a program that manipulates a binary tree data structure. The code appears to be part of a function that processes a binary tree and updates a table based on certain conditions. Your task is to understand the code and implement a specific functionality related to binary trees. The code...
magicoder
You are tasked with implementing a feature for a sample metadata panel in a web application. The panel allows users to edit metadata associated with a sample. The metadata is represented as key-value pairs, and the panel has an edit mode that enables users to modify the metadata. The `SampleMetadataPanel` component is...
magicoder
You are working on a quantum chemistry project and need to implement a function to calculate the correlation energy and total energy using reduced rank coupled cluster singles and doubles with perturbative triples correction (RCCSD(T)) method. The RCCSD(T) method is a widely used quantum chemical method for accurate ca...
magicoder
You are tasked with creating a script to automate the process of updating a Git branch. Your script should take the name of the Git branch as input and then perform the following actions: 1. Print a message indicating the branch being updated. 2. Print the current working directory. 3. Switch to the specified Git branc...
magicoder
You are working on a Python web application using the aiohttp framework. Your task is to extend the functionality of the `Application` class by implementing three methods: `add_routes`, `add_view`, and `add_subapp`. The `add_routes` method takes a list of routes and adds them to the application. Each route is represen...
magicoder
You are tasked with creating a Python function that processes an audio file and returns a specific result based on the audio data. The function will take in the path to the audio file as input and should utilize the `soundfile` library to read the audio data and perform the necessary processing. Create a function `pro...
magicoder
You are given a code snippet that includes a macro `FR(i, n)` which is used to iterate `i` from 0 to `n-1`. Your task is to implement a similar macro `FRL(i, l, r)` that iterates `i` from `l` to `r` (inclusive). You should write a macro that can be used in a C++ program to achieve this functionality. Your task is to d...
magicoder
You are tasked with creating a program to manage and optimize the settings for a robotic hand. The robotic hand is represented by the object `i01.rightHand`, and it has individual components for the thumb, index finger, middle finger, ring finger, and pinky. Each component has default settings for its range of motion, ...
magicoder
You are tasked with creating a form validation function for a user registration form in a web application. The form contains fields for sex, date of birth (dob), nationality, and assigned date. The form uses the Angular framework, and the validation rules are defined using the Validators module. The form fields are de...
magicoder
You are tasked with creating a Python class that manages statistics for a game. The class should be initialized with an `ai_settings` object and should have a method to reset the game statistics. The `ai_settings` object contains various settings for the game. Your task is to complete the implementation of the class by...
magicoder
You are tasked with implementing a Python function that calculates the floor value of a window within a given range. The floor value of a window is defined as the largest integer less than or equal to the midpoint of the window. The function should take two integer parameters, representing the upper and lower bounds of...
magicoder
You are working on a project to optimize communication costs for a network of cameras sending data to a cloud server. The code snippet provided is a part of a Python script that uses the `matplotlib` library to create a bar chart representing the communication costs for different scenarios. The x-axis represents the to...
magicoder
You are tasked with implementing a trait for a bitmap font in Rust. The trait, `ToBitmapFont`, has three methods: `bitmap_height`, `bitmap_width`, and `font_size`. Your goal is to create a struct that implements this trait and returns the appropriate values for each method. The `ToBitmapFont` trait is defined as follo...
magicoder
You are tasked with creating a custom admin interface for a scientific research paper management system. The system should allow administrators to register and manage different types of scientific papers. Each paper has specific attributes such as title, authors, publication date, and abstract. To achieve this, you nee...
magicoder
You are tasked with creating a Python function that processes seismic focal mechanism data using spherical harmonics. The function should take in a set of seismic focal mechanism solutions and classify them based on their mechanism type. The seismic focal mechanism solutions are represented in a hash format and need to...
magicoder
You are tasked with implementing a memory management system for a video game console emulator. The system involves managing program (PRG) and character (CHR) memory pages. The provided code snippet is a part of the memory management module and contains a method for selecting a CHR memory page. The `select_chr_page` me...
magicoder
You are tasked with designing a protocol-oriented system for presenting items in a list and their details. The system should include protocols for presenting the list of items and for presenting the details of a specific item. You are provided with a code snippet that defines two functions: `makeItemsPresentable` and ...
magicoder
You are tasked with implementing a class for managing embeddings in a natural language processing (NLP) system. The class, `EmbeddingsMachine`, is responsible for initializing and working with word embeddings derived from a given corpus representation, word2vec representation, and key-value store representation. The `...
magicoder
You are working on a project that involves training a neural network model for image recognition. You have a pre-trained model and a set of weights that you want to load into the model before fine-tuning it on your specific dataset. The code snippet provided is a common operation in deep learning frameworks, where `mod...
magicoder
You are given a code snippet that processes elements in a 6x26 grid based on their coordinates and assigns them unique element numbers. The grid is divided into six rows and 26 columns, and the code snippet contains conditional statements to determine the element numbers based on the coordinates (x, y) within the grid....
magicoder
You are tasked with implementing a simple checkpoint system for a 3D game using Unity and C#. The provided code snippet is a part of the checkpoint system. The `OnTriggerEnter` method is called when another collider enters the trigger collider attached to the game object. The goal is to complete the implementation of t...
magicoder
You are working for a sports analytics company that wants to analyze the performance of basketball players based on their average score, handedness, and other attributes. The company has provided you with a dataset in the form of a pandas DataFrame named `df`. The DataFrame contains the following columns: 'name' (playe...
magicoder
You are given a code snippet that manipulates a color map for visualization. Your task is to implement a function that takes a color map and a position, and then modifies the color at that position to be white. You need to write a Python function `modify_color_map(cMap, position)` where: - `cMap` is a color map repres...
magicoder
You are tasked with creating a web page that includes a form for user authentication. The provided code snippet is a part of the HTML and PHP code for this web page. The snippet includes an input field for submitting the form and a link for user registration. Additionally, there is a conditional check for errors that m...
magicoder
You are given a vector `A` containing unsigned integers. You are also given an unsigned integer `average`. Your task is to implement a function that filters the elements of `A` based on whether they are greater than `average` or not. The filtered elements greater than `average` should be stored in a new vector `B`, and...
magicoder
You are given a set of functions representing a game board with free cells. The functions are as follows: 1. `int nthFreeCellIndex(int n)`: This function takes an integer `n` as input and returns the index of the `n`-th free cell on the game board. The first free cell has index 0, the second has index 1, and so on. 2...
magicoder
You are tasked with implementing a method to optimize API filters for a request object. The request object contains a map of dimensions to sets of API filters. The goal is to merge filters for dimensions that implement the `FilterOptimizable` interface. The `ApiFilters` class provides a method `merge` to merge filters ...
magicoder
You are tasked with implementing a function that processes a list of objects representing different types of shapes. Each object has a `type` attribute indicating the type of shape it represents. The function should filter the list to include only objects representing a specific type of shape and then perform a specifi...
magicoder
You are tasked with implementing a vector library for 2D vectors. Your goal is to extend the functionality of the existing `Vec2` struct by adding a method to compute the cross product of two vectors. You are provided with the following code snippet as a starting point: ```rust pub(crate) struct Vec2(f32, f32); impl ...
magicoder
You are tasked with creating a Python function that processes signals emitted by D-Bus and extracts specific information from the signals. D-Bus is a message bus system that allows communication between applications running on the same machine. The code snippet provided is a simplified example of a D-Bus signal handler...
magicoder
You are tasked with implementing a function that calculates the hash value of a given input string using the SHA-256 algorithm. The provided code snippet demonstrates the final steps of the hash calculation process, where the hash value is formatted and returned as a string. Your task is to complete the implementation ...
magicoder
You are tasked with creating a JavaScript function that makes an asynchronous GET request to a server and updates the content of a specified HTML element with the received data. Your function should take in the URL for the GET request and the ID of the HTML element to be updated. You should use the jQuery library for t...
magicoder
You are tasked with creating a function that simulates a simplified version of a server shutdown process. The function will take in a list of tasks and their corresponding completion times, and it should return the order in which the tasks should be executed to ensure a smooth shutdown process. You are given a struct ...
magicoder
You are tasked with implementing a validation system for the properties of an `ApiEntry` model in a Laravel application. The `ApiEntry` model represents an entry in an API and has the following properties: `user_id`, `wallet`, `trade`, and `token`. The properties `updated_at`, `trade`, and `wallet` are defined as strin...
magicoder
You are tasked with creating a script to automate the deployment process for a web application. The script should perform the following tasks: 1. Change the current directory to the directory containing the script. 2. Run the npm build command to build the web application. 3. Remove the existing "dist" directory. 4. C...
magicoder
You are tasked with creating a Python programming problem that involves testing a class using parameterized testing with pytest. The problem will require students to understand how to use pytest.mark.parametrize to test different scenarios for a given class. Write a Python class called `Rectangle` that has the followi...
magicoder
You are tasked with implementing a Python class that generates a grid with surrounding walls and assigns random colors to the cells. The grid is represented as a 2D array, and the walls are represented by the outermost cells of the grid. The colors for the non-wall cells are chosen from a predefined list. Your task is...
magicoder
You are tasked with creating a Python class that simulates a simple bank account. The class should have methods for depositing funds, withdrawing funds, and checking the balance. Additionally, the class should keep track of the total number of transactions (deposits and withdrawals) made on all instances of the bank ac...
magicoder
You are tasked with creating a Python function that can interpret and execute Larch scripts. Larch is a domain-specific language for scientific computing and data analysis. Your function should be able to take a Larch script as input and return the output of the script's execution. You are provided with a partial code...
magicoder
You are tasked with implementing a camera calibration algorithm for a computer vision project. The `load_camera_params()` function is responsible for loading the intrinsic and extrinsic parameters of the camera from a file. The parameters include the camera matrix, distortion coefficients, rotation, and translation vec...
magicoder
You are tasked with implementing a function that converts a given 2D NumPy array into a string and then back to the original array. The function should handle the conversion accurately and efficiently. You are provided with the following code snippet for inspiration: ```python import base64 import numpy as np def Ar...
magicoder
You are tasked with creating a service for an e-commerce platform that handles order confirmations. The service should include a function to generate a confirmation message based on the order details. The order details include the title, subject, and asset name. The confirmation message should be formatted as follows: ...
magicoder
You are tasked with implementing a simple HTTP server that serves a specific type of content. The server should be able to handle incoming requests and respond with the appropriate content type and data. Your task is to create a Python class that represents this server and implement the necessary methods to achieve the...
magicoder
You are tasked with implementing a web application that allows users to download files after they have been authenticated. The code snippet provided is a part of a Python Flask web application. The `@main.route('/download', methods=['POST'])` decorator specifies the route `/download` for handling POST requests, and the...
magicoder
You are tasked with implementing a static method within a PHP class that determines whether a given descriptor is handled by the class. The descriptor is a data structure that describes a data package. Your task is to complete the `handlesDescriptor` method in the `MyCustomDatapackage` class to check if the provided de...
magicoder
You are tasked with implementing a function to retrieve deployment information from a given system. The function should take in a deployment ID and return the details of the deployment if it exists, or an error message if it does not. You are provided with the following code snippet as a starting point: ```csharp { ...
magicoder
You are tasked with implementing a simple option type in Rust. An option type is a common programming construct that represents either a value or nothing. In this problem, you will create a module called `opt` and define an enum `Option` within it. The `Option` enum should have two variants: `Some` to hold a value of t...
magicoder
You are tasked with creating a Python function that processes image data and calculates the time taken for the entire process. The function will take a list of image paths as input, process each image, and then print a message indicating the time taken for the entire process. The function should perform the following ...
magicoder
You are tasked with implementing a simple resource management system using C#. The system should allow for the proper handling of resources to prevent memory leaks and ensure efficient resource usage. Your task is to create a class that manages a server handle using the IDisposable interface. Create a C# class called ...
magicoder
You are tasked with creating a Bash script that reads user configuration from a file and applies the settings accordingly. The user configuration file contains key-value pairs in the format `key=value`, with each pair on a new line. Your script should read this file and set the corresponding variables in the script bas...
magicoder
You are tasked with implementing a class that represents a MIDI channel with a negative offset. The MIDI channel should support indexing, where the index is adjusted based on the negative offset. The MIDI channel should be able to return the adjusted index for a given input index. Write a Python class `MidiChannel` th...
magicoder
You are tasked with implementing a sampling function for a custom data structure. The function should take a vector of items and a sample size as input, and return a random sample of the specified size from the input vector. Additionally, the function should handle potential errors using a custom error type. You are p...
magicoder
You are given a list of strings representing contact information from a business card scanner. Each string in the list corresponds to a line of text from the scanned business card. The task is to write a function that extracts the email addresses from the contact information. Write a function `extract_emails(card: Lis...
magicoder
You are given a JavaScript function that is intended to render a section of a web page. However, the function is incomplete and contains a placeholder `// Your code here` that needs to be filled in. Your task is to complete the function so that it properly renders the section with the given content. The function shoul...
magicoder
You are tasked with implementing a class that represents an item in a store's inventory. The item has two attributes: `sellIn` representing the number of days until the item expires, and `quality` representing the quality of the item. Your task is to implement a method in the class that updates the `sellIn` and `qualit...
magicoder
You are tasked with creating a logging configuration system for a PHP application. The system should be able to handle different levels of logging and store the logs in a structured manner. Your task is to implement a class that can configure and manage the logging system. You are provided with a basic PHP code snippe...
magicoder
You are tasked with creating a simple Rust program to manage a library of books. The program should allow users to add new books, remove existing books, and display the list of all books in the library. To achieve this, you need to define a `Book` struct with fields for `title`, `author`, and `isbn`. Additionally, you ...
magicoder
You are tasked with implementing a text formatting function for a styling language. The function should take an array of styling tokens and produce a formatted text output based on the token types and content. The styling tokens consist of three types: `StyleTokenType.TEXT`, `StyleTokenType.STYLE`, and `StyleTokenType....
magicoder
You are tasked with implementing a custom TLS (Transport Layer Security) options class for an MQTT (Message Queuing Telemetry Transport) client in C#. The class should provide the necessary properties to configure the TLS settings for secure communication with an MQTT broker. Your task is to complete the implementatio...
magicoder
You are tasked with creating a Python function that parses a given policy rule and extracts the required permissions from it. The policy rules are defined using the `oslo_policy` library, and the permissions are represented as strings. The function should take a policy rule as input and return a list of permissions ext...
magicoder
You are tasked with implementing a Python class method that determines whether a result file is the main file in a distributed result set. The method should return True if the global number of nodes does not equal the number of nodes in the file, and False otherwise. However, it should be noted that this method is not ...
magicoder
You are given a string containing a mix of uppercase and lowercase letters. Your task is to write a function that returns a new string where the uppercase letters are converted to lowercase and the lowercase letters are converted to uppercase. Any characters that are not letters should remain unchanged. Write a functi...
magicoder
You are working on a project that involves integrating the Spotify Web API into a Java application. As part of the continuous integration process, you need to automate the decryption of a file using OpenSSL and import the decrypted file into the GPG keychain. The encrypted file `codesigning.asc.enc` is stored in the `t...
magicoder
You are tasked with implementing a function that processes and displays information about browser extensions. The function takes an object representing a browser extension record as an argument and generates HTML code based on the record's properties. The record object has the following structure: ```javascript const r...
magicoder
You are tasked with implementing a message delivery confirmation system for a satellite communication protocol. The protocol involves sending Short Burst Data (SBD) messages from a mobile device to a satellite network. Your goal is to create a Rust structure and associated methods to handle the confirmation status of t...
magicoder
You are tasked with creating a function to process image features and questions for a visual question answering system. The function should take in image features, bounding boxes, and a question, and then pad the image features and process the question using specific methods. You are given the following code snippet a...
magicoder
You are tasked with creating a simple GraphQL server using Python and the `graphene` library. Your goal is to define a schema that includes a query and a mutation. The schema should be able to handle basic operations for a hypothetical data model. Your task is to define the necessary components to achieve this, inclu...
magicoder
You are tasked with creating a Bash script that processes user input to perform various file operations. The script should handle the following functionalities: 1. If the user enters "ls", the script should list all the files in the current directory. 2. If the user enters "cat <filename>", the script should display t...
magicoder
You are tasked with implementing a function that updates the order of offshelf stacks for a given event in a Redux store. The function takes in the current state of the stacks and an action containing the list of stack IDs and the event ID. It should return a new state with the offshelf stack list updated according to ...
magicoder
You are tasked with implementing a Python class that performs a specific type of transformation on a given input. The class should contain a method that applies a transformation function to each element of a given array based on certain conditions. Your task is to complete the implementation of the method `apply_transf...
magicoder
You are tasked with implementing a Python class that provides various string manipulation and mathematical operations. The class should have methods for extracting numbers from a string, extracting and converting float numbers, performing mathematical operations, converting currency, removing strings, and inserting str...
magicoder
You are working on a machine learning project to classify images of different plant diseases. You have a confusion matrix `c_matrix` that represents the performance of a classification model. The confusion matrix is a 2D array where the rows represent the actual classes and the columns represent the predicted classes. ...
magicoder
You are tasked with implementing a message queue system for a multi-process application. The goal is to capture and store messages from various processes and then retrieve and display them in a specific format. Your task is to create a Python class called `MessageQueue` that provides the following functionality: 1. `...
magicoder
You are tasked with creating a script to manage the lifecycle of processes on a Unix-based system. The script should be able to start, stop, and check the status of a given process. Additionally, it should handle cases where a process does not stop gracefully within a specified timeout period. Your script should inclu...
magicoder
You are tasked with implementing a caching mechanism for language definitions in a multilingual application. The provided code snippet is from a PHP Laravel application and is part of a method that clears the cached language definitions. The `forget` method is called with a `$request` parameter, and it iterates through...
magicoder
You are tasked with creating a weather forecast application. The application needs to periodically update the weather forecast data from an external source and store it in the database. To achieve this, you need to implement a forecast updater module that will be triggered when the application starts. Your task is to ...
magicoder
You are tasked with implementing a function that maps an internal validation result with array errors to a mapped validation result. The internal validation result contains a key, message, type, and a boolean indicating success, along with an array of errors. Each error in the array contains fields for name, surname, a...
magicoder
You are tasked with implementing a memoization utility for caching the results of opening iModel databases. Memoization is a technique used to improve the performance of functions by caching the results of expensive function calls and returning the cached result when the same inputs occur again. Your goal is to impleme...
magicoder
You are tasked with creating a React component that displays a specific story based on the ID provided in the URL. The component should fetch the story data from an API and render it on the page. Your task is to implement the `StoryItem` component, which will be used as the route handler for the path `/story/:id`. The...
magicoder
You are tasked with implementing a simple command-line application for managing a list of tasks. The application should allow users to add tasks, mark tasks as completed, view all tasks, and delete tasks. The tasks should be stored in memory and should persist for the duration of the application's execution. Your task...
magicoder
You are tasked with creating a Python class that interacts with a Redis database and generates an HTML template. The class should have methods for pushing data to a Redis list, calculating the total size of the list, and shutting down the class instance. Your task is to implement the missing methods of the class based ...
magicoder
You are tasked with implementing a custom form validation for a user login system in a Django web application. The provided code snippet is a part of a Django form class for user login, and it includes a custom validation check for the email field. Your task is to complete the custom validation logic for the email fiel...
magicoder
You are tasked with implementing a function that checks whether a given string represents a valid ISO 8601 duration. An ISO 8601 duration is a string that represents a time span, such as "P3Y6M4DT12H30M5S" for a duration of 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds. You need to create a function `...
magicoder
You are tasked with implementing a Python class to manage a set of magical artifacts and their effects. Each artifact can have multiple effects, and the effects are represented as strings. Your task is to create a class `ArtifactSet` with the following functionalities: 1. Add a new artifact to the set. 2. Remove an art...
magicoder
You are given a Python code snippet that manipulates a pandas DataFrame `df` using the `Constants` class and the NumPy library. Your task is to write a function that replicates the behavior of the code snippet and returns the modified DataFrame. The code snippet performs the following operations: 1. It calculates the ...
magicoder
You are tasked with implementing a version control system for a software project. The system needs to support externalizing the project's version to a file. The provided code snippet is a part of the system's functionality. The `wr.WriteVersion(maxVersion)` call is used to write the maximum version of the project to an...
magicoder