instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with implementing a function to calculate the particle distribution function along the y-axis in a computational fluid dynamics simulation. The function `get_psi` takes three parameters: `s_bar`, `phi_b`, and `phi_w`. The `s_bar` parameter is a function of `y_bar` and `z`, while `phi_b` and `phi_w` are f...
magicoder
You are tasked with implementing a class that manages the navigation mode for a mobile application. The class, `NavigationModeController`, is responsible for handling changes in the navigation mode and transient states of the navigation bar. The provided code snippet shows part of the `NavigationModeController` class, ...
magicoder
You are tasked with creating a program to simulate a simple ATM (Automated Teller Machine) interface. The program should display a welcome message and a menu for the user to perform various banking operations. The menu should include options for checking balance, depositing money, withdrawing money, and exiting the pro...
magicoder
You are tasked with implementing a Python class that simulates a network configuration. The class should have the following properties: - `timeout`: a floating-point number representing the timeout value for network requests, with a default value of 10.0 seconds. - `is_https`: a boolean indicating whether the network ...
magicoder
You are tasked with implementing a class that simulates a simple notification system. The system should allow users to subscribe to different types of notifications and receive notifications when they are published. Each notification has a type and a message. Create a class `NotificationSystem` with the following meth...
magicoder
You are tasked with creating a Python function that reads a text file, removes any sensitive information, and writes the modified content back to the file. The function should take the filename as an argument and should remove any sensitive information such as credit card numbers, social security numbers, or any other ...
magicoder
You are given a string containing a series of parentheses. Your task is to write a function to determine if the parentheses are balanced. A string of parentheses is considered balanced if every opening parenthesis has a corresponding closing parenthesis and they are properly nested. Write a function `isBalancedParenth...
magicoder
You are tasked with implementing a function that processes HTTP request headers to modify the accepted encoding and content types. The function should take in the current state of the HTTP request headers and return the modified headers according to specific requirements. You are given a code snippet that sets up the ...
magicoder
You are tasked with implementing a Python generator function that yields a sequence of secret numbers based on a given rule. The rule for generating the sequence is as follows: - The first number in the sequence is 1. - Each subsequent number in the sequence is the sum of the previous number and the current index of th...
magicoder
You are tasked with implementing a custom error message class in Java that can be used to encapsulate error information from an OrderException. The class should have the ability to serialize the error code and error message into a JSON format using the Jackson library. Your task is to complete the implementation of th...
magicoder
You are tasked with creating a command-line interface (CLI) parser for a software tool. The CLI parser should be able to handle various command-line parameters and set corresponding environment variables based on the provided options. Your task is to implement a Python function `parse_params()` that parses the command-...
magicoder
You are tasked with creating a Swift package manager configuration for a new project called "AddressManager." The project has dependencies on three external packages: "JSON," "FluentMySQL," and "Vapor." Your goal is to write the necessary Swift Package Manager configuration code to specify the project's name, dependenc...
magicoder
You are tasked with implementing a data validation function that checks and updates a dictionary based on custom attributes and limits. The function takes in a custom attributes dictionary, a section, and a value to be validated. The custom attributes dictionary contains sections, each with keys and their corresponding...
magicoder
You are working on a project that involves encrypting and hiding a secret message within an image. Your task is to write a Python program that takes a plaintext message, encrypts it using the Advanced Encryption Standard (AES) algorithm in Cipher Block Chaining (CBC) mode, and then embeds the encrypted message into an ...
magicoder
You are tasked with creating a Java class that models a game character's decision-making process for playing mini-games. The character can be in different states, and based on its current state, it decides whether to play a mini-game or not. Your task is to implement the `getSituacao` method in the given class to retur...
magicoder
You are working on a web development project and need to automate the process of downloading a CSS file from a remote server. Your task is to write a Python script that accomplishes this using the `requests` library. Write a Python function `download_css_file(url, destination)` that takes in two parameters: - `url` (s...
magicoder
You are tasked with creating a function that takes a string representing an HTML document and checks if the opening and closing tags for the `<head>` and `<body>` elements are correctly paired. The function should return `true` if the tags are properly nested and balanced, and `false` otherwise. For the purpose of thi...
magicoder
You are tasked with creating a Python program to manage a database for a risk management system. The program should include functionality to create tables for different types of risks and their associated fields. You are provided with a code snippet that demonstrates the creation of tables for three entities: RiskTyp...
magicoder
You are tasked with creating a Python program to simulate a guessing game. The program should repeatedly prompt the user to input a guess until a specific input is provided. The program should keep track of the number of attempts made by the user and display the total number of failed attempts at the end. The program ...
magicoder
You are tasked with creating a Python class that manages channel aliases for different user types in a messaging system. The system has a predefined key, help category, and user controller. Your task is to create a class that inherits from the `AbstractChannelAdminCommand` and implements the necessary functionality for...
magicoder
You are tasked with implementing a simple dependency injection framework in Java. The framework should provide the ability to define beans and their dependencies, and then retrieve fully constructed beans from the application context. You are given the following code snippet as a starting point: ```java import com.my...
magicoder
You are tasked with implementing a custom assertion method for comparing two arrays of integers in Java. The method should compare the contents of the arrays and return true if they are equal, i.e., they have the same elements in the same order. You are not allowed to use any built-in Java libraries for array compariso...
magicoder
You are tasked with implementing a class to manage the state of devices in a network. The class, named `Device`, should have the following functionalities: 1. Initialize a device with a unique `id`, set its initial state to `OFFLINE`, and record the time it was last brought online. 2. Provide a method `offline()` to c...
magicoder
You are tasked with creating a program that processes an image using the OpenCV library in Python. The program should read an image provided by the user and perform a specific image processing operation on it. Your task is to implement a Python program that accomplishes the following: 1. Prompt the user to enter the f...
magicoder
You are tasked with creating a Rust library that interacts with Windows API functions to retrieve version information from a file. The provided code snippet includes external function declarations using the `extern_sys!` macro, which is used to define foreign function interfaces (FFI) for calling functions from externa...
magicoder
You are tasked with creating a program that processes and displays data using the RxDataSources library in Swift. RxDataSources is a library that provides a convenient way to display data in UITableView and UICollectionView using RxSwift. Your task is to create a Swift program that uses RxDataSources to display a list...
magicoder
You are tasked with creating a program that processes a video file and extracts frames from it. Your program should handle exceptions that may occur during the frame extraction process. You are given a code snippet that attempts to save a frame from the video using the OpenCV library, and it catches any exceptions that...
magicoder
You are tasked with creating a program that processes a series of step definitions for a test automation framework. Each step definition is represented by a string in the format "* adding step definition: {step}". Your task is to write a function that takes a list of step definition strings as input and returns a dicti...
magicoder
You are tasked with creating a Java class that manages country data using a database. The class should be able to retrieve, update, and delete country information from the database. You are provided with a code snippet that initializes a `CountryDataRepository` object using an `AppDatabase` instance. Your task is to im...
magicoder
You are tasked with implementing a custom data structure in Java that can store values of different types (String, Date, Number, Boolean, Link, None) and provide methods to manipulate and retrieve these values. Your task is to create a class `CustomDataStructure` with the following requirements: 1. The class should ha...
magicoder
You are working on a deep learning project and have been tasked with implementing a custom training loop using the PyTorch library. As part of this task, you need to create a function that saves model checkpoints and runs validation at the end of each epoch. The provided code snippet is a part of the training loop and ...
magicoder
You are tasked with implementing a function to process a list of integers and return two distinct parts of the list based on a specific criterion. Additionally, you need to verify the correctness of the two parts against expected values. You are given the following code snippet as a reference: ```python part_1, part_...
magicoder
You are given a Python file named `__init__.py` containing the following code snippet: ```python ''' @file: __init__.py.py @author: qxLiu @time: 2020/3/14 9:37 ''' ``` Your task is to write a Python function that extracts the file name, author, and timestamp from the given `__init__.py` file and returns them as a di...
magicoder
You are tasked with creating a password strength indicator based on the length and complexity of the password. The strength indicator should display a corresponding strength class and text based on the following criteria: - If the password length is less than 6 characters, the strength should be 'Weak'. - If the passwo...
magicoder
You are tasked with creating a program that processes a list of Java source files and extracts the author, date, and description information from the file headers. The file headers are in the form of comments at the beginning of each file, as shown in the code snippet below: ```java /** * @Author: John Doe * @Date: ...
magicoder
You are tasked with creating a Python class that handles the conversion of XMind files to XLS (Excel) format. Your class should include methods for identifying the file type, performing the conversion, and displaying a message if an incorrect file type is selected. Your class should have the following functionality: 1...
magicoder
You are tasked with creating a Python package for controlling smart bulbs. The package should be able to connect to a hub and control individual bulbs connected to it. Your task is to implement the necessary classes and methods to achieve this functionality. You are provided with a code snippet that imports the `Hub` ...
magicoder
You are tasked with creating a shell script that processes the `/etc/passwd` file to extract and manipulate user information. The script should perform the following steps: 1. Remove any lines starting with `#` from the `/etc/passwd` file. 2. Extract every other line from the remaining content. 3. Split each line using...
magicoder
You are tasked with creating a script to automate the process of checking and updating the version of CMake used in a development environment. Your script should ensure that the CMake version is above 3.13.4 and, if necessary, download and use the latest stable CMake version. Write a Bash script that accomplishes the ...
magicoder
You are tasked with creating a Python script that simulates a simplified version of a task scheduler for a distributed system. The script should utilize the `autoreload` module to automatically restart a Celery worker whenever a command is executed. The Celery worker is responsible for executing asynchronous tasks in t...
magicoder
You are working on a signal processing project and need to analyze EEG (electroencephalogram) data to extract features for classification. The given code snippet is a part of the feature extraction process from EEG data. The code initializes four arrays `F_dez`, `F_onze`, `F_doze`, and `F_treze` with zeros, representin...
magicoder
You are tasked with implementing a DateRangeOptions class in TypeScript. The class should have a getter and a setter for managing date range options. The getter should return the current date range options, and the setter should update the date range options based on the provided input while merging it with the default...
magicoder
You are tasked with implementing a custom neural network layer in Python. The layer, named `CustomLayer`, should perform a series of operations on the input data `x` based on a given sequence of sub-modules and an optional batch normalization step. The operations to be performed are as follows: 1. Iterate through the s...
magicoder
You are tasked with creating a program that processes a given SQL query and extracts the table name from the query. The SQL query will be provided as a string, and it may contain various SQL commands and formatting. Your program should be able to identify the table name specified in the "FROM" clause of the query. Wri...
magicoder
You are given a list of strings representing the names of various animals. Your task is to write a function that takes this list as input and returns a new list containing only those animal names that end with the letter 'h'. For example, given the input list: ``` ['tiger', 'lion', 'elephant', 'cheetah', 'tundrah', 'g...
magicoder
You are tasked with creating a Python function that validates the version number of a software. The version number is represented as a string in the format "x.y" where x and y are non-negative integers. The function should return True if the version number is valid according to the specified format, and False otherwise...
magicoder
You are tasked with implementing a Python class that represents a simple bank account. The class should have the following functionalities: 1. Initialize the account with an initial balance. 2. Deposit funds into the account. 3. Withdraw funds from the account. 4. Check the current balance of the account. You need to ...
magicoder
You are working on a Python application that interacts with a RESTful API to retrieve information about available services. The code snippet provided is a part of a class that handles these API requests. The `get_services` method is responsible for making a GET request to retrieve a list of services from a specified ho...
magicoder
You are working on a web application that involves interacting with a Designer Repository through a service called `DesignerRepositoryActionsServiceStatic`. This service provides a method called `GetDownloadObjectContextId` which is used to retrieve an object context ID for downloading a specific object from the reposi...
magicoder
You are given a Python code snippet that includes a decorator `@print_calls` and two functions `part2` and `load`. The `part2` function takes a graph as input and returns the shortest path length between nodes "YOU" and "SAN" in the graph, after converting the graph to an undirected graph and subtracting 2 from the res...
magicoder
You are tasked with implementing a parser for a custom language that uses a specific syntax for defining key-value pairs. The language allows for defining multiple key-value pairs within a single string, with each pair separated by commas. The keys can have optional values, which are enclosed in square brackets and sep...
magicoder
You are tasked with creating a Python class that can scrape movie information from a website. Your class should have a method `scrape_movie` that takes in the movie title, release year, and any additional parameters, and returns the relevant information about the movie. Your task is to implement the `Vumoo` class with...
magicoder
You are tasked with implementing a WeatherConstants class that stores and manages weather-related constants for a travel application. The class should provide a set of predefined constants for different weather conditions and their corresponding values. The WeatherConstants class should have the following requirements...
magicoder
You are tasked with implementing a simple text-based adventure game in Python. The game will involve navigating through different rooms, encountering obstacles, and making decisions that affect the outcome of the game. Your task is to create a class called `Room` that represents a room in the game. Each room should ha...
magicoder
You are tasked with implementing a simplified version of an Interrupt Descriptor Table (IDT) in C++. An Interrupt Descriptor Table is a data structure used by the x86 architecture to define the interrupt and exception handlers. The given code snippet provides a partial implementation of the IDT using macros and a class...
magicoder
You are tasked with creating a program that generates stub code for Swift protocols. The program should take a protocol with long names as input and produce a stub code for the protocol. The stub code should include a function declaration with appropriate argument types and names. Your task is to implement a function ...
magicoder
You are tasked with implementing a state machine that processes a sequence of input elements and maintains a set of states based on the input. Each state transition is determined by the current state and the input element. Your goal is to implement the `add_state` method, which adds a new state to the state machine bas...
magicoder
You are tasked with implementing a function that validates the correctness of a given list of filters for a specific path in a web application. The function should take the path and the list of filters as input and return a boolean value indicating whether the filters are valid for the given path. The filters for a pa...
magicoder
You are tasked with creating a testing utility for a JavaScript project. Your goal is to implement a function that compares the output of a piece of code with a previously saved "snapshot" of the expected output. This is a common technique used in testing frameworks to ensure that the output of a piece of code remains ...
magicoder
You are tasked with implementing a function to convert tile coordinates to upper-left latitude and longitude coordinates on a map. The given code snippet contains a function `tile2upper_left_coordinate(z, x, y)` that takes in three parameters: `z` (zoom level), `x` (tile x-coordinate), and `y` (tile y-coordinate). The ...
magicoder
You are tasked with implementing a function that processes a list of integers and returns the sum of all the even numbers in the list. However, there is a catch - you are only allowed to use a specific set of characters to write the function. The characters you can use are: `(`, `)`, `{`, `}`, `[`, `]`, `<`, `>`, `+`, ...
magicoder
You are tasked with implementing a reinforcement learning algorithm using the Keras-RL library. The code snippet provided shows the training and testing phases of the algorithm. After training and testing, the results need to be visualized using TensorBoard. Your task is to write a function that takes care of this visu...
magicoder
You are tasked with creating a middleware function for a web server that logs the timestamp, HTTP method, and path of incoming requests. The middleware function should be implemented in Node.js using Koa, a web framework for Node.js. Your task is to complete the middleware function to log the required information for e...
magicoder
You are tasked with creating a validation method for a department title in a software system. The validation method should ensure that the department title does not exceed a certain length. You are provided with a code snippet from a unit test that checks if the validation fails when the department title is too long. Y...
magicoder
You are tasked with implementing a simplified version of a pipeline execution system using Java. The pipeline consists of a series of data processing operations that need to be executed in a specific order. Your goal is to create a class that can traverse the pipeline topologically and execute the processing operations...
magicoder
You are given a code snippet for a function `smallestRepunitDivByK` that takes an integer `K` as input. The function is intended to find the length of the smallest positive integer `N` such that `N` is a multiple of `K`, and `N` consists only of the digit 1 repeated one or more times. Your task is to complete the impl...
magicoder
You are tasked with creating a Python program that generates random samples from either a normal distribution or a uniform distribution and saves the samples to a file. The program should accept command-line arguments to customize the number of samples, the output filename, the input dimension, and the distribution typ...
magicoder
You are tasked with creating a simple implementation of the MediatR library in C#. MediatR is a popular open-source library that allows developers to implement the mediator pattern in their applications. The mediator pattern promotes loose coupling between components by ensuring that components do not explicitly commun...
magicoder
You are tasked with creating a simple ROS (Robot Operating System) service that adds two integers and returns the result. The provided code snippet is a part of a Python script that sets up and runs the ROS service for adding two integers. Your task is to complete the Python script by implementing the `setup` function...
magicoder
You are tasked with implementing a simple class that represents a bank account. The class should have methods to deposit funds, withdraw funds, and check the current balance. Additionally, the class should have a private method to calculate the interest on the account balance. The interest calculation method should onl...
magicoder
You are tasked with implementing a cached property decorator in Python. A cached property is a property that is computed once and then stored, so that subsequent accesses return the cached value without recomputation. Your task is to create a `cached_property` decorator that can be used to define cached properties in P...
magicoder
You are tasked with implementing a custom data structure to store question-answer pairs for a quiz application. The data structure should support adding, removing, and retrieving question-answer pairs, as well as providing the ability to check if a question exists in the structure. You need to implement a class `QAObj...
magicoder
You are tasked with implementing a Python function that processes a list of Boolean equations. The function should handle both single and multiple Boolean equations and provide the option to display verbose output. You are given the following code snippet as a starting point: ```python else: if verbose: ...
magicoder
You are given a Python function that takes in three integer parameters `a`, `b`, and `c`. The function is intended to solve a quadratic equation of the form `ax^2 + bx + c = 0`. However, the code snippet provided is incomplete and needs to be filled in to correctly handle the different cases of the quadratic equation's...
magicoder
You are tasked with creating a Bash script that processes a given directory and its subdirectories to find all files with a specific file extension. Your script should then calculate the total size of all these files and print the result in a human-readable format. Your Bash script should accept two command-line argum...
magicoder
You are tasked with creating a Python function that simulates a simplified version of a user authentication process for a web application. The function should take in a code and state as input parameters, make a GET request to a mock authentication endpoint, and then validate the response to ensure that the user is red...
magicoder
You are tasked with creating a Python program that processes an image and extracts the red, green, and blue color components. Your program should then display each color component in a separate window using the OpenCV library. Additionally, you need to print the red color component to the console. Your program should ...
magicoder
You are tasked with implementing a booking system for a hotel. The system should allow users to make reservations for specific time slots. Each reservation should have a unique identifier, a start time, and a finish time. The reservations should be ordered by their start time in descending order. Additionally, the syst...
magicoder
You are tasked with creating a Python program that interacts with Near Field Communication (NFC) tags. The program should utilize the `nfc` library to read and process NDEF (NFC Data Exchange Format) messages from NFC tags. The NDEF message format is a standard for defining how data is stored within an NFC tag. Your pr...
magicoder
You are tasked with creating a Python script to automate the configuration of screenshot settings on a macOS system. The script should utilize the `subprocess` module to execute the necessary terminal commands for changing the default screenshot settings. Your script should perform the following tasks: 1. Set the defa...
magicoder
You are tasked with implementing a function that determines the source label of a product based on a given input. The function should take a product source label as input and return the corresponding source label based on predefined sets of analytical and production sources. You are given the following code snippet as...
magicoder
You are tasked with creating a Python 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. If the user inputs an invalid choice, the progra...
magicoder
You are tasked with implementing a parameter generator class in C++. The generator is responsible for producing a list of parameters based on certain input criteria. Your goal is to create a method to parse the output of the parameter generator and perform a sanity check to ensure that at least one parameter has been g...
magicoder
You are tasked with implementing a Python class that can convert its attributes to a dictionary format. The class should handle nested objects and lists of objects, converting them to dictionaries as well. Your task is to complete the implementation of the `to_dict` method in the given Python class. ```python class Ex...
magicoder
You are given a code snippet from a Python script that appears to be part of a parser implementation. The code snippet contains some errors and inconsistencies. Your task is to analyze the code and identify the issues, then propose the correct code to fix the problems. Given the code snippet: ``` print str(nod...
magicoder
You are tasked with creating a script to automate the setup process for a developer's environment. The script should perform the following tasks: 1. Create a directory named "projects" in the user's home directory. 2. Clone repositories from GitHub using a script located in the "projects" directory. 3. Remove the exis...
magicoder
You are tasked with creating a Python function that captures a screenshot of a selected area of the screen using the `maim` command-line tool and saves it to a file with a timestamp in the filename. Your function should take no input and return the filename of the saved screenshot. The code snippet provided demonstrat...
magicoder
You are tasked with implementing a program to perform K-means clustering on a dataset using the scikit-learn library in Python. The dataset used for this problem is the famous Iris dataset, which contains samples of iris flowers, each described by four features: sepal length, sepal width, petal length, and petal width....
magicoder
You are given a code snippet that attempts to find a Pythagorean triplet (a, b, c) where a < b < c and a^2 + b^2 = c^2. The code snippet uses nested loops to search for such a triplet within certain constraints. Your task is to implement a function that efficiently finds the product of the Pythagorean triplet (a, b, c)...
magicoder
You are working on a machine learning library called `simple_ml` that provides various algorithms for classification, regression, and dimensionality reduction. The code snippet provided includes imports for different modules within the `simple_ml` library. Your task is to create a function that dynamically loads and ex...
magicoder
You are tasked with creating a simple authentication middleware for an Apollo GraphQL server. The middleware should intercept incoming requests, check for a valid authentication token, and attach the authenticated user's information to the request context before passing it to the resolver functions. The provided code ...
magicoder
You are tasked with implementing a simple reinforcement learning environment for a two-dimensional grid world. The grid world consists of cells, each of which can be either empty or occupied by an obstacle. An agent can move in four directions: up, down, left, and right. The agent receives a reward of +10 when it reach...
magicoder
You are tasked with implementing a method to retrieve an adapter for working with a program tree fragment database table. The method takes in a database handle, an open mode, and a tree ID, and returns the corresponding fragment table adapter. The database handle's version must match the expected version, and any issue...
magicoder
You are given a Python class representing a cluster of nodes. The class has three methods: `getStandbyNodes`, `getNodeState`, and `existsPendingNode`. The `getStandbyNodes` method iterates through the nodes in the cluster and returns a list of node IDs for nodes in standby state. The `getNodeState` method takes a node ...
magicoder
You are tasked with implementing a function that extracts a specific group from an application object. The application object can be null, and the function should handle this case appropriately. The application object has the following structure: ```typescript interface Application { id: number; name: string; gr...
magicoder
You are tasked with creating a Python program to automate the process of extracting data from an Excel spreadsheet and performing specific operations on it. The program should read data from a given Excel file, manipulate the data according to certain criteria, and then write the modified data back to a new Excel file....
magicoder
You are tasked with implementing a Python class method that processes JSON data and updates a dictionary based on certain conditions. The class has a list of secondary indexes, and the method should update the dictionary with values from the JSON object if they are not empty or None. Additionally, if a sort key is prov...
magicoder
You are tasked with implementing a Python function that parses a string and extracts a specific substring based on a predefined pattern. The function should return the extracted substring. Write a function `extract_substring` that takes no parameters. Inside the function, there is a call to a method `get_hoge()` of an...
magicoder
You are tasked with creating a Python script to organize and process log data from Wikimedia Foundation's Wikidata Query Service (WDQS). The provided code snippet is a part of the script and is responsible for setting up the necessary directories for storing the log data. Your task is to complete the Python script by ...
magicoder
You are tasked with implementing a key deletion action for a curve editor. The curve editor manages a set of keys, each with a position and value. The provided code snippet is part of the implementation for the "remove keys" action in the curve editor. Your task is to complete the implementation of the `CurveDeleteKeys...
magicoder