instruction_seed stringlengths 29 40.5k | source stringclasses 6
values |
|---|---|
You are tasked with creating a custom Django template filter that takes a list of strings and returns a new list containing only the strings that are longer than a specified length. Your task is to implement the custom template filter and write a Django template that demonstrates its usage.
Create a custom Django temp... | magicoder |
You are tasked with creating a Python script that simulates the functionality of the `update-rc.d` command in Linux. The `update-rc.d` command is used to install or remove System-V style init script links. The script should be able to add or remove a service from the system's startup sequence.
Your Python script shoul... | magicoder |
You are tasked with creating a Python function that utilizes the `SpeechRecognition` library to transcribe speech from a WAV file. The function should read a configuration file to determine the language for transcription. The configuration file is in the INI format and contains the necessary settings.
You are provided... | magicoder |
You are tasked with implementing a simple stack data structure in Swift using an array. The stack should support the following operations:
1. `push`: Add an element to the top of the stack.
2. `pop`: Remove and return the element at the top of the stack.
3. `peek`: Return the element at the top of the stack without rem... | magicoder |
You are working on a project that involves creating a database schema using SQLAlchemy, a popular Python SQL toolkit and Object-Relational Mapping (ORM) library. Your task is to define a new SQLAlchemy model class that represents a table in the database. The model should inherit from the `Base` class, which is a part o... | magicoder |
You are tasked with creating a Python function that generates Django URL patterns for a given set of views. The function should take a list of view names and return a list of URL patterns that include these views. Each URL pattern should be in the format `url(r'^<view_name>/$', <view_name>),` where `<view_name>` is the... | magicoder |
You are tasked with creating a Python function that simulates a specific behavior of the provided code snippet. Your function should generate an infinite sequence of numbers, starting from 1 and incrementing by 1 with each iteration. However, the function should allow for the sequence to be generated lazily, meaning th... | magicoder |
You are working on a project that involves processing audio data using Python and its libraries. You have been given a code snippet that loads a scaler model and processes an audio file. Your task is to complete the code by implementing a function that applies the loaded scaler to the audio data and returns the scaled ... | magicoder |
You are tasked with creating a Python Flask API endpoint that retrieves and returns data from a SQL database. The database is already set up and contains a table named `countries` with the following schema:
```
CREATE TABLE countries (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
populati... | magicoder |
You are tasked with implementing a function that processes a list of developers and their respective skills. The function should take in the developer's name, skills, and the global list of developers, and update the global list with the new developer's information. Each developer's information is represented as a dict... | magicoder |
You are tasked with creating a Python program to automate the process of fetching images from a website using Selenium and Chrome WebDriver. Your program should be able to navigate to a specific webpage, locate and download images, and save them to a designated folder on your local machine.
Your program should perform... | magicoder |
You are tasked with creating a Python function that processes a dynamic state of infrastructure nodes to identify failed nodes and nodes to be removed. The dynamic state is represented as a nested dictionary, and the function should extract information from it to determine the failed and remove nodes.
The dynamic stat... | magicoder |
You are tasked with implementing a simple linear regression model using Python. Your goal is to create a class called `SimpleLinearRegression` that can fit a linear model to a given set of data points and make predictions based on the fitted model.
Your `SimpleLinearRegression` class should have the following methods:... | magicoder |
You are tasked with creating a system for a 2D game engine using the Bevy game engine framework. The game engine uses the ECS (Entity-Component-System) architecture, where entities are composed of components and systems operate on entities with specific components. Your goal is to implement a system that updates the po... | magicoder |
You are working on a computer vision project that involves processing video streams from a camera. You need to develop a Python program that captures video from a camera using OpenCV and displays it in a window. Additionally, you are required to overlay text on the video frames to display some information.
You are giv... | magicoder |
You are given a string representing a snippet of C++ code. The code snippet is incomplete and contains an unbalanced number of opening and closing curly braces (`{` and `}`). Your task is to write a function to determine the minimum number of opening or closing curly braces that need to be added to balance the code sni... | magicoder |
You are tasked with creating a Python function to manage the conversion of mesh files from one format to another for finite element simulations. The function should handle the conversion of mesh files using external software tools and ensure that the converted files are up to date.
You are given the following code sni... | magicoder |
You are tasked with implementing a class for managing string conversions. The class contains a method `_MoveDown` that selects a conversion, retrieves its data, and then attempts to swap it with the next conversion in the list. Your task is to complete the implementation of the `_MoveDown` method by writing the code to... | magicoder |
You are tasked with implementing a signature verification function for a custom data structure called `CrdsValue`. The `CrdsValue` can represent different types of data, such as `ContactInfo` and `Vote`. Each `CrdsValue` is associated with a public key and a timestamp. The code snippet provided demonstrates the usage o... | magicoder |
You are tasked with creating a Python function that calculates the time difference between the current time and a given future time. The function should take the future time as input and return the time difference in hours, minutes, and seconds.
The code snippet provided initializes the variable `now` with the current... | magicoder |
You are working on a machine learning project and need to optimize the hyperparameters for a support vector machine (SVM) model using Amazon SageMaker's HyperparameterTuner. The SVM model has two hyperparameters: `c` and `gamma`. The `c` parameter is a continuous value that needs to be tuned within a specified range, a... | magicoder |
You are working on a file storage system that organizes files into different categories using prefixes. Each file is associated with a specific prefix, and the full prefix for a category is formed by combining the common prefix and the category-specific prefix.
You have been given the following Python code snippet:
`... | magicoder |
You are tasked with implementing a quiz program in Python. The program should present a series of multiple-choice questions to the user, allow them to select an answer, and then provide feedback on their response. The quiz should consist of at least 5 questions, and the user's score should be calculated and displayed a... | magicoder |
You are tasked with creating a program that analyzes a given TypeScript file to extract information about the imported modules. Your program should be able to identify the imported modules and count the occurrences of each module. For the purpose of this problem, you can assume that the TypeScript file follows the Angu... | magicoder |
You are tasked with creating a TypeScript function that generates a set of rules based on a given schema. The function takes a `CURDOptions` object as input and returns a set of rules. Each rule corresponds to a specific operation: list, edit, and view. The `schematic` function is used to create rules for each operatio... | magicoder |
You are tasked with creating a program to analyze the average word count per user in a chat application. You are given a function `avg_word_count_by_user` that takes a list of comments as input and returns a dictionary where the keys are user IDs and the values are the average word count of comments made by each user.
... | magicoder |
You are tasked with implementing a custom layout for a collection view in an iOS app. The goal is to create a grid layout where the size of each item is dynamically calculated based on the available width and a specified number of items per row.
You are given the following code snippet from the `StartViewController` c... | magicoder |
You are tasked with creating a Python class that interacts with a SQLite database to retrieve and process data related to user posts. The class should have methods to fetch posts based on different criteria and return the results in a specific format.
Your task is to implement the `PostRepository` class with the follo... | magicoder |
You are tasked with implementing a Python function that parses a given text and extracts information about classes and their inheritance hierarchy. The text will be formatted similarly to the provided code snippet, with class names and their inheritance relationships listed in a specific format.
You need to write a fu... | magicoder |
You are tasked with creating a React component that displays a list of items based on a selected filter. The component should have a state to store the current filter and should render the items based on this filter. The code snippet provided is a part of the React component, showing the initialization of the component... | magicoder |
You are tasked with creating a Python function that parses a given file and extracts the copyright information from it. The copyright information is typically found in the header of source code files and includes the year and the copyright holder's name.
Write a function called `extract_copyright_info` that takes a fi... | magicoder |
You are working on a Python class that represents an email message. The class has several methods and attributes related to handling the message's headers and body. Your task is to implement a method that checks whether the message is runnable based on certain conditions.
You are given the following code snippet as a ... | magicoder |
You are tasked with creating a custom test framework for unit testing in Swift. Your framework should be able to handle test cases, execute them, and report the results. To achieve this, you need to implement a TestSuite class, a TestCase class, and a TestRunner class.
The TestSuite class should be responsible for sto... | magicoder |
You are tasked with creating a context manager for a database connection in Python. The context manager should handle the opening and closing of the database connection automatically when entering and exiting the context. Your task is to implement the `DatabaseConnection` class to achieve this functionality.
The `Data... | magicoder |
You are tasked with creating a program that processes a string containing SQL table creation statements and extracts the table names from the statements. The SQL table creation statements are enclosed within double curly braces `{{ }}` and may contain multiple table creation statements. Each table creation statement is... | magicoder |
You are working on a project that involves managing machine learning jobs on Amazon SageMaker. Your task is to implement a Python class that provides methods for starting and stopping hyperparameter tuning jobs. The class should have the following methods:
1. `start_transform_job(self, name, input_data, output_data)`:... | magicoder |
You are tasked with creating a Python function that simulates the behavior of the `os.path.join` function. The `os.path.join` function in Python takes multiple path components and joins them into a single path using the appropriate separator for the operating system. Your task is to implement a simplified version of th... | magicoder |
You are tasked with implementing a C++ program that simulates a simple file I/O monitoring system. The program should define a structure to store I/O operation counts and provide functions to update and display these counts.
Your task is to complete the implementation of the given structure `_IO_COUNTERS` and the func... | magicoder |
You are working on a project that involves optimizing and transforming neural network models represented in the ONNX format. As part of this process, you need to implement a Python function that checks for a specific condition in the ONNX graph and raises an exception if the condition is met. The provided code snippet ... | magicoder |
You are tasked with creating a Bash script to manage the volume control of a media player. The script should read the current volume level and mute status, and then set the appropriate icon based on these parameters. The volume level is represented by a number between 0 and 100, and the mute status is represented by "[... | magicoder |
You are tasked with implementing a custom data structure called `EasyList` in Swift. The `EasyList` should support various list types and provide auto-sizing cell configuration for a table view.
Your task is to complete the implementation of the `EasyList` data structure and the `setupAutoSizingConfiguration` method. ... | magicoder |
You are tasked with creating a Python program that generates random jokes from a predefined list. The program should utilize the `numpy.random.choice` function to select a joke from the list and print it to the console. Additionally, the program should be able to handle potential errors that may occur during the joke s... | magicoder |
You are working on a project that involves optimizing video processing algorithms for a multimedia application. As part of this project, you need to implement a function that calculates the masked sub-pixel variance for different block sizes. The masked sub-pixel variance is a measure of the variation in pixel values w... | 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, determine the winner, and display the result.
Your program should follow these guidelines:
-... | magicoder |
You are tasked with implementing a class to track the usage statistics of a system. The class, named `SystemStats`, should have the following properties and methods:
Properties:
- `openFiles`: A long integer representing the number of files currently open in the system.
- `computation`: A long integer representing the... | magicoder |
You are tasked with creating a form validation function for a web application. The function should validate the input from a source URL field in a form. The source URL field is represented by the HTML code snippet below:
```html
<FormControl margin="normal" fullWidth>
<InputLabel htmlFor="source-url">Source Url</Inp... | magicoder |
You are tasked with creating a Python class that manages a simple inventory system for a small business. The class should allow for adding, removing, and updating items in the inventory, as well as providing functionality to check the quantity of a specific item and to generate a report of all items in the inventory.
... | magicoder |
You are tasked with implementing a custom table class in Python that can be used to display data in a tabular format. The table will have columns with customizable headers and data accessors. Your task is to create a class called `CustomTable` that extends the provided `Table` class and allows for the creation of table... | magicoder |
You are tasked with creating a program that simulates the behavior of a CSS parser. Given a series of CSS style declarations, your program should parse the declarations and identify any properties that are set to specific values. In this case, you need to identify and extract all the properties that are set to "none" o... | magicoder |
You are tasked with designing a simple routing system for a web application. The application should handle various HTTP request methods and map them to specific controller methods. Your task is to implement a routing system that matches the given HTTP request methods to their corresponding controller methods.
You are ... | magicoder |
You are tasked with creating a simple to-do list application using Rust and GTK. The application should allow users to add, remove, and view tasks. Your task is to implement the functionality to add tasks to the to-do list.
You are provided with a code snippet that initializes the GTK application and sets the applicat... | magicoder |
You are tasked with implementing a Python class that interacts with a REST API. Your class should have a method that constructs and returns the full URL for a given API endpoint. The class should also allow for the customization of the API server URL.
Create a Python class `APIRequest` with the following specification... | magicoder |
You are tasked with implementing a function that simulates a simple game mechanic. The game involves controlling a male player character, and the function is responsible for executing the logic associated with the player's actions.
You are provided with a code snippet from the game's source code, which includes a meth... | magicoder |
You are tasked with creating a Python program that processes image files in a given directory. The program should identify all image files in the directory based on their file extensions and then process each image using a specific function.
Your task is to implement the `process_images` function, which takes a direct... | magicoder |
You are tasked with implementing a student management system that can perform various operations such as adding new students, removing students, and displaying the list of students. Your task is to complete the `manage_students` function, which should support the following operations:
1. Add a new student: The functio... | magicoder |
You are tasked with creating a Python function that initializes a classifier for a data visualization tool. The function takes several input parameters and is responsible for setting up the classifier based on the provided inputs. Your goal is to implement the `initialize_classifier` function according to the given spe... | magicoder |
You are tasked with creating a Python function to manage the power consumption of smart plugs in a household. The smart plugs are connected to various devices and can be controlled remotely. The `tplink_smartplug_py3` library provides the necessary functionality to interact with these smart plugs. The library includes ... | magicoder |
You are given a string representing a pattern of asterisks and colons. Your task is to write a program to count the number of asterisks and colons in the pattern and then print the count of each character.
For example, given the input string:
```
* :::::::.. '..:::: :. :::: :
```
The program should output:
... | magicoder |
You are tasked with creating a Python function that processes a given simulation type and returns a formatted string. The simulation type is represented as a constant string defined in a module. The module contains a license header and the definition of the simulation type constant. Your task is to extract the simulati... | magicoder |
You are tasked with implementing a Python function that ensures the presence of a specific anchor in a set of firewall rules. The function should check if the anchor is already present in the rules, and if not, add it and update the rules accordingly.
You are given the following code snippet as a starting point:
```p... | magicoder |
You are tasked with implementing a function to prevent buffer overflows in a C++ embedded systems project. The project involves interfacing with a sensor module using the `arm` namespace and the `rocs` namespace. The `arm` namespace contains a global variable `global_slave_addr` representing the slave address of the se... | magicoder |
You are tasked with creating a program to match users with nearby locations based on their geographical coordinates and search radius. Given a list of users with their email addresses and zip codes, along with a list of locations and their coordinates, the program should identify which users are near which locations wi... | magicoder |
You are tasked with implementing a Java class to manage the ranking of titles in a system. The class, `TitleRanksPair`, is responsible for storing and retrieving information about the titles and their corresponding ranks. The class has the following attributes and methods:
Attributes:
- `title`: A `Text` object repres... | magicoder |
You are tasked with implementing a Python class that manages a collection of neural network layers for a reinforcement learning system. The class should provide methods for adding different types of layers, such as DenseEmbeddingNet, QNet, CNNEmbeddingNet, PolicyNet, and ValueNet, and for retrieving specific layers bas... | magicoder |
You are tasked with creating a script to automate the process of restoring a MySQL database from a dump file. The script should take the necessary parameters and execute the restoration process using the `mysql` command-line tool.
Your script should accept the following parameters:
- `HOST`: The hostname of the MySQL ... | magicoder |
You are tasked with creating a Python function that generates a list of HTML elements based on a given set of data. The function should take in a list of most active items and return a string containing HTML elements representing each item.
The function signature should be:
```python
def generate_most_active_html(all_... | magicoder |
You are tasked with implementing a class that simulates a context-free grammar (CFG) in Python. The class should be able to generate random strings based on the rules defined in the grammar. The grammar is represented by a set of non-terminal symbols, terminal symbols, and production rules.
Your task is to complete th... | magicoder |
You are tasked with implementing a Python class called `ColorWriter` that inherits from the `TextResource` class. The `ColorWriter` class should have a method called `write` that takes a string and a color as input and prints the string in the specified color. The available colors are "red", "green", "blue", "yellow", ... | magicoder |
You are tasked with implementing a function that performs padding removal on a 4-dimensional tensor in a deep learning framework. The input tensor `out` has dimensions (batch_size, channels, height, width), and the padding values `pad_h` and `pad_w` represent the number of rows and columns of padding to be removed from... | magicoder |
You are tasked with creating a Python function that processes image data to calculate the distribution of labels within a dataset. The function should take a single argument, `dataset_path`, which represents the path to the dataset directory. The function should utilize the `ImageFolder` class from the `torchvision.dat... | magicoder |
You are tasked with creating a program to analyze and manipulate a given PHP code snippet. The code snippet provided is a segment of a Symfony controller class. Your task is to identify and extract the names of the controller actions (methods) defined in the class. The controller actions are annotated with `@Route` to ... | magicoder |
You are tasked with implementing a simplified version of an auto factory management system. The `AutoFactory` class is responsible for loading and managing different types of vehicles. The `vehicles` dictionary within the `AutoFactory` class stores the mapping of car model names to their respective classes. The `load_a... | magicoder |
You are given a Python code snippet that contains an `else` statement. Your task is to write a program that analyzes the given code and identifies the possible scenarios that could lead to the execution of the `else` block.
Write a Python function `identify_else_scenarios(code: str) -> List[str]` that takes a string ... | magicoder |
You are tasked with implementing a simple class in PHP that represents a basic shopping cart. The shopping cart should allow items to be added, removed, and the total cost to be calculated. The class should also be able to apply a discount to the total cost if a discount code is provided.
Your task is to complete the ... | magicoder |
You are tasked with implementing a utility class in TypeScript to handle JSON manipulation and request processing. The class `Helper` contains three static methods: `jsonStringifyAndEscapeNonASCII`, `parseLink`, and `isReadRequest`.
1. The `jsonStringifyAndEscapeNonASCII` method takes an argument of any type and retur... | magicoder |
You are tasked with implementing a custom neural network model for a reinforcement learning framework. The model will be used to process input data and make predictions in a specific environment. You will need to define the architecture of the neural network using the provided code snippets and ensure that it meets the... | magicoder |
You are tasked with creating a program that processes a set of images and generates a composite visualization. The program should read a series of image files, arrange them in a grid, and display the composite visualization. Each image should be labeled with a specific title based on its position in the grid.
You are ... | magicoder |
You are tasked with implementing a Python function that takes a nested dictionary as input and returns a flattened dictionary. The input dictionary may contain nested dictionaries, and the output should be a single-level dictionary with keys representing the full path to each value in the original nested dictionary.
Y... | magicoder |
You are tasked with creating a program to manage different types of files in a content management system. The system should be able to handle model files and texture files, each with its own specific control for displaying and managing the file content.
You are given a code snippet from the existing system that uses a... | magicoder |
You are tasked with implementing a simple iOS app feature that involves manipulating a UILabel based on user input. The app has a single view controller with a UILabel outlet named `label`. The goal is to create a function that takes a string as input and updates the label's text to display the input string in reverse ... | magicoder |
You are tasked with implementing a function to determine if a given string has all unique characters. You need to create a method `isUniqueCharsOnly` that takes a string as input and returns `true` if the string contains only unique characters, and `false` otherwise. For example, the string "abcde" should return `true`... | magicoder |
You are given a JSON object representing image annotations in a machine learning project. The object contains a list of regions, where each region has associated region attributes. Your task is to write a function that extracts the region attributes from each region and stores them in a list.
You are to implement the ... | magicoder |
You are tasked with creating a C++ program that simulates a simple machinery management system. The system should be able to add new machinery, remove existing machinery, and display the details of all machinery in the system. Additionally, the program should be able to test the machinery by invoking a plugin layer and... | magicoder |
You are tasked with implementing a simple input handling system for a game engine. The provided code snippet shows a part of the implementation for the input handling system. The system consists of an `IInputReceiver` interface and a class `engine_impl` that manages input capturing.
The `IInputReceiver` interface is u... | magicoder |
You are tasked with creating a Python script that automates the process of checking and installing Python packages. Your script should be able to handle both local and global installations and should provide feedback on the success or failure of the installation process.
Write a Python function called `install_package... | magicoder |
You are tasked with creating a Python class that simulates typing on a keyboard. The class should have a method for typing individual letters and another method for typing a sequence of letters. The typing simulation should take into account any necessary keyboard modifiers, such as shift, and allow for a specified dur... | magicoder |
You are tasked with creating a program that can validate whether a given HTML tag is well-formed or not. For the purpose of this problem, a well-formed HTML tag must adhere to the following rules:
1. It must start with an opening angle bracket `<`.
2. It must be followed by a valid tag name, which consists of one or mo... | magicoder |
You are tasked with implementing a function that takes in a dictionary representing a music track and a set of tags that should only be set if they are missing in the track. The function should update the track's tags according to the given set of rules.
You are given the following code snippet for inspiration:
```py... | magicoder |
You are working for a company that is developing a configuration management system. Your task is to write a function that will sanitize sensitive information in a given configuration array. The sensitive information includes passwords and keys, which should be replaced with placeholder strings.
Write a function `sani... | magicoder |
You are tasked with creating a program that can analyze and extract key information from a given Chinese text. The program should be able to identify and count the occurrences of Chinese characters, English letters, digits, and special symbols in the text.
Write a function `analyze_text` that takes a Chinese text as i... | magicoder |
You are tasked with creating a Python function that converts angles from radians to degrees. The function should take a single argument, a float representing an angle in radians, and return the equivalent angle in degrees. You should use the math module to perform the conversion.
Create a function called `convert_to_d... | magicoder |
You are tasked with implementing a Python function that downloads a file from a given URL and saves it to the local file system. The function should handle the case where the download fails and return an appropriate error message. Use the following code snippet as a starting point:
```python
import requests
import os
... | magicoder |
You are tasked with implementing a pagination feature for a web application. The application uses a trait called `WithPagination` to handle pagination functionality. The `WithPagination` trait provides methods for managing pagination, such as `paginate()` and `render()`. Your task is to implement the `render()` method ... | magicoder |
You are tasked with implementing a class that manages URLs and image URLs for a web application. The class should have methods to set and retrieve the URL and image URL.
You need to create a Java class called `WebPage` with the following specifications:
- It should have two private instance variables: `url` of type `S... | magicoder |
You are tasked with implementing a function that processes a list of employee names and their corresponding salaries. The function should calculate the average salary of all employees whose names are not null. If a name is null, it should be excluded from the average calculation. The function should return the average ... | magicoder |
You are tasked with understanding and implementing a custom conditional bean creation in a Spring Boot application. The given code snippet is a part of a Spring Boot configuration class and uses annotations to conditionally create a bean based on the presence of other beans in the application context.
Your task is to ... | magicoder |
You are tasked with implementing a function that processes a list of image filters and their corresponding parameters. The function should apply these filters to an input image and return the processed image. The filters can include operations such as blurring, sharpening, edge detection, and color manipulation. Each f... | magicoder |
You are tasked with implementing a function to simulate a series of duels between different AI agents in a game. Each agent has a specific strategy, and the outcome of the duels will determine their effectiveness. The duels are conducted in a round-robin fashion, where each agent fights every other agent exactly once. ... | magicoder |
You are working on a computer vision project and need to implement a function that filters and returns the largest contours based on their relative areas. The function takes in two arrays: `relative_areas` containing the relative areas of contours and `top_contours` containing the contours themselves. Additionally, the... | magicoder |
You are tasked with creating a Python function that filters a list of data file keys based on their creation time. The function should take a list of data file keys and a reference time as input, and return a filtered list containing only the keys that were created before the reference time.
The data file keys are ins... | magicoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.