instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with implementing a Python function that takes a list of integers as input and returns the sum of all the even numbers in the list. If the input list is empty or does not contain any even numbers, the function should return 0. The function signature is: ```python def sum_of_even_numbers(nums: List[int])...
magicoder
You are tasked with implementing a simple syntax checker for a custom programming language. The language uses curly braces for defining code blocks, and your task is to identify and report any missing or mismatched braces in the code. You are given a snippet of code as a string. The code may contain any combination of...
magicoder
You are tasked with simulating a game where the player's objective is to reach a target score by collecting points. As the player's total score reaches or exceeds the target score, the game's difficulty level increases, resulting in certain game elements being upgraded. The game has two specific upgrades: increasing th...
magicoder
You are tasked with implementing a function that converts a given string into "camel case" format. In camel case, each word in the string (except the first one) is capitalized and all the words are concatenated without any spaces. For example, "hello world" would become "helloWorld". You need to implement the followin...
magicoder
You are tasked with creating a Python program that simulates a simplified file system. The program should allow users to navigate through directories, list the contents of a directory, and change the current working directory. To achieve this, you need to implement a class called `FileSystem` with specific methods. Th...
magicoder
You are tasked with creating a PHP class method that retrieves the number of media records from a database using the Laravel framework's Eloquent ORM and the Illuminate\Support\Facades\DB class. You are provided with a partial code snippet from the Medias class, which extends the Model class. The Medias class represen...
magicoder
You are given a Python code snippet that initializes a complex number `c` and an integer `n`. Your task is to implement a function that generates the Mandelbrot set based on these inputs. The Mandelbrot set is a set of complex numbers for which the function f(z) = z^2 + c does not diverge when iterated from z = 0. The...
magicoder
You are given a list of integers. Write a function `max_prod_three` to find the maximum product that can be obtained by multiplying three integers from the list. For example, given the input list `[5, -2, 3]`, the maximum product that can be obtained by multiplying three integers is `-30` (5 * -2 * 3). For the input l...
magicoder
You are tasked with creating a Python function that processes a list of optimization targets and creates directories for each target using the target's ID. The function should take in a list of target objects and create directories named after each target's ID within a "targets" directory. The target object has the fo...
magicoder
You are tasked with creating a validation function for a decentralized application (dApp) using the Holochain framework. Holochain is a platform for building decentralized applications that uses a unique approach to data storage and validation. In this problem, you will be working with the Rust programming language and...
magicoder
You are tasked with creating a Python class that simulates a simple banking system. The class should have the following functionalities: 1. Initialize with a bank name and an empty customer list. 2. Allow the addition of new customers with their initial balance. 3. Enable deposits and withdrawals for existing customers...
magicoder
You are tasked with implementing a simple region management system for a graphical user interface. The region is defined by its left, bottom, width, and height, and also has a center point (cx) calculated based on these properties. Your task is to write a function that updates the region properties and determines if th...
magicoder
You are tasked with creating a Python class that simulates a simple email sending bot. The bot should be able to send emails using the provided email and password. Additionally, the bot should have a maximum number of tries for sending emails, which can be specified during its initialization. Your task is to complete ...
magicoder
You are tasked with creating a PHP class that manages user authentication and article creation. The class should include methods for user authentication and article creation, and it should utilize the provided `User` and `StoreArticleRequest` classes. Your task is to implement the `ArticleManager` class with the follo...
magicoder
You are tasked with creating a program that processes a list of Git clone commands and extracts the repository names from each command. The repository name is the last segment of the URL after the last forward slash ("/"). Write a function `extract_repo_name` that takes a list of Git clone commands as input and return...
magicoder
You are tasked with implementing a custom view class in Swift that manages the layout of its subviews. The provided code snippet is a part of the custom view class, and it includes an overridden method `prepare()` that sets the height of the view. Your task is to complete the implementation of the custom view class by ...
magicoder
You are given an array of integers `in` of size `n`. Your task is to write a program to find the number of elements in the array that are greater than the average of all the elements in the array. Write a function or a program that takes an integer `n` as input, followed by `n` integers representing the elements of th...
magicoder
You are tasked with creating a program that can parse and extract information from a given code file. The code file contains a class definition in Swift, and your program needs to extract the class name, the date it was created, and the copyright information. You are given a code snippet as an example: ```swift // Cr...
magicoder
You are tasked with creating a script that processes data and generates a flame graph visualization based on a given filter. The script takes a filter as an argument, then uses the `uniq`, `awk`, and `flamegraph.pl` commands to process the data and create the visualization. Your task is to write a Bash script that tak...
magicoder
You are tasked with creating a Python function that reads configuration settings from a file and returns specific values. The configuration file is in the format of a standard INI file and contains sections and key-value pairs. You need to implement two functions: `getResultDirname()` and `getDataTableName()`. The `get...
magicoder
You are tasked with implementing a selection sort algorithm to sort a given list of integers in ascending order. However, the algorithm seems to be taking longer than expected to execute. Your task is to analyze the given code snippet, identify the potential issue causing the slow execution, and optimize the code to im...
magicoder
You are working as a DevOps engineer for a company that uses Kubernetes for managing containerized applications. Your team is responsible for deploying and managing various microservices on the Kubernetes cluster. As part of the deployment process, you often use the `kubectl` command-line tool to apply configuration fi...
magicoder
You are tasked with creating a Python function that processes letters and extracts relevant information based on the specified text type. The function takes in parameters `max_letters`, `workdir`, and `text_type`. The `max_letters` parameter limits the number of exported letters for testing purposes. The `workdir` para...
magicoder
You are tasked with creating a web application that involves showing and hiding a button based on user input. The application uses jQuery for DOM manipulation. Below is a simplified version of the relevant code snippet: ```html <!DOCTYPE html> <html> <head> <title>Show/Hide Button</title> <script src="https://...
magicoder
You are tasked with implementing a module resolution algorithm for a JavaScript module system. The module system uses the `export` and `import` keywords to define and use modules. When an `export` statement is encountered, it makes the local binding available for use in other modules. The `export * from 'module'` synta...
magicoder
You are tasked with creating a simple program to keep track of financial transactions. The program should continuously prompt the user to input a monetary value and update a running total based on the input. The program should terminate if the user inputs a negative value and print the final total. Write a Python prog...
magicoder
You are tasked with creating a Python function to generate a Docker Compose command based on a given set of parameters. The function should take in the site name, MariaDB root password, admin password, and app name as input and construct a Docker Compose command to set up a new site with the specified parameters. The ...
magicoder
You are tasked with creating a Python program to optimize a given scalar objective function using the DiscreteMinimizer class from the desdeo_tools library. The DiscreteMinimizer is a part of the desdeo_tools package, which provides tools for solving multiobjective optimization problems. The DiscreteMinimizer is used t...
magicoder
You are given a Rust enum `EggMediaType` and a mapping of its variants to the corresponding variants of another enum `MediaType`. Your task is to write a function that takes a value of `EggMediaType` as input and returns the corresponding `MediaType` according to the given mapping. Rust enum `EggMediaType`: ```rust en...
magicoder
You are tasked with creating a Python program to manage Docker containers. Your program should be able to remove a specified Docker container and then remove the corresponding Docker image. You are given the following information: - The code snippet provided demonstrates the commands to remove a Docker container named...
magicoder
You are tasked with implementing a content provider for a simple note-taking application. The content provider manages a collection of notes and exposes them to other parts of the application through a set of URIs. The code snippet provided is a part of the content provider implementation. Your task is to complete the...
magicoder
You are tasked with implementing a function that converts a given integer into its English word representation. For example, the integer 123 would be converted to "one hundred twenty three". The function should support integers within the range of 0 to 999,999,999,999 (inclusive). Your task is to implement the `int_to...
magicoder
You are tasked with implementing a Python module for handling HTTP request parameters in a web application. The module should provide classes for filtering, pagination, query string parsing, and sorting of data. Your task is to create the necessary classes and methods to achieve this functionality. You should implemen...
magicoder
You are tasked with implementing a generic vehicle state and command bounds class in C++. The class should be capable of handling both upper and lower bounds for vehicle states and commands. Your task is to define the class template and its member variables to store the upper and lower bounds for vehicle states and com...
magicoder
You are working on a memory manipulation algorithm for a game cheat program. The code snippet provided is a part of a function that is responsible for calculating the offset between the base address and the memory location of a specific data item within the game's memory space. The function iterates through the data it...
magicoder
You are tasked with creating a Python class that processes a DataFrame and performs various operations, including directory creation, data comparison, visualization, and file saving. Your task is to implement the missing methods in the given class to achieve the desired functionality. The class `DataProcessor` has the...
magicoder
You are working on a scientific simulation project that involves calculating the gravitational mass of a celestial body. The gravitational mass (GM) of a celestial body can be calculated using the formula: GM = G*(4.0/3.0)*π*(r0^3)*ρ0*Frac, where G is the gravitational constant, r0 is the radius of the celestial body, ...
magicoder
You are tasked with implementing a generic class that represents a shopping cart. The class should have a property called `Items` that stores the items in the shopping cart as an `ObservableCollection`. Additionally, the `Items` property should have a setter that initializes some internal logic by calling a method name...
magicoder
You are tasked with simulating the movement of a robot in a 2D space using the bicycle model. The bicycle model is a simplified representation of a vehicle's motion, where the robot moves based on its velocity, yaw rate, and time increment. The robot's position and orientation are represented by its x and y coordinates...
magicoder
You are given a code snippet containing variable declarations and an array initialization. Your task is to write a program that performs specific operations on these variables and the array. Given the following code snippet: ``` USHORT us = 0; int i = 0; unsigned int ui = 0; char string[] = "G...
magicoder
You are tasked with creating a Python function that calculates the mean absolute percentage error (MAPE) and then uses it to determine the accuracy of a predictive model. The MAPE is a measure of prediction accuracy of a forecasting method, and the accuracy is calculated as 100 minus the mean of the MAPE values. You a...
magicoder
You are tasked with implementing a function to validate a commitment in a cryptographic protocol. In this protocol, a commitment is generated and then decoded to a string, which is then converted back to the original commitment. Your task is to implement the decoding and validation process for the commitment. You are ...
magicoder
You are tasked with implementing a trait for a custom data type in Rust. The trait, `QueryStringable`, requires the implementation of a method that converts the data type into a vector of key-value pairs representing query parameters. The provided code snippet shows an example implementation for a data type called `Sca...
magicoder
You are tasked with implementing a simple Android application that tracks the direction of touch gestures on the screen. The provided code snippet is a part of the touch event handling logic in the application. The `switch` statement handles different types of touch events, and the `case MotionEvent.ACTION_MOVE` block ...
magicoder
You are tasked with implementing a password generator function in Python. The function should take in two parameters: `length` (an integer representing the length of the password to be generated) and `complexity` (an integer representing the complexity level of the password). The complexity level can be 1, 2, or 3, wit...
magicoder
You are tasked with implementing a simplified version of a web server response handling system. The system receives HTTP requests and sends corresponding responses. Your goal is to complete the implementation of the `handleRequest` method in the `WebServer` class, which processes the incoming request and sends the resp...
magicoder
You are tasked with implementing a Price class that represents a monetary value in a specific currency. The Price class should support division operations by both decimal and long values. Your task is to implement the Div method in the Price class, which divides the Price object by a given divisor and returns a new Pri...
magicoder
You are working on a database management system for a mobile device manufacturer. The system stores information about mobile devices, including their International Mobile Equipment Identity (IMEI) numbers and Type Allocation Code (TAC) numbers. The TAC is the first 8 digits of the IMEI number and is used to identify th...
magicoder
You are tasked with implementing a custom observation space function for a reinforcement learning environment. The function should take in the observation space and return a modified observation space based on certain criteria. The provided code snippet is a part of a class that is intended to be used as a wrapper for ...
magicoder
You are tasked with creating a Rust enum and a function to convert its variants to corresponding values from a foreign function interface (FFI) library. The FFI library provides constants for different modes, and the function should map the enum variants to these constants. Create a Rust enum `BitMode` with the follow...
magicoder
You are tasked with creating a Python class that simulates a simple blockchain-based ERC20 token transfer system. The class should include methods for initializing the token contract, transferring tokens between accounts, and retrieving token balances. Additionally, you need to implement a method for indexing ERC20 eve...
magicoder
You are tasked with implementing a face detection algorithm for a camera application. The application provides a method `stopGoogleFaceDetect()` that is responsible for stopping the face detection process. The method accesses the camera parameters and, if the camera supports face detection, it stops the face detection ...
magicoder
You are tasked with implementing a function that processes a list of error codes and their corresponding error messages. The function should take in a list of tuples, where each tuple contains an error code and its corresponding error message. Your goal is to create a dictionary that maps each error code to its respect...
magicoder
You are tasked with implementing a simple graphics module for a virtual display. The module is responsible for rendering pixels on a 64x32 virtual screen using SDL2 library. Your goal is to complete the implementation of the `Graphics` struct and its associated methods to enable drawing pixels on the screen. The `Grap...
magicoder
You are tasked with creating a Python program that sends email notifications using Django's email functionality. Your program should send an email with both plain text and HTML content to multiple recipients. Additionally, the program should handle potential errors related to the SMTP server connection. Your program s...
magicoder
You are tasked with implementing a custom data structure in C# that mimics the functionality of a stack but also keeps track of the minimum element in the stack at any given time. You need to create a class `MinStack` that supports the following operations: 1. `Push(int x)`: Add element `x` to the top of the stack. 2. ...
magicoder
You are tasked with implementing a function to calculate the nth term of the Lucas series using a recursive approach. The Lucas series is a sequence of numbers in which each term is the sum of the preceding two terms. The first two terms of the Lucas series are 2 and 1. Write a Python function `recur_luc(n)` that take...
magicoder
You are given an array of non-negative integers, where each element represents the maximum jump length at that position. You can assume that you are initially positioned at the first index. Write a function `jump` to determine the minimum number of jumps required to reach the last index. The function signature is: ```...
magicoder
You are tasked with implementing a class that generates documentation using string templates. The provided code snippet is a constructor for a `DocGenerator` class, which takes a `DocFileWriter` utility as a parameter and loads a string template file using `StringTemplateUtil`. Your task is to complete the implementati...
magicoder
You are tasked with implementing a ConcertsService class in TypeScript. The class should have the following methods: 1. `findOne(id: any): Promise<Concert>`: This method should take an ID as a parameter and return a Promise that resolves to a Concert object corresponding to the given ID. 2. `findAll(): Promise<Concer...
magicoder
You are tasked with implementing a function to verify an email verification token generated for a user. The token is created using a serializer with a secret key and an expiration time. The function should verify the token and return the user ID and email if the token is valid, or raise an exception if the token is exp...
magicoder
You are tasked with creating a Python program to manage a membership system for a club. The program should allow users to view and update member details, including gender and membership status. The default set of options for gender and membership status is provided in the `_default_options` dictionary as shown below: ...
magicoder
You are tasked with implementing a function that generates class names for a given component in a web application. The provided code snippet is a TypeScript function that creates a higher-order function for generating component class names. Your task is to create a TypeScript function that takes a component name and r...
magicoder
You are working on a project that involves interfacing with a C library from Python using the ctypes module. In this scenario, you have a C function called `_mu_B` that you need to call from Python. The function has been declared with a return type of `scalar`. Your task is to create a Python wrapper function using cty...
magicoder
You are tasked with implementing a dynamic time warping (DTW) algorithm to compare two time series data. DTW is a method used to measure the similarity between two sequences that may vary in time or speed. In this problem, you are required to write a Python function that calculates the DTW distance between two given ti...
magicoder
You are tasked with implementing a Python decorator that will allow you to dynamically register methods of a class and then execute them in a specific order. The decorator should be able to register methods and then execute them in the order they were defined within the class. Your task is to complete the implementat...
magicoder
You are tasked with implementing a configuration manager class in PHP. The configuration manager should allow for the storage and retrieval of configuration settings for a web application. The configuration settings should be stored in an associative array, with each setting identified by a unique key. Your task is to...
magicoder
You are tasked with creating a Python function that takes a string as input and returns the number of vowels (a, e, i, o, u) in the string. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be counted. Additionally, the input string may contain non-alphabetic characters, which ...
magicoder
You are tasked with creating a function that extracts the class names from a given Java package. The function should take the package name as input and return a list of class names present in that package. You can assume that the package contains only Java class files and no sub-packages. For example, given the packag...
magicoder
You are working on a project that involves updating the EXIF (Exchangeable Image File Format) metadata of image files. The EXIF metadata contains various fields such as description, location, date, and time, among others. Your task is to create a Python function that updates the description field of the EXIF metadata w...
magicoder
You are tasked with implementing a Python class that represents a 2D rectangular grid world as a Gym environment. The grid world consists of cells, each of which can be in one of three states: empty, occupied by an obstacle, or containing a goal. The environment should support the following functionalities: 1. Initiali...
magicoder
You are tasked with implementing a custom chart view in Swift that can display various types of chart points. Each chart point has a border color and a background color. Your goal is to create a method that will render these chart points on the chart view using Core Graphics. You are given a code snippet that shows pa...
magicoder
You are tasked with implementing a Python class for controlling a Fixed Focus Kirkpatrick-Baez Mirror. The mirror is part of the 1st gen Toyama designs with LCLS-II Beckhoff motion architecture. Your task is to create a class called `FFMirror` that inherits from `BaseInterface` and `GroupDevice`. The class should have ...
magicoder
You are working on a project that involves analyzing the layers and parameters of a machine learning model. You have a code snippet that processes the layers of a model and saves some basic information about the model to a JSON file. Your task is to write a Python function that takes the model layers information and ge...
magicoder
You are tasked with implementing a function that generates a list of indices for a given value in a list, excluding specific indices that are provided as exclusion criteria. Your task is to write a Python function `generate_indices` that takes in a list of values and a value to search for, along with a tuple of indices...
magicoder
You are tasked with implementing a custom `base_repr` function in Python's `numpy` namespace. The function should take a long integer `number` and convert it to a string representation in the specified `base`, with an optional `padding` parameter to ensure a minimum length of the output string. The function signature ...
magicoder
You are tasked with creating a Bash script that calculates the total memory consumption of a cache based on the given parameters. The script should take into account the value size, cache bytes, and block length, and output the total memory consumption in bytes. The script should use the following default values if th...
magicoder
You are tasked with implementing a custom data structure to store and manage tags associated with various items. The `Tags` struct should support adding, removing, and querying tags efficiently. You need to implement the `Tags` struct with the following methods: 1. `new()`: Creates a new instance of `Tags` with no ini...
magicoder
You are tasked with implementing a Rust trait and a struct to manage configuration data for a bridge program. The provided code snippet includes a partial definition of the `Pyth2WormholeConfig` struct and its implementation of the `Owned` trait. The `Pyth2WormholeConfig` struct has three public fields: `owner`, `wh_p...
magicoder
You are tasked with implementing a Python class for a sequential camera runner that captures images from multiple camera handlers. The class should allow for setting a wait duration and provide a method to retrieve a specified number of images from each camera handler. Your task is to complete the implementation of th...
magicoder
You are tasked with implementing a function that calculates the average of a list of numbers, excluding any outliers. An outlier is defined as a number that is either significantly larger or smaller than the rest of the numbers in the list. To identify outliers, you will use the concept of Z-score, which measures how m...
magicoder
You are tasked with implementing a simple error handling mechanism for a fictional entity management system. The system consists of entities with various attributes, and it needs to handle errors that may occur during the processing of these entities. Your task is to create a class that manages error handling for the e...
magicoder
You are working on a social media scraping tool that collects data from various original user accounts. The tool has a method `add_target` that adds a target user to the scraping database. The method takes three parameters: `username` (the target user's username), `source` (the source of the interaction), and `interact...
magicoder
You are tasked with creating a Python function that automates the process of building Docker images for a given directory. The function should take in the directory path and the image name as input and then execute the Docker build command using the subprocess module. Write a Python function called `build_docker_image...
magicoder
You are tasked with implementing a Python function that simulates a simple file system. The file system will consist of directories and files, and the function should be able to perform basic operations such as creating directories, creating files, listing the contents of a directory, and navigating through the file sy...
magicoder
You are working on a Django web application for managing user profiles. The code snippet provided is from a Django app's `apps.py` file, which is responsible for application configuration. The `name` variable holds the app's name, and the `verbose_name` variable holds a human-readable name for the app. Additionally, th...
magicoder
You are tasked with implementing a function that checks whether a given character is a valid start of an identifier according to the Unicode standard. In the provided code snippet, the function `UnicodeXID::is_xid_start(ch)` is used to determine the validity of the character `ch2` as the start of an identifier. The fun...
magicoder
You are tasked with implementing a function that performs k-fold cross-validation on a dataset. K-fold cross-validation is a technique used to assess the performance of a predictive model by partitioning the original dataset into k equal-sized subsamples. The following steps outline the process: 1. The original datase...
magicoder
You are tasked with creating a program that processes and analyzes GitHub repository information. The program will read in a series of lines, each containing a GitHub repository's details. Each line will consist of the following components separated by delimiters: - `<reponame>`: The name of the GitHub repository. - `e...
magicoder
You are tasked with creating a Python function that filters a list of packages based on certain criteria. The function should take in three parameters: a list of all available packages, a list of standard packages, and a list of packages to exclude. The function should filter out the standard packages and the excluded ...
magicoder
You are tasked with implementing a class for managing query parameters in a database application. The class, `QueryParams`, is responsible for constructing query parameters for database queries. One of the functionalities of this class is to set an end point for a query result. The `endAt` method is used to specify the...
magicoder
You are tasked with creating a utility function to parse and extract specific information from a given i18next configuration object. The i18next library is used for internationalization in JavaScript applications. The configuration object contains settings for i18next initialization, including the preload paths for lan...
magicoder
You are tasked with implementing a custom delta structure for a set variable in a constraint satisfaction problem solver. The delta structure is responsible for efficiently storing and managing the changes to the set variable's domain during search, allowing for effective backtracking and propagation. Your task is to ...
magicoder
You are tasked with simulating a simplified garbage collection system for managing temporary data structures in a distributed computing environment. The system consists of a `GarbageCollector` class with two methods: `stop` and `run`. The `run` method continuously checks a queue for temporary data structures to be garb...
magicoder
You are tasked with creating a program that processes a given source code file and identifies the lines that do not contain specific keywords. Your program should read the source code file and output the line numbers of the lines that do not contain any of the specified keywords. Write a function `find_lines_without_k...
magicoder
You are tasked with creating a Python function that retrieves memory information from a CUDA-enabled device. The function should handle different scenarios and provide the appropriate memory information based on the input parameters. Write a function `get_device_memory_info` that takes three parameters: - `cuda`: a bo...
magicoder
You are tasked with implementing a platform management system in Python. The system should support adding different platform types and retrieving the host platform based on the current operating system. You are provided with a partial code snippet that defines a function to add platform types to the system and another...
magicoder
You are tasked with designing a system to manage pet care services. The system should allow pet care providers to specify the types of pets they can care for and the types of care that are incompatible with their services. You need to implement the backend logic for managing compatible and incompatible pet care types. ...
magicoder
You are tasked with implementing a module resolution algorithm for a simple JavaScript module system. The system uses the `export` statement to make components available for import in other modules. When a module imports another module, the module resolution algorithm should determine the location of the imported modul...
magicoder
You are tasked with creating a Python web application using FastAPI. Your application should have two endpoints: one to retrieve a greeting message and another to manage notes. Create a FastAPI application with the following requirements: 1. Create a GET endpoint at `/api/hello` that returns a JSON response with a gre...
magicoder