instruction_seed
stringlengths
29
40.5k
source
stringclasses
6 values
You are tasked with implementing a simple expression parser for a programming language. The parser needs to handle unary operators with different precedence levels. The unary operators are categorized into three kinds: `Check`, `Unwrap`, and `Deref` with `Prefix::L` precedence, and `Not`, `Neg`, `BitNot`, `Member`, and...
magicoder
You are tasked with implementing a function to sample noise for the parameters of a machine learning model. The given code snippet is part of a larger class that initializes a model and then samples noise for its parameters. Your task is to complete the `sample_noise` function to generate noise for each parameter of th...
magicoder
You are tasked with implementing a function that checks if a given string contains any repeated characters. The function should return `True` if the string contains any repeated characters and `False` otherwise. You are not allowed to use any built-in functions or data structures to solve this problem. Function signat...
magicoder
You are tasked with implementing a Python function that parses a given configuration dictionary and returns a list of all the unique keys present in the dictionary. The configuration dictionary may contain nested dictionaries, and the keys can be of any hashable type. You need to implement the following function: ```...
magicoder
You are tasked with implementing a function to process a list of account keys and extract relevant information based on a given network ID. Each account key is a string that consists of multiple parts separated by colons. The last part of the key represents the network ID. Your task is to create a function that takes a...
magicoder
You are tasked with creating a Python unit test for a Django web application. The application has two news items, `item_a` and `item_b`, each belonging to a different site, `site_a` and `site_b`. The test is to ensure that when a user accesses the URL of `item_a` and `item_b`, the correct news item is displayed in the ...
magicoder
You are tasked with implementing a simple dictionary class in Python that supports adding, updating, and retrieving key-value pairs. The dictionary should also support marking certain key-value pairs as deprecated, which means they can still be accessed but should be considered outdated. Your task is to implement the ...
magicoder
You are working on a medical imaging project that involves preprocessing CT scans. You need to implement a class that handles the preprocessing of CT scans by clipping values, applying masks, and gathering statistics for foreground classes. You are given a partial code snippet for the class constructor: ```python cla...
magicoder
You are given a text file containing lines of data representing the velocities of objects in a 2D space. Each line consists of a string of characters, and the velocities are encoded within specific positions of the string. The velocities are represented as 12-character substrings, with the first 11 characters represent...
magicoder
You are working as a DevOps engineer for a software company that uses Docker for containerization. Your team is responsible for managing the Docker images used in the development and deployment processes. You have been tasked with creating a script to automate the process of building and managing Docker images. Your t...
magicoder
You are tasked with implementing a function that processes and manipulates bitmap images. The function takes in an input bitmap and a scaling factor, and it should return a new scaled bitmap. However, there is a bug in the provided code snippet that needs to be identified and fixed. The code snippet provided is a part...
magicoder
You are tasked with implementing a function that calculates the visual rectangle of a layout box model object in a web rendering engine. The function takes an ancestor layout box model object, a reference to a physical rectangle, map coordinates flags, and visual rectangle flags as input parameters. Your goal is to wri...
magicoder
You are working on a web scraping and data augmentation tool that fetches data from various web pages and augments a given item with the extracted information. The tool has a `fetch_page_data` method that fetches data from a web page and updates the provided page object with the fetched data. Additionally, there is an ...
magicoder
You are tasked with creating a Python function that parses the information from a `setup` function call in a `setup.py` file and returns a dictionary containing the relevant details. The `setup` function is used in Python packaging to describe the distribution and its metadata. You need to implement a function `parse_...
magicoder
You are tasked with creating a Python function that extracts the version number from a given Python package's `__init__.py` file. The version number is stored as a string within the file and is denoted by the `__version__` variable. The version number is enclosed within single or double quotes and is the only content o...
magicoder
You are tasked with implementing a resolver function for a routing system in an Angular application. The resolver function is responsible for fetching data before the route is activated. Your task is to complete the implementation of the resolver function to fetch user data based on the user ID provided in the route pa...
magicoder
You are tasked with creating a subclass of the `Title` class provided in the code snippet. Your subclass, named `CustomTitle`, should have additional functionality to handle a specific type of content. The `CustomTitle` class should have a method `setContent` that takes a string as input and sets the content of the tit...
magicoder
You are tasked with implementing a simplified version of a timer class in C++. The provided code snippet is a part of the Timer class, which has a method `hasTicked()` that checks if the timer has expired based on the difference between the current time and the next tick time. Your task is to complete the implementati...
magicoder
You are tasked with creating a Python class that handles the parsing of genomic data from a file. The class should be able to read both plain text and gzipped files, and store the genomic data in a dictionary format for easy access. Your task is to implement the `GenomeParser` class with the following requirements: - ...
magicoder
You are tasked with implementing a function that processes a given style object and returns a new object containing only the properties that have numerical values. The style object is represented as a JavaScript object, where each key represents a CSS property and its value represents the corresponding style value. The...
magicoder
You are given a code snippet that reads text from a file, processes it, and stores the result in an array. Your task is to understand the code and identify the specific processing steps applied to the input text. Your task is to write a function that replicates the processing logic described in the code snippet. The f...
magicoder
You are given a list of strings, each representing a combination of a letter and a number. The letter represents a city code, and the number represents the population of that city. Your task is to write a function that sorts the list of city codes based on their population in ascending order. If two cities have the sam...
magicoder
You are tasked with creating a form validation system for a web application. The form consists of two fields: an email field and a password field. The email field must be non-empty and the password field must be at least 5 characters long and non-empty. Additionally, the email field should be pre-populated with a value...
magicoder
You are tasked with creating a script to automate the configuration of an OAuth2 proxy for a web application. The script should read a template configuration file, replace placeholder variables with actual values, and then start the web application using a process manager. The template configuration file, `oauth2_prox...
magicoder
You are tasked with creating a Python function that determines the size of a given file in bytes and returns the size in a human-readable format. The function should take the file path as an argument and return a string representing the file size in a human-readable format (e.g., "10.5 MB", "1.2 GB", "500 bytes"). You...
magicoder
You are tasked with implementing a Python function that processes historical terminology data and saves it as a JSON file. The function should take a list of historical terminology as input, create a dictionary of historical periods, and then save this dictionary as a JSON file. You are also required to write a testing...
magicoder
You are tasked with implementing a custom Android view that combines a text view and an image view. The view should display a text string and an image side by side. Your task is to create a custom view class that extends the Android `View` class and includes the necessary logic to set the text and image for display. Y...
magicoder
You are tasked with implementing a module system for a front-end web application. The application uses a tooltip component to display information when users hover over certain elements. The tooltip component is composed of several sub-components, each responsible for a specific part of the tooltip's content. The code s...
magicoder
You are tasked with creating a Python function that extracts the filename and file extension from a given file path. The file path will be provided as a string, and the function should return the filename and file extension as separate strings. If the file path does not contain an extension, the function should return ...
magicoder
You are tasked with creating a Python program that generates a mapping of glyph names to their corresponding Unicode code points from a given font file. The font file is represented as a list of dictionaries, where each dictionary contains information about a specific font. The program should extract the glyph names an...
magicoder
You are tasked with creating a script to organize and archive files based on their types and creation timestamp. Your script should take files with the extensions ".py" and ".sh" from the current directory and move them into a newly created directory named "tempFiles" followed by the current timestamp in seconds. For e...
magicoder
You are tasked with implementing a function that processes a list of transactions based on a given mode. The transactions are represented as a list of dictionaries, where each dictionary contains information about a single transaction. The mode can be one of the following: "Update", "Delete", or "Insert". If the mode i...
magicoder
You are tasked with implementing a function that calculates the time difference between two given timestamps. The timestamps are represented as integers, where each integer denotes the time in seconds. Your task is to write a function `calculateTimeDifference` that takes two integer parameters `timeStart` and `timeEnd`...
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 as values. You should also handle any potential errors that may occur during the processing of the URLs. Your function should have the following signat...
magicoder
You are tasked with implementing a custom QuerySet class for a Salesforce backend in a Django application. The provided code snippet includes an import statement and the beginning of a custom QuerySet class. Your task is to complete the implementation of the `SalesforceQuerySet` class by adding necessary methods and at...
magicoder
You are tasked with creating a command-line tool that simulates the behavior of Node Version Manager (NVM) for managing different versions of Node.js. Your tool should support the following commands: 1. `nvm install <version>`: This command installs the specified version of Node.js. 2. `nvm exec <version> <script>`: T...
magicoder
You are tasked with implementing a network communication protocol for a software application. The application needs to send a version message to a remote server. Your task is to write a function that takes the version information and constructs the version message to be sent over the network. You are provided with a P...
magicoder
You are tasked with implementing a custom method for the `UIViewController` class in Swift. The method should allow the user to present an alert with a specified title, message, and a completion handler. You are not allowed to use any third-party libraries or frameworks for this implementation. Your task is to complet...
magicoder
You are tasked with creating a Python program to generate and push fake employee data into a database. The program should utilize the `faker` library to create realistic fake names and job titles for the employees. The generated data should then be inserted into a database table using Python's `sqlite3` module. Your p...
magicoder
You are tasked with creating a program to process XML data representing information about buckets in a cloud storage system. The XML data contains details about various buckets, and your program needs to parse this data and store it in a structured format for further processing. The XML data has the following structur...
magicoder
You are tasked with designing a class for managing bookings and tutors for a tutoring center. The class should have the following functionalities: 1. Store bookings for tutorials and pools in separate dictionaries, where the keys are the day index and the hour, and the values are lists of room names. 2. Maintain a lis...
magicoder
You are tasked with creating a Python function that simulates a social media bot's behavior. The bot is programmed to follow pages on the social media platform. However, due to occasional errors or restrictions, the bot may not always successfully follow a page. Your task is to implement a function that encapsulates th...
magicoder
You are tasked with implementing a function that processes a Gherkin document, which is used in behavior-driven development (BDD) to describe the behavior of software in a human-readable format. The Gherkin document is represented by the `gherkinDocument` variable, which is an instance of the `IGherkinDocument` interfa...
magicoder
You are tasked with creating a simple iOS app that displays a list of menu items with corresponding images. The app should use a table view to display the menu items and their images. The menu items and images are provided in a JSON file. Your task is to implement the necessary code to parse the JSON file, populate the...
magicoder
You are given a set of items, each with a value and a weight. Your task is to maximize the total value of items that can be carried in a knapsack with a maximum capacity for both value and weight. You need to implement a dynamic programming solution to solve this problem. You are given the following variables and arra...
magicoder
You are working on a simulation program for particle physics experiments. The code snippet provided is a part of a function that calculates the position of a particle at a certain point in time. The function takes in the initial position and velocity of the particle, as well as the time and the angles of its trajectory...
magicoder
You are tasked with processing a JSON file containing information about a knowledge graph. The file contains an array of objects, each representing a node in the knowledge graph. Each node object has several attributes, including an 'id' field. Your goal is to write a Python program that reads the JSON file, iterates t...
magicoder
You are tasked with implementing a class that represents a simple grid layout system for a graphical user interface (GUI) application. The grid layout should support adding and positioning widgets within a grid structure. Each widget can have a specified size and appearance properties. Your task is to create a Python ...
magicoder
You are given a graph represented as an adjacency list. Your task is to implement a method to show the graph visually using a graph visualization library. The graph visualization library provides a `show()` method to display the graph. You need to write a Python function `visualize_graph(graph)` that takes the graph a...
magicoder
You are tasked with implementing a custom map data structure in Rust. The map should support key-value pairs, where the keys are integers and the values are floating-point numbers. Additionally, the map should allow for duplicate keys, with the values associated with the same key being stored in a vector. Your task is...
magicoder
You are tasked with implementing a token validation system for a user authentication module. The provided code snippet is a part of a Django REST framework serializer class method used to validate and process user authentication tokens. The `validate` method is responsible for validating the input attributes and adding...
magicoder
You are tasked with implementing a simplified version of the Cryptonight hash function, which is commonly used in cryptocurrencies like Monero. The Cryptonight hash function takes a block of data and produces a hash value. The provided code snippet is a part of the implementation of this hash function. Your task is to ...
magicoder
You are tasked with implementing a pagination feature for a web application that retrieves data from a database using Laravel's Eloquent ORM. The code snippet provided is a part of a method in a Laravel controller that retrieves a paginated list of items from the database. Your task is to complete the implementation of...
magicoder
You are working on a Flutter application that utilizes the `kraken_webview` package to display web content. As part of the integration process, you need to register the necessary plugins with the FlutterPluginRegistry. The code snippet provided demonstrates the registration of two plugins, `ConnectivityPlugin` and `Kra...
magicoder
You are working on a facial recognition system using the OpenCV library in Python. You have decided to use the LBPH (Local Binary Patterns Histograms) algorithm for face recognition. However, you want to provide flexibility for users to choose between different face recognition algorithms such as EigenFaceRecognizer an...
magicoder
You are given a code snippet that is part of a larger function. Your task is to complete the function by implementing the missing logic. The function takes in an array of integers and should return true if the array is sorted in non-decreasing order, and false otherwise. You need to write the missing logic to achieve t...
magicoder
You are tasked with implementing a function to calculate the area of a 2D polygon given its vertices and colors. The function should take in the vertices of the polygon, their corresponding colors, and return the total area of the polygon. The vertices are represented as (x, y) coordinates, and the colors are represent...
magicoder
You are tasked with implementing a function to parse an integer from a given C-style string. The function should ignore any leading whitespace characters and then parse the integer value until a non-digit character is encountered. If the string does not contain a valid integer, the function should return 0. You are pr...
magicoder
You are tasked with implementing a function to count the number of successful nodes in a tree-like data structure. Each node in the tree has a `success` property indicating whether it was successful or not, and may have children nodes in an array. You are given a sample tree structure represented as a JavaScript objec...
magicoder
You are tasked with creating a Python class that processes and manipulates widget objects for a graphical user interface (GUI). The class should have methods for adding different types of widgets, such as Dropdown and Text, and for setting their properties. Your task is to implement the `GUIManager` class with the foll...
magicoder
You are working on a user authentication system for a web application. The system uses an object-oriented approach, and you are tasked with implementing a method to set and save a user's password. The code snippet below demonstrates the usage of the `password` method and the `save` method on an object `$x` to set and s...
magicoder
You are working as a software developer for a company that is using a Python-based database migration tool called Alembic. Your task is to create a migration script that adds two new columns to a table in the database. The provided code snippet is a part of the migration script and contains placeholders for the passwor...
magicoder
You are tasked with creating a program that calculates the distance between two points in a 2D plane. The program should prompt the user to input the coordinates of two points and then calculate the distance between them using the Euclidean distance formula. The Euclidean distance between two points (x1, y1) and (x2, y...
magicoder
You are tasked with creating a Python program to calculate the average distance traveled by a group of people. The program should take input for the number of people and the distance traveled by each person, and then calculate the average distance traveled. You are provided with the following code snippet as a startin...
magicoder
You are tasked with creating a script to automate the packaging and distribution of software components. The script should perform the following tasks for two different software components: Systems-Unit-Tests and Systems-Query-Debugger. 1. For Systems-Unit-Tests: - Remove the Intermediate and Documentation director...
magicoder
You are tasked with creating a Python program to automate the process of sending emails using the `smtplib` library. Your program should prompt the user to input their email credentials, recipient's email address, and the content of the email. The program should then send the email using the provided credentials and co...
magicoder
You are tasked with implementing a Python function that downloads, extracts, and validates a dataset file. The function should handle the creation of a subfolder for the dataset, downloading the file from a given URL, extracting the file if necessary, and validating the file using its MD5 hash. The function should log ...
magicoder
You are working on a data pipeline using Apache Airflow, a platform to programmatically author, schedule, and monitor workflows. In this scenario, you are tasked with creating a new task in the existing workflow. The task involves executing a Bash command to print a specific message to the console. Given the code snip...
magicoder
You are tasked with implementing a function that calculates the intersection of two sets represented as dictionaries in Python. The keys of the dictionaries represent elements of the sets, and the values indicate whether the element is present in the set. If the value is "Yes", the element is present in the set; otherw...
magicoder
You are tasked with creating a simple web application that displays a list of products. The application should retrieve product data from a JSON file and render it on a web page using HTML and JavaScript. Your task is to write the JavaScript code that fetches the product data from the JSON file and dynamically generate...
magicoder
You are tasked with creating a program that simulates a simple card game called "War." In this game, two players are each dealt half of a standard deck of 52 playing cards. The players then reveal the top card from their respective decks, and the player with the higher card wins both cards, placing them at the bottom o...
magicoder
You are tasked with implementing a simplified version of a backend configuration system. The system consists of a `Backend` class with two methods: `configure` and `build`. The `configure` method takes a string parameter representing the configuration settings, and the `build` method is responsible for building the bac...
magicoder
You are tasked with implementing a message tracking system for a server application. The given code snippet is a part of this system and is responsible for updating the count of sent messages for a specific client connection. The code snippet is written in C++ and is a part of a larger server application. It is assume...
magicoder
You are tasked with implementing a Python function that calculates the average of a list of numbers. However, the catch is that you are not allowed to use any built-in Python functions or libraries for mathematical operations. You must implement the average calculation from scratch using only basic arithmetic operation...
magicoder
You are tasked with creating a program that processes an audio file and splits it into multiple segments based on periods of silence. Your program should use the `ffmpeg` command-line tool to achieve this. Your program should take an audio file as input and use the `silencedetect` filter in `ffmpeg` to detect periods ...
magicoder
You are tasked with implementing a function to parse a response from an API call and extract the application authentication token. The response is in the form of a dictionary, and the authentication token is stored under the key "application_auth_token". Your function should handle cases where the key may not exist in ...
magicoder
You are tasked with implementing a TypeScript type definition for a floating navigation menu style props and class keys. The provided code snippet outlines the initial structure for the type definition. Your goal is to complete the type definition by incorporating the necessary properties and ensuring type safety. Com...
magicoder
You are tasked with creating a Python script to interact with a messaging service using the TAT (Text and Annotation Tool) API. The TAT API requires authentication credentials and allows users to retrieve a list of messages from a specified topic. Your script should retrieve the latest 5 messages from the specified top...
magicoder
You are tasked with implementing a function to prepare a log record header in a logging system. The function `prepare_lrh` takes in five parameters: `csn` (commit sequence number), `checkpoint_csn` (checkpoint commit sequence number), `tsn` (transaction sequence number), and `rec_type` (record type). The function is re...
magicoder
You are tasked with implementing a function that processes image data and returns relevant information. The function takes in a URL and a checksum, and then logs a message indicating that the image has been resolved. If a checksum is provided, the function returns the URL, checksum, and the string 'md5'. If no checksum...
magicoder
You are tasked with creating a custom facade in a Laravel application to provide a simplified interface to a complex functionality. In Laravel, facades serve as "static proxies" to underlying classes in the service container, allowing for a more expressive and readable syntax when interacting with the underlying class....
magicoder
You are tasked with implementing a scheduling system for a smart home automation application. The system allows users to create and edit schedule rules for controlling various devices. Each schedule rule consists of specific settings, such as activation time, dimmer level, and associated device. The provided code snipp...
magicoder
You are tasked with creating a Python script to automate the dehazing process for a collection of images using a given model. The script should take a folder containing hazy images and a specific dehazing model as input, and then apply the model to each image to generate dehazed versions. The script should be designed ...
magicoder
You are working on a Python application that interacts with a Model Packaging API. The provided code snippet is part of a class that handles interactions with the Model Packaging API. The class contains three methods: `packaging_get`, `packaging_get_id`, and `packaging_put`. The `packaging_get` method retrieves all mod...
magicoder
You are tasked with implementing a simple component manager for a game development framework. The component manager is responsible for managing different types of components that can be attached to game entities. Each component has a unique identifier and can be added to or removed from entities. Your task is to imple...
magicoder
You are tasked with implementing a class method for a geographical zones service. The method should retrieve specific information about zones based on the provided parameters. The code snippet provided is a part of the class, and you need to complete the implementation of the `get_zones_australia` method. The `get_zon...
magicoder
You are working on a script to automate the process of creating a backup of a navigation system's data. The script prompts the user for confirmation before proceeding with the backup. If the user enters "Y" as the response, the script creates a directory for the backup, navigates to that directory, and then runs a comm...
magicoder
You are tasked with creating a TypeScript class that interacts with an Elasticsearch client to manage indices. Your goal is to implement the `checkIndexOrCreate` method, which checks for the existence of specific indices and creates them if they do not exist. The `Client` class is already provided, and it has a method...
magicoder
You are tasked with implementing a generic data structure in Rust that represents a binary tree and provides various operations for manipulating the tree. The binary tree should support the following operations: creating an empty tree, inserting a new element, checking if a specific element is present, and traversing t...
magicoder
You are tasked with implementing a configuration class in C# that loads settings from a JSON file and provides access to these settings through properties. Your task is to complete the `Configuration` class by implementing the static constructor and defining the properties to access the configuration settings. The `Co...
magicoder
You are tasked with implementing a function that simulates the behavior of the Python `split()` method. The function should take in a string, a separator, and an optional maximum number of splits, and return a list of substrings obtained by splitting the original string at each occurrence of the separator, up to the sp...
magicoder
You are tasked with creating a Python script to automate the process of logging into a social media platform, retrieving pages, and extracting comments from a user's profile. The script should utilize the Selenium library to interact with the web browser and perform these actions. You are provided with a code snippet t...
magicoder
You are tasked with implementing a Python module for managing a library of stereoscopic images. The module should provide classes for representing individual stereoscopic images and a collection of such images. Each stereoscopic image consists of a left-eye image and a right-eye image. Your task is to implement the `S...
magicoder
You are given a Python code snippet that sorts sentiment scores based on their average value. Your task is to implement a function that takes a list of sentiment scores and returns the sorted indices based on the given logic. You are to write a function `sort_sentiment_indices(sentiment_scores: List[float]) -> List[in...
magicoder
You are tasked with implementing a layout manager for a user interface in a mobile application. The layout manager is responsible for positioning UI elements within a parent view. The code snippet provided below represents part of the logic for adjusting the constraints of these UI elements based on the parent view's d...
magicoder
You are working on a data conversion subsystem that processes files based on a configuration. The configuration is stored in a dictionary named `DCS_CONFIG`. The subsystem has multiple instances, each identified by a unique `SUBSYSTEM_INSTANCE_ID`. The configuration includes a key `DATA_CONVERSION_SUBSYSTEM_STATE_FILES...
magicoder
You are tasked with implementing a Java class for generating samples from a three-dimensional categorical distribution. A three-dimensional categorical distribution is a discrete probability distribution that describes the likelihood of an event occurring in one of several categories across three dimensions. The class ...
magicoder
You are tasked with creating a script to automate the installation and configuration of CUDA (Compute Unified Device Architecture) on a Linux system. CUDA is a parallel computing platform and programming model developed by NVIDIA for general computing on GPUs. The provided code snippet is a part of such a script and co...
magicoder
You are tasked with creating a Python class that simulates a data stream from a sensor. The class should have methods to pull a sample from the sensor and print the sample along with its timestamp. The timestamp should be in the format of hours:minutes:seconds. Your task is to implement the `DataStream` class with the...
magicoder
You are tasked with creating a Python function to simulate drawing a random playing card from a standard 52-card deck. The function should return the drawn card's face value and suit. You are provided with a code snippet that initializes the faces and suits of the playing cards. Your task is to complete the `carddraw`...
magicoder