instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with creating a web application that displays a list of courses. The courses are stored in a database, and you need to retrieve and display their names using a server-side scripting language like PHP. The code snippet provided is a part of the view file that iterates through the retrieved courses and dis...
magicoder
You are tasked with implementing a Java interface for verifying digital signatures. The interface, `SignatureVerifier`, extends another interface `SignatureVerifierSimple` and takes a generic type `S` that extends `SignatureBinary`. The interface includes a default method `verifyAfterUpdate` that takes an object of typ...
magicoder
You are tasked with implementing a LandmarkCollection class in Python that allows the addition of landmarks and retrieval of the collection's name. The LandmarkCollection class should have the following functionalities: 1. The ability to add a landmark to the collection using the add_landmark method, which takes a list...
magicoder
You are tasked with implementing a simplified version of a Twitter API client in Rust. Your goal is to create a method for posting a tweet using the provided code snippet as a reference. You are given the following code snippet as a starting point: ```rust use crate::{TweetResult, TwitterAPI}; use anyhow::Result; use...
magicoder
You are tasked with implementing a logging system for a weather modeling application. The application consists of multiple modules, including `weather_models`, each of which requires its own logger for tracking events and errors. Your goal is to create a logging system that allows each module to have its own logger ins...
magicoder
You are tasked with implementing a validation system for a web application's configuration settings. The configuration settings are represented as a dictionary with keys representing the setting names and values representing the validation rules for each setting. The validation rules can include requirements such as be...
magicoder
You are tasked with creating a Python web application for managing tickets. The application uses the Flask framework, and the code snippet provided registers a blueprint for handling ticket-related functionality. Your task is to implement a function that generates unique ticket IDs for each new ticket created in the s...
magicoder
You are tasked with implementing a simple caching mechanism for a product organization's data. The organization has a set of products, each with a unique identifier and a boolean value indicating availability. Your task is to create a caching system that efficiently stores and retrieves this product data. You are prov...
magicoder
You are working on a machine learning project and need to evaluate the performance of a classifier. You decide to use a dummy classifier as a baseline to compare the performance of your model. The `DummyClassifier` class from the `sklearn.dummy` module in Python's scikit-learn library can be used to create simple basel...
magicoder
You are tasked with creating a command-line tool that can remove specific polygons from a given shapefile based on a user-defined attribute. The shapefile contains various polygons, each associated with different attributes. Your task is to implement a Python script that takes user input to specify the attribute value ...
magicoder
You are tasked with creating a custom Django REST Framework viewset for a model called `VarType`. The viewset should include custom permissions and caching for authenticated users. Additionally, the viewset should use a read-only serializer for the `VarType` model. Your task is to complete the implementation of the cu...
magicoder
You are tasked with implementing a method to create source items from a given date range. The method should take in a source, start date, end date, minimum quantity, maximum quantity, creation date, creator name, and source group enum, and return a collection of source items that fall within the specified date range an...
magicoder
You are tasked with implementing a class that represents a book in a library. The class should have methods to set and get the title of the book. Below is a partial implementation of the `Book` class: ```java public class Book { private String title; // Other methods and constructors are not shown public...
magicoder
You are tasked with creating a Python function that determines the platform and execution path based on the given cross tool. The function should take a string representing the cross tool as input and return a tuple containing the platform and execution path. The function should adhere to the following specifications:...
magicoder
You are tasked with creating a program that analyzes a given text file to count the occurrences of specific words. The program should read the text file, tokenize the words, and then count the occurrences of each word. Additionally, the program should ignore common stop words (e.g., "the", "is", "and") and should be ca...
magicoder
You are tasked with implementing a Python function that processes a list of dictionaries representing different items. Each dictionary contains information about an item, including its name, price, and category. Your goal is to create a function that filters the list of items based on a given category and sorts the fil...
magicoder
You are tasked with creating a Python class that manages a music library. The class should be able to handle albums, students, modules, and tracks, and provide serialization functionality for each of these entities. Your task is to implement the `MusicLibrary` class with the following requirements: 1. The class should...
magicoder
You are tasked with creating a program to manage and visualize school events on a timeline. The provided code snippet is part of a larger program that populates a "tail diagram" with school events for each year. The `source` object contains information about the school events, including the years covered and the events...
magicoder
You are tasked with implementing a caching mechanism for thumbnail images in a file management system. The system has a method `cacheReceiveThumb` that takes in a `BaseFileInfo` object and an `InputStream` containing the thumbnail image data. The method is responsible for caching the thumbnail image and ensuring that d...
magicoder
You are tasked with implementing a custom Python package installer that supports both regular and "zip-safe" installations. The installer should be able to handle dependencies and ensure that the package is installed correctly based on the specified installation mode. Your task is to implement the `install_package` fu...
magicoder
You are given a singly linked list implementation in Python. The `Node` class is defined as follows: ```python class Node: def __init__(self, data): self.data = data self.next = None ``` You need to implement a method `find_nth_from_end(head, n)` that takes the head of a linked list and an integer...
magicoder
You are tasked with implementing a Python class that extends the functionality of the provided `BasePage` class. The new class, `ExtendedPage`, should inherit from `BasePage` and include additional methods for interacting with web elements using Selenium. Your task is to complete the implementation of the `ExtendedPag...
magicoder
You are given a string `s` consisting of lowercase English letters and spaces. The string contains a hidden message encoded using a simple substitution cipher. In this cipher, each letter is shifted a certain number of places down or up the alphabet. For example, with a shift of 3, 'a' would be replaced by 'd', 'b' wou...
magicoder
You are tasked with implementing a class that manages job requests and their recovery status. The class should provide methods to check if a job requests recovery and to set the recovery status of a job request. You need to implement a Java class called `JobManager` with the following specifications: - The class shoul...
magicoder
You are given a string `haystack` and a string `needle`. Your task is to implement a function `find_needle_in_haystack` that returns the index of the first occurrence of `needle` in `haystack`, or -1 if `needle` is not part of `haystack`. The twist is that before searching for `needle` in `haystack`, you need to revers...
magicoder
You are tasked with implementing an autocorrect function that replaces certain words or phrases with a predefined replacement. The function should take a string as input and replace specific words or phrases with the designated replacements. Your task is to write a Python function `autocorrect` that takes a string as i...
magicoder
You are tasked with implementing a custom view in Swift that displays an image and a title label. The provided code snippet contains a custom view class with two methods: `layoutSubviews` and `setUI`. The `layoutSubviews` method is responsible for setting the frames of the `imageView` and `titleLabel`, while the `setUI...
magicoder
You are tasked with implementing a file structure processing module for a file management system. The module is responsible for crafting messages based on the file structure response received from the system. The code snippet provided is a part of this module and shows the construction of an action message with a paylo...
magicoder
You are tasked with creating a program that processes a code snippet and extracts specific information from it. The code snippet will contain a reference to a GitHub repository, the number of stars the repository has, and a list of modules within the repository. Your task is to write a function or method that takes th...
magicoder
You are tasked with creating a Django REST framework serializer for a User model. The serializer should have two fields: "password" and "token". The "password" field should be a write-only field with a minimum length of 8 characters, and the "token" field should be a read-only field with a maximum length of 255 charact...
magicoder
You are tasked with creating a Python package that simulates a simple banking system. The package should include functionalities for creating accounts, depositing and withdrawing funds, and checking the balance. Your task is to implement the `BankAccount` class with the specified methods and attributes. The `BankAccou...
magicoder
You are tasked with implementing a function that calculates the content margin for an element based on the provided properties. The function should handle cases where the `border` property is not defined or is not an object. The content margin is calculated based on the `gutter` and `border` properties. The function s...
magicoder
You are tasked with implementing a logging system for a web crawling application. The provided code snippet demonstrates the setup of a logging system using the Python `logging` module. Your task is to complete the implementation by adding the necessary configurations and logging statements to capture relevant informat...
magicoder
You are tasked with implementing a generic command structure for a command-line interface in Rust. The structure should support formatting the command as a string and should be parameterized by the names and arguments of the command. Your task is to complete the implementation of the `Command` structure and its associ...
magicoder
You are tasked with creating a color picker component for a mobile application. The color picker consists of sliders for red, green, and blue components, and a stepper for the alpha (transparency) component. The sliders and stepper have initial values and constraints set as shown in the following code snippet: ```swif...
magicoder
You are tasked with implementing a priority setting system for a logging library. The logging library uses the log4cpp framework, which provides a `Priority` class for setting the logging priority level. The `setPriority` method is used to set the priority level for logging messages. Your task is to create a class tha...
magicoder
You are tasked with creating a Python class that manages the execution of Node.js scripts using a specific runtime image. Your task is to implement the `NodeJSExecutionsTest` class with the necessary methods to set up the environment and execute a basic Node.js script. The class should have the following attributes an...
magicoder
You are tasked with implementing a class representing a 2D location in a coordinate system. The class should have methods to move the location by a given delta in the x and y directions. Below is a partial code snippet for the `Location` class: ```python class Location: def __init__(self, x, y): self.x = x...
magicoder
You are tasked with simulating a passcode lock system in Swift. The passcode lock system has a delegate that is notified whenever the state of the passcode lock changes. Your goal is to implement the `PasscodeLock` class and its delegate, and then write a function to test the state change functionality. The `PasscodeL...
magicoder
You are tasked with creating a custom repository method for a user entity using Doctrine ORM in PHP. The user entity is represented by the `User` class, and the custom repository method will be added to the `UserRepository` class. The `UserRepository` class extends the `Doctrine\ORM\EntityRepository` class, which provi...
magicoder
You are tasked with implementing a simple cryptographic hash function called the Miyaguchi-Preneel (Miyaguchi-Preneel Compression Function) in Rust. The Miyaguchi-Preneel hash function is based on the Miyaguchi-Preneel construction, which is a method for constructing cryptographic hash functions from block ciphers. In ...
magicoder
You are tasked with implementing a function that takes in a list of tuples representing 2D points and returns the centroid of these points. The centroid of a set of points is the average position of all the points. It can be calculated by finding the average of the x-coordinates and the average of the y-coordinates of ...
magicoder
You are tasked with creating a Python function that handles database errors and extracts the precise error message from the exception. Your function should take in an exception object and return the specific error message associated with the database error. Create a function `extract_database_error_message` that takes...
magicoder
You are tasked with implementing a simplified version of a performance monitoring system. The system should track the duration of various operations and provide summary statistics for different categories of operations. You are given a code snippet from a Java method that is part of the performance monitoring system. ...
magicoder
You are tasked with implementing a Python class method that opens a local socket on a specified port and sends a ping command to ensure the server is alive. Your task is to complete the `_openLocalSocket` method within the given class. The method should handle socket errors and close the socket if an error occurs. You...
magicoder
You are tasked with creating a script to automate the installation of a custom zsh theme and reloading the zsh settings. Your script should perform the following steps: 1. Create a directory named "themes" in the $ZSH directory if it does not already exist. 2. Download a zsh theme file named "hyperzsh.zsh-theme" from a...
magicoder
You are tasked with implementing a function to perform sparse vector multiplication. A sparse vector is a vector in which most of the elements are zero. The function should take a list representing the sparse vector, the length of the vector, and a pair of indices and values. The function should return the result of th...
magicoder
You are given a Python function `process(record)` that takes a dictionary `record` as input. The dictionary `record` contains key-value pairs representing various attributes of a surface. The function is intended to process the `idsurface` attribute of the input `record`. The `idsurface` attribute is a space-separated ...
magicoder
You are tasked with creating a program to process and display nutrition information for a recipe. The given code snippet is a part of a PHP script that is responsible for displaying a list of nutrition information for a recipe. The `$thisRecipe` variable holds the recipe data, and the nutrition information is stored in...
magicoder
You are tasked with implementing a Python function that processes a given dictionary containing markdown text and file names. The function should create individual markdown files using the provided file names and populate them with the corresponding markdown text content. The input dictionary `md` contains two keys: -...
magicoder
You are given a Python class that performs various operations related to clustering and label analysis. The class contains a method `create_experiment` that takes a variable number of arguments and sets the global variable `args` to the provided arguments. The method also logs information about the count of kernels and...
magicoder
You are given a string `s` of length `n`. Your task is to write a function or method to find the length of the shortest substring that can be repeated to form the original string. If no such substring exists, return 0. For example, given the string "abcabcabc", the shortest repeating substring is "abc", and its length...
magicoder
You are tasked with creating a Python program that reads a file and counts the occurrences of reserved keywords in the file. Reserved keywords are words that have special meaning in the Python programming language and cannot be used as identifiers. Your program should read the file specified by the `filename` variable ...
magicoder
You are tasked with implementing a featurization and correlation analysis tool for a text dataset. The provided code snippet is a part of a Python script that performs featurization, correlation computation, and filtering of top n-grams based on their correlations. Your task is to implement the `Featurizer` class and ...
magicoder
You are tasked with creating a Python function that analyzes a given BEL graph to identify potential errors within the graph and provide suggestions for fixes. The function should take a BEL graph as input and return a list of suggestions for improving the graph's integrity. The BEL graph is represented as a collectio...
magicoder
You are working on a Python project that involves data processing using the Dagster library. Your task is to create a custom type storage plugin for a specific data type. Type storage plugins in Dagster are used to define how a specific Python type should be stored and loaded from the Dagster event log. You need to imp...
magicoder
You are tasked with implementing a Java class to parse and manipulate version numbers. The class `VersionNumber` represents a version number in the format "major/minor/patch". The provided code snippet is part of a method that processes version number information and returns a new `VersionNumber` object. Your task is ...
magicoder
You are tasked with implementing a function that processes a wishlist of items and returns the total count of unique items in the wishlist. The wishlist is represented as an array of strings. However, the provided code snippet contains a potential issue that needs to be addressed. The code snippet provided is a partia...
magicoder
You are tasked with creating a program to solve a crossword puzzle. The crossword puzzle is represented as a 2D board of characters, and your program needs to find the head letters for each word in the puzzle. The head letter of a word is the first letter of the word in the crossword puzzle, and its position is denoted...
magicoder
You are tasked with creating a Python function that parses a dictionary containing metadata information about a software package and extracts specific details based on given criteria. Write a function `extract_metadata` that takes in a dictionary `metadata` and a list of strings `criteria`. The `metadata` dictionary c...
magicoder
You are tasked with implementing a simple asynchronous task scheduler for a microcontroller using the Arduino Uno platform. The scheduler should allow tasks to be scheduled for execution at specific intervals. The microcontroller has a single-core processor and limited memory, so the scheduler needs to be efficient and...
magicoder
You are tasked with implementing a reference counting mechanism for managing the lifetime of objects in a C++ program. The provided code snippet is a simplified version of a reference counting system. The `AcquireReference` and `ReleaseReference` functions are used to increment and decrement the reference count of an o...
magicoder
You are tasked with parsing and extracting information from a set of HTML elements representing approval requests. Each approval request is represented by an HTML snippet containing the following structure: ```html <div class="row" style="line-height: 39px; border-bottom: 1px solid #F1F1F1;"> <a class="col-md-7" h...
magicoder
You are tasked with creating a Python function that processes a list of URLs and returns a dictionary containing the domain names as keys and the number of occurrences of each domain as values. You are given a code snippet that sets the `ROOT_DIR` variable and imports the necessary modules for a Django web application....
magicoder
You are tasked with implementing a Python function that simulates a simple game of rock-paper-scissors. The function should take two arguments representing the choices of two players and determine the winner based on the classic rules of the game. The function should return the result as a string indicating the winner ...
magicoder
You are tasked with implementing a function that reads in an embedding file and stores its contents as a dictionary object. The embedding file can be either a binary or text file, and the function needs to determine the type of file and process it accordingly. The keys of the dictionary will be tokens (strings), and th...
magicoder
You are tasked with implementing a session management system for a web application. The given code snippet is a part of a method that associates a user's session ID with their user ID and user information in a cache. The CacheUtil class provides methods for interacting with the cache, and the Constants class contains v...
magicoder
You are tasked with creating a Python function that simulates a simple file loading and plotting process. Your function should take a directory path as input, load data from files within that directory, and then plot the loaded data using the `matplotlib` library. Additionally, you need to ensure that the function is p...
magicoder
You are tasked with implementing a message handling system for a network application. The given code snippet is a partial implementation of a message type called "Destroy_MessageType" and its corresponding event "Destroy_Message". Your task is to complete the implementation of the "Destroy_MessageType" class and provid...
magicoder
You are tasked with implementing a merge function that aligns the ordering of ordered features that are not containment references in a software system. The merge function takes two lists of strings as input and merges them into a single list while aligning the ordering of the elements based on certain rules. The rule...
magicoder
You are tasked with creating a Python function that processes data from a CSV file and generates a graph using the Plotly library. The function, `graph_difficulties`, takes two optional boolean parameters: `is_by_height` and `show`. The function reads data from a CSV file, creates a Plotly figure, and adds a scatter pl...
magicoder
You are tasked with implementing a function that converts a universally unique identifier (UUID) to and from an array of bytes. The UUID is represented as a 16-byte value, and the array of bytes is a collection of 16 unsigned 8-bit integers. Your goal is to create a function that can perform this conversion bidirection...
magicoder
You are given a set of coordinates representing points on a 2D plane. Your task is to find the minimum area of a rectangle that can be formed by selecting four distinct points from the given set of coordinates. You are to implement a function `min_rectangle_area(coordinates)` that takes in a list of tuples, where each...
magicoder
You are tasked with implementing a function that calculates the sum of all the even numbers in a given list of integers. The function should take a list of integers as input and return the sum of all the even numbers in the list. For example, given the input list [1, 2, 3, 4, 5, 6], the function should return 12 (2 + ...
magicoder
You are tasked with creating a Python function that dynamically loads a specific class based on a given file extension. The function should be able to handle different file types and return the appropriate class instance based on the file extension. You are provided with a code snippet that imports classes from differ...
magicoder
You are tasked with implementing a Python class that generates a compiled list of strings based on given templates and data. The class should have methods to add templates, categories, and compiled data, and a method to generate the final compiled list. You are given a code snippet that partially implements the class....
magicoder
You are tasked with implementing a class that represents a software feature. The class should have a property to retrieve the description of the feature. You need to create a Feature class with a private field _featureInfo of type FeatureInfo, and a public property Description that returns the description from the _fea...
magicoder
You are tasked with simulating the configuration of Open vSwitch (OVS) interfaces and ports using the `nmcli` command-line tool. Your goal is to create a Python program that generates the necessary `nmcli` commands based on a given set of network configurations. You are given the following information: - A list of net...
magicoder
You are tasked with implementing a velocity decay system for a game engine. The system is responsible for decreasing the velocities of entities over time to simulate friction or air resistance. You are given a code snippet from the system's update function, which takes in mutable references to the system's data. The `d...
magicoder
You are tasked with creating a Python web application that provides an API for retrieving information about bike availability in different postcodes. The application uses the aiohttp library for handling HTTP requests and responses. The code snippet provided sets up two routes for the application: one for retrieving in...
magicoder
You are tasked with implementing a pattern generator function that takes an integer `i` as input and yields a specific pattern based on a predefined `BASE_PATTERN`. The `BASE_PATTERN` is a sequence of values that the generator will iterate through. The generator should repeat each value in the `BASE_PATTERN` `i + 1` ti...
magicoder
You are given a binary tree represented by a class `TreeNode` with the following structure: ``` class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } ``` The `val` field represents the value of the node, and the `left` and `right` fields represent the left and right chi...
magicoder
You are tasked with creating a Python function that simulates a simplified version of the `git-fortune` command-line tool. The function should take in a format type and a fortune ID, and return the corresponding fortune message in the specified format. The `git-fortune` tool retrieves a fortune message from a database...
magicoder
You are tasked with implementing a Python class that simulates a simple bank account. The class should have methods for depositing funds, withdrawing funds, and checking the current balance. Additionally, the class should raise custom exceptions for invalid operations, such as attempting to withdraw more funds than are...
magicoder
You are tasked with creating a program that extracts and organizes information from a given HTML file. The HTML file contains multiple script tags with src attributes pointing to JavaScript files. Your goal is to parse the HTML file, extract the URLs of the JavaScript files, and then organize them into a list. Write a...
magicoder
You are working on a data processing pipeline for aviation data. The given code snippet is a part of a function that processes a list of dictionaries and writes the data to a CSV file. However, there is a commented-out line that seems to be related to the keys of the dictionaries in the list. Your task is to complete t...
magicoder
You are tasked with creating a program that processes a list of file paths and extracts specific information from each file. Each file contains data related to Unicode character properties. The program should read the content of each file, extract the relevant information, and store it in a structured format for furthe...
magicoder
You are tasked with implementing a wallet manager system that can be in one of three states: created, disconnected with a reason, or connected. The states are represented using an enum called `WalletManagerState`. The `WalletManagerState` enum is defined as follows: ```swift public enum WalletManagerState: Equatable {...
magicoder
You are tasked with creating a C# program that interacts with an OData service to retrieve and process data. The program should utilize the `Microsoft.OData.Client` library to establish a connection to the OData service and retrieve a specific set of records based on a given filter condition. Additionally, the program ...
magicoder
You are tasked with implementing a custom networking framework in Swift. The framework should support making GET requests with the ability to set acceptable content types and report progress. Your task is to create a class `CustomNetworking` with the following requirements: - A method `setAcceptableContentTypes` that ...
magicoder
You are tasked with creating a Python function that takes a list of strings as input and returns a new list containing only the unique strings from the input list. The function should preserve the original order of the strings while removing any duplicates. Create a function called `get_unique_strings` that accepts a ...
magicoder
You are tasked with creating a Python function that interacts with different types of databases based on a specified database type. The function should connect to the database, execute a query, and return the results. The function should support two types of databases: "sqlite" and "mysql". For "sqlite" databases, the ...
magicoder
You are given a data structure called a Fenwick tree (also known as a Binary Indexed Tree) and two operations to perform on it: `add` and `sum`. The Fenwick tree is represented by an array `d` of length `n`, initially filled with zeros. The tree supports two main operations: 1. `add(int i, T x = 1)`: This operation ad...
magicoder
You are tasked with creating a Rust function that converts a given JSON object into a pretty-printed string. The function should take a JSON object as input and return a string with the JSON content formatted in a human-readable way. You are provided with the following code snippet for inspiration: ```rust let to_writ...
magicoder
You are tasked with creating a Swift function that processes a given file and returns the line and column numbers of a specific character within the file. The function should also check if the iOS version is available and handle any conditional compilation directives present in the file. You are provided with a code s...
magicoder
You are tasked with implementing a class that represents a job application. The class should have a field to indicate whether the job has an annex. You need to create the getter and setter methods for this field. Create a Java class `JobApplication` with the following specifications: - A private field `jobHasAnnex` of...
magicoder
You are tasked with implementing a class that represents a source of data. The class should have methods for adding data, retrieving data, and checking if the source is empty. You are provided with a code snippet that tests the interface of the model class `Source`. Your task is to create the `Source` class with the sp...
magicoder
You are tasked with implementing a function that retrieves the URL from a given dictionary `status`. The function should handle potential exceptions and return `None` if the URL is not found or if an exception occurs. Write a function `get_url(status)` that takes a dictionary `status` as input and returns the URL if i...
magicoder
You are working on a project involving NMR (Nuclear Magnetic Resonance) data processing. Your task is to write a Python function that performs a comparison between two Sparky NMR data files and identifies any differences between them. The Sparky NMR data files are in UCSF format. The code snippet provided demonstrates...
magicoder
You are tasked with implementing a simple 2D rendering engine that can draw triangles with basic material shading. The rendering engine will utilize a scene, triangles, and a basic material shader to render the triangles with appropriate shading. You are provided with the following classes and their functionalities: 1...
magicoder