instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with implementing a parallel tokenization function for processing a collection of documents. The function should take a list of documents, a tokenizer function, and a maximum number of tokens as input, and then parallelize the tokenization process across multiple CPU cores using the `joblib` library. Th...
codefeedback
You are tasked with creating a Python script to automate the configuration of CPU frequency settings on a Linux system. The script should read a configuration file containing the desired settings and apply them to the appropriate system files. The configuration file will contain lines in the following format: ``` <cor...
codefeedback
You are tasked with creating a Python class that interacts with a database using the `muttlib` library. The `muttlib` library provides utilities for database connections and operations. Your task is to create a class that encapsulates the functionality to perform CRUD (Create, Read, Update, Delete) operations on a spec...
codefeedback
You are tasked with implementing a message logging system in Python. The system should support logging messages of different types (error, warning, info) and provide a way to retrieve the messages based on their type and timestamp. Your task is to implement the `MessageLogger` class with the following requirements: 1....
codefeedback
You are tasked with implementing a custom decorator in Python that replicates the functionality of the `@login_required` decorator commonly used in web frameworks like Django. The `@login_required` decorator is used to restrict access to certain views in a web application to only authenticated users. When a user tries ...
codefeedback
You are tasked with implementing a dynamic embedding service that maps input keys to embeddings based on a given configuration. The service interacts with a knowledge bank service and supports various functionalities such as handling empty keys, specifying a unique variable name, controlling gradient updates, and setti...
codefeedback
You are tasked with creating a simple web application using Flask, a popular Python web framework. Your goal is to implement a basic message board feature where users can post messages and view all the messages posted by other users. To achieve this, you need to define a Flask blueprint for the message board functional...
codefeedback
You are given a Python code snippet that operates on a variable `s`. The code snippet contains a series of operations using slicing and indexing, and a comment indicating the calculation of the exponent of the constant `e`. Your task is to understand the operations being performed and write a Python function that repli...
codefeedback
You are tasked with implementing a generic index buffer class in C++ to manage indices for various types of graphics primitives. The index buffer should support adding and retrieving indices, as well as resizing the buffer when necessary. Your task is to complete the implementation of the `IndexBufferBase` class by add...
codefeedback
You are tasked with creating a Python program to simulate a rock-paper-scissors game against a computer opponent. The program should take user input for their choice (rock, paper, or scissor) and then randomly generate the computer's choice. The program should then determine the outcome of the game based on the choices...
codefeedback
You are tasked with implementing a class that manages a document editing form in a Windows Forms application. The form contains a group box for editing document options, including a numeric up-down control for setting line width. However, the given code snippet seems to be incomplete and contains some errors. Your task...
codefeedback
You are tasked with implementing a Python function that performs slicing on a multi-dimensional array. The function should take in a multi-dimensional array `m`, a list of slices `slices`, and an axis `axis`. The function should return the sliced array based on the provided slices along the specified axis. The functio...
codefeedback
You are working on a natural language processing project and need to process evaluation metrics for machine translation models. You have a file containing evaluation results in the following format: ``` RESULT: baseline: BLEU: AVG: 0.75 RESULT: baseline: METEOR: AVG: 0.68 ``` You need to write a Python function to pa...
codefeedback
You are tasked with creating a Python unit test for a class representing a Heroku application. The class has several methods for interacting with the application, and the unit test framework being used is `unittest` with `mock` for mocking external calls. Your task is to write a unit test for the `HerokuApp` class, sp...
codefeedback
You are tasked with creating a Python class that represents a collection of official documents. Each document has a unique identifier, a title, and a content. Your task is to implement the `OfficialDocument` class and the `OfficialDocumentsCollection` class to manage these documents. The `OfficialDocument` class shoul...
codefeedback
You are tasked with implementing a class that simulates a simple banking system. The class should have methods to deposit funds, withdraw funds, and check the current balance. Additionally, the class should keep track of the total number of transactions (deposits and withdrawals) made on the account. You need to creat...
codefeedback
You are tasked with creating a TypeScript class that represents a user subscription. The class should have a `userId` property of type `string` and a `validUntil` property of type `string`, representing an ISO date. Additionally, the `validUntil` property should be annotated with a decorator that sets its default value...
codefeedback
You are tasked with creating a script to automate the installation of PHP PEAR packages on a Debian system. The script should handle configuring PHP via PHP PEAR, updating PEAR channels, and installing required packages. Your task is to write a Bash script that accomplishes these tasks. Your script should perform the ...
codefeedback
You are tasked with implementing a Bloom Filter data structure in Python. A Bloom Filter is a space-efficient probabilistic data structure used to test whether an element is a member of a set. It may return false positives but never false negatives. Your task is to complete the implementation of the BloomFilter class b...
codefeedback
You are tasked with implementing a synchronization mechanism for different types of data in a web application. The given code snippet is part of a function that handles synchronization based on a specified mechanism. The function takes a `context` object as a parameter, which contains a `mechanism` property indicating ...
codefeedback
You are tasked with implementing a class for managing user information. The class should have the following attributes and methods: Attributes: - `name`: a string representing the user's name - `password`: a string representing the user's password - `email`: a string representing the user's email Methods: - `__init__...
codefeedback
You are working on a project that requires creating a Python function to build a map using a specific projection. The function will utilize the Basemap module from the mpl_toolkits library to generate the map. The function, map_RegCMdomain, takes several parameters to define the map's domain and projection properties. ...
codefeedback
You are tasked with creating a Python function that processes and validates car data received from a web request. The function should take in three parameters: `body_type`, `mileage`, and `mileage_unit`. The `body_type` parameter represents the type of car body (e.g., sedan, SUV), `mileage` represents the mileage of th...
codefeedback
You are given a code snippet that processes polygon vertices and indices to generate a list of vertices. Your task is to implement a function that takes in the polygon vertices, polygon indices, and a starting index, and returns a list of vertices based on the given indices. Write a function `GenerateVertices` that ta...
codefeedback
You are tasked with implementing a simple event handling mechanism using the Observer pattern in Swift. You are provided with a `ViewModel` class that represents the view model of a user interface component. The `ViewModel` class has a property called `disposeBag` of type `DisposeBag`, which is used to manage the dispo...
codefeedback
You are tasked with creating a Python program that simulates a simple text-based adventure game. The game will involve the player making choices that affect the outcome of the story. The game will be implemented using Python's `tkinter` library for the graphical user interface (GUI). Your task is to implement a functi...
codefeedback
You are tasked with creating a simple library management system using the Rust programming language. The system should allow users to add, remove, and search for books in the library. Additionally, users should be able to check out and return books. You are provided with the following code snippet as a starting point:...
codefeedback
You are tasked with implementing a simplified version of a control flow graph (CFG) creation utility in a programming language of your choice. A control flow graph is a representation of a program's control flow, where nodes represent individual statements or expressions, and edges represent the flow of control between...
codefeedback
You are given a list of integer differences `diffs`. Your task is to write a function to find the maximum sum of a subsequence of `diffs` such that no two elements in the subsequence are adjacent in the original list. In other words, you need to find the maximum sum of non-adjacent elements in the list. Write a functi...
codefeedback
You are tasked with implementing a function to process font characters and their corresponding Unicode values. The given code snippet is part of a font processing module and contains two methods: `characterIdToUnicode` and `guessSpaceCharacterId`. The `characterIdToUnicode` method attempts to find the Unicode represent...
codefeedback
You are given a list of integers and a target sum. Your task is to write a function that finds all unique combinations in the list that sum up to the target. Each number in the list may only be used once in the combination. The solution set must not contain duplicate combinations. Function Signature: ```python def co...
codefeedback
You are tasked with implementing a Python program that simulates a simple database entry system. The program should read input from a file, process the data, and save the entries to a database. However, the provided code snippet contains a critical error that needs to be identified and fixed. The code snippet is as fo...
codefeedback
You are tasked with creating a Python program that simulates a simple game of "Guess the Number." The program should generate a random number between 1 and 100, and then prompt the user to guess the number. After each guess, the program should provide feedback on whether the guess was too high, too low, or correct. The...
codefeedback
You are tasked with creating a script to automate the build process for a PHP project. The provided code snippet is a part of the buildphp function, which is responsible for setting up the PHP source code and running the necessary configuration steps. The function starts by changing the current directory to the locati...
codefeedback
You are tasked with implementing a function that groups a list of events by their date and returns a dictionary where the keys are the dates and the values are lists of events that occurred on that date. The events are represented as dictionaries with a 'date' key containing the date of the event. You need to write a ...
codefeedback
You are tasked with creating a Python program that simulates a simple logging and reporting system. The program should utilize the `logging` module to set different levels of logging and then generate reports based on the logged data. Your task is to complete the Python program by implementing the missing parts. The p...
codefeedback
You are tasked with implementing a function that filters a given array of movies based on a set of criteria. Each movie is represented as an associative array with 'title' and 'year' as keys. The function should take the movie array and a filter array as input and return a new array containing only the movies that sati...
codefeedback
You are tasked with implementing a version control system for a software project. The system should support the ability to apply a series of transformers to a set of instances of a given type. Each transformer will modify the instances in a specific way. Your task is to write a class method that takes an ID as input, r...
codefeedback
You are tasked with implementing a lock-free concurrent data structure for managing a collection of unique elements. The data structure should support adding, removing, and checking for the presence of elements in a thread-safe manner. To achieve this, you will utilize the `crossbeam-epoch` library, which provides lock...
codefeedback
You are tasked with implementing a file storage system that enforces restrictions on the allowed file extensions. Your task is to create a class `FileStorage` with the following requirements: - The class should have a method `add_allowed_extension` that takes a single argument `extension` (a string) and adds it to the...
codefeedback
You are tasked with implementing a custom exception class and handling the exception in a Python program. The custom exception class should be designed to handle a specific error condition, and the program should demonstrate the usage of this custom exception. Your task is to create a Python program that simulates a l...
codefeedback
You are tasked with creating a number guessing game using a Raspberry Pi and its GPIO pins. The game will display a binary number on three LEDs, and the player must press a button to submit their guess. The binary number will be converted to decimal, and the player's guess will be compared to the actual number. If the ...
codefeedback
You are given a string representing a license file. The license file contains a series of comments and a list of software packages with their respective licenses. Each comment starts with `//` and ends with a newline character. Each software package entry starts with `// *` and ends with `// *`. The software package en...
codefeedback
You are tasked with implementing a function that processes a given set of data and returns a specific result based on certain conditions. The function takes in two optional String parameters: `name` and `flag`. The function should return a message based on the following conditions: - If `name` is not provided, the func...
codefeedback
You are tasked with creating a command-line tool that simulates a simple task scheduler. The tool should be able to execute tasks in a specified order and handle dependencies between tasks. Your task is to implement the logic for the task scheduler. You are given the following code snippet as a starting point: ```bas...
codefeedback
You are tasked with implementing a function to create an oracle for a quantum computing simulation. The oracle is a crucial component in quantum algorithms, and it is used to encode the problem-specific information into the quantum state. The oracle is created based on a given method, and the user can input a custom st...
codefeedback
You are tasked with implementing a simplified version of a header parsing algorithm for a data processing application. The given code snippet is part of the header parsing process, which involves reading and processing specific sections of the header data. The header is represented by an array `hz.header` of bytes, an...
codefeedback
You are working on a deployment script for a software release. The script is responsible for creating and setting permissions for specific directories. The code snippet provided is a part of the deployment script and contains some shell commands. Your task is to write a function that simulates the behavior of the code...
codefeedback
You are tasked with creating a Python program to generate a PDF file containing a specific geometric shape. The program should utilize the `reportlab` library to draw the shape and save it as a PDF file. The code snippet provided below is a part of the program that accomplishes this task. ```python from reportlab.lib....
codefeedback
You are tasked with implementing a custom property wrapper in Swift that ensures a given floating-point value falls within a specified range. The property wrapper should validate the input value and, if it falls outside the specified range, return the nearest boundary value. The property wrapper should be used to decor...
codefeedback
You are tasked with creating a Python class that simulates a simple file management system. The class should handle file operations such as creating, deleting, and searching for files, as well as providing information about the files. Your task is to implement the `FileManager` class with the following specifications:...
codefeedback
You are tasked with creating a function that parses a given TypeScript interface and returns the number of GitHub stars associated with the interface name. The GitHub stars are denoted by the placeholder `<gh_stars>` followed by the number of stars. The function should take the TypeScript interface as input and return ...
codefeedback
You are working on a computer graphics project and need to implement a rendering function that can handle different rendering modes. The rendering function takes a list of rendering modes and a set of hidden parameters, and it should render all the instances in the renderer and read the output from the framebuffer into...
codefeedback
You are tasked with creating a Python class to retrieve the market capitalization of a cryptocurrency on a specific date using the CoinGecko API. Your class should include a method `get_market_cap_by_date` that takes three parameters: `coingecko_id` (the unique identifier of the cryptocurrency), `date` (the date for wh...
codefeedback
You are tasked with implementing a color class in Python that supports the representation and manipulation of colors in the HSB (Hue, Saturation, Brightness) color model. The HSB color model is a cylindrical-coordinate representation of colors, where the three parameters Hue, Saturation, and Brightness are used to defi...
codefeedback
You are tasked with creating a Python class for word vector analysis. The class should be able to load pre-trained word vectors, perform various operations on word vectors, and evaluate the accuracy of the word vectors using a specific dataset. Your task is to implement the `WordVectorAnalyzer` class with the followin...
codefeedback
You are tasked with implementing a function that takes in a list of strings representing words and returns a dictionary containing the frequency of each unique word in the list. The function should ignore case sensitivity, treating "Word" and "word" as the same word. Additionally, any non-alphabetic characters should b...
codefeedback
You are tasked with creating a unit test for a component in an Angular application. The component, `RegisterCityComponent`, is responsible for handling the registration of cities. The test framework being used is Jasmine with Angular's TestBed and ComponentFixture. Your goal is to write a unit test that ensures the pr...
codefeedback
You are tasked with creating a Python function that processes a given text file to extract and count the occurrences of unique words. The function should read the contents of the file, tokenize the words, and then return a dictionary containing each unique word as a key and its frequency as the corresponding value. Yo...
codefeedback
You are tasked with creating a Python program to interact with a SQLite database containing information about genes. The database has a table named "Genes" with two columns: "gid" (gene ID, primary key) and "name" (gene name). Your program should provide functionality to insert new gene records, retrieve gene informati...
codefeedback
You are tasked with implementing a rating system for a sports league using the Elo rating system. The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as chess. In this problem, we will adapt the Elo rating system for a team-based sports league. The Elo rating...
codefeedback
You are tasked with implementing a lazy initialization mechanism for a service in a Swift application. The lazy initialization should ensure that the service is only instantiated when it is first accessed and then reused for subsequent accesses. You are provided with a code snippet that demonstrates the lazy initializa...
codefeedback
You are tasked with creating a Python class that implements the Observer design pattern. The Observer pattern is a behavioral design pattern where an object (known as the subject) maintains a list of its dependents (observers) and notifies them of any state changes, usually by calling one of their methods. Your task is...
codefeedback
You are given two integer arrays, `nums1` and `nums2`, representing two sequences of numbers. A line connecting two numbers in the sequences is called an "uncrossed line" if the line does not intersect any other line. Your task is to find the maximum number of uncrossed lines that can be drawn between the two sequences...
codefeedback
You are tasked with implementing a Python class to calculate and store shipping charges, including tax details. The class `ShippingCharge` has the following attributes and methods: Attributes: - `is_tax_known`: a boolean indicating whether the tax information is known for the shipping charge. - `excl_tax`: a decimal r...
codefeedback
You are tasked with creating a Python function that simulates a simplified version of the `open` function for file handling. Your function, `custom_open`, should take a file path and a mode as input and return a file object. The mode can be one of the following: "r" for reading, "w" for writing, or "a" for appending. I...
codefeedback
You are tasked with implementing a Long Short-Term Memory (LSTM) neural network for time series prediction. The LSTM class is provided with a configuration file "settings.ini" that contains all the necessary hyperparameters and settings for the LSTM model. Your goal is to complete the implementation by defining the LST...
codefeedback
You are given a string `reg` which represents a regular expression pattern. Your task is to write a function `match_pattern` that takes a list of strings and returns a new list containing only the strings that match the given regular expression pattern. The regular expression pattern `reg` can contain the following sp...
codefeedback
You are working on a compiler optimization tool that analyzes Swift code. Your task is to implement a part of the tool that identifies and optimizes unnecessary borrow and copy operations in the code. Given the following Swift code snippet: ```swift // CHECK: [[X_COPY:%.*]] = copy_value [[BORROWED_X]] // CHECK: s...
codefeedback
You are tasked with implementing a function that manipulates a binary search tree (BST). A binary search tree is a data structure in which each node has at most two child nodes, referred to as the left child and the right child. For each node, all elements in its left subtree are less than the node, and all elements in...
codefeedback
You are tasked with implementing a class-based interface for generating alternate names for command-line options. The interface `IPropertyOptionAlternateNameGenerator` defines the contract for generating alternate names for options represented by properties. Your task is to create a class that implements the `IPropert...
codefeedback
You are tasked with implementing a PermissionFragmentFactory class that manages the creation and retrieval of permission fragments in an Android application. The factory should ensure that only one instance of each type of permission fragment is created and reused when requested. The PermissionFragmentFactory class sh...
codefeedback
You are working on a secure messaging application that requires the use of digital certificates for encryption and decryption. Your task is to implement a function that fetches a specific certificate from a given set of certificates and returns its encoded value. You are given a code snippet that includes a function c...
codefeedback
You are tasked with designing a data structure to represent the configuration settings for an S3 File Gateway. The S3 File Gateway is a service that enables on-premises applications to use Amazon Simple Storage Service (S3) storage. Your task is to create a Swift struct that encapsulates the configuration settings for ...
codefeedback
You are tasked with implementing a simplified version of a tensor operation called MTTKRP (Matrix-Vector Tensor Contraction along a specified mode) using C++. MTTKRP is a fundamental operation in tensor computations, and it involves multiplying a tensor by a matrix along a specified mode to produce a new tensor. In th...
codefeedback
You are working on a project that involves processing a dataset of images of playing cards. The dataset is stored in a pandas DataFrame called `data_df`, which has the following columns: - "image_id": a unique identifier for each image - "categories": a list of categories (e.g., "hearts", "diamonds", "clubs", "spades")...
codefeedback
You are given a list of items, each with a specific weight and value. Your task is to write a function to determine the maximum value that can be obtained by selecting a subset of the items to fit into a knapsack of a given capacity. The function should take the list of item weights, item values, and the knapsack capac...
codefeedback
You are tasked with creating a TypeScript type definition generator for a given set of function declarations. The input will be an array of function declarations, each containing the function name and its parameters. Your goal is to write a function that takes this input and generates a TypeScript type definition for t...
codefeedback
You are tasked with implementing a file processing class in Python that handles writing sensor and weather data to CSV files. The class, `FileProcessor`, has an `__init__` method to initialize the file name, file path, and rotation location. It also has a `write_to_csv` method to write data to the CSV file. The `write_...
codefeedback
You are tasked with implementing a graph algorithm to find the maximum clique size and number of edges in a given graph. A clique in a graph is a subset of vertices such that every two distinct vertices in the clique are adjacent. The number of edges in a graph is the count of unique pairs of vertices that are connecte...
codefeedback
You are tasked with implementing a simple encoding and decoding algorithm for a custom data type called `BitVec`. The `BitVec` type represents a vector of bits, and it supports encoding and decoding operations. The encoding process converts a value of a specific type into a bit vector, while the decoding process conver...
codefeedback
You are tasked with implementing a generic data structure that supports storing elements of any type and provides a handle to access and manipulate these elements. The provided code snippet defines the public interface of the data structure, specifying the element type and the handle type. Your task is to implement th...
codefeedback
You are tasked with creating a program to implement a custom k-fold cross-validation for a machine learning model. The program should read a CSV file containing training data, split the data into k folds, and assign fold numbers to each row in the dataset. The program should use the StratifiedKFold method from the scik...
codefeedback
You are working on a network security application that needs to handle various types of data and network configurations. The given code snippet defines several constants using bitwise left shift operations. These constants are used to represent different data types, file types, and network configurations. Your task is ...
codefeedback
You are given a string containing a series of paragraphs. Each paragraph contains sentences with placeholders denoted by `<NAME>`. Your task is to write a program to replace these placeholders with actual names provided in a separate list. If a placeholder appears multiple times in a paragraph, all occurrences should b...
codefeedback
You are tasked with implementing a command-line tool for managing software releases. The tool uses a library called `release_plz_core` to perform various release-related operations. The code snippet provided is a part of the command processing logic for this tool. Your task is to understand the code and design a data s...
codefeedback
You are tasked with creating a Python function that generates a unique hostname and starts a Docker container with specific configurations. The function should take two parameters: a string `name` and an integer `uid`. The `format_hostname` function is provided to format the hostname based on the input parameters. The ...
codefeedback
You are given a sequence of integers representing the values of elements in a game. The goal is to maximize the sum of selected elements subject to certain constraints. The constraints are as follows: 1. You can't select two consecutive elements. 2. If you select an element, you can't select the next element. 3. If the...
codefeedback
You are tasked with implementing a quantum algorithm to solve a specific type of optimization problem. The problem involves creating a quantum oracle and using Grover's algorithm to find the optimal solution. The code snippet provided initializes the quantum oracle, sets up the Grover algorithm, selects a backend for q...
codefeedback
You are tasked with implementing a function that converts a color from the RGB (Red, Green, Blue) color space to the HSV (Hue, Saturation, Value) color space. The RGB color space represents colors using the intensities of red, green, and blue, while the HSV color space represents colors using their hue, saturation, and...
codefeedback
You are tasked with implementing a Python class to manage a history graph for composing tasks. The class, `ComposingHistoryGraph`, should be designed using the `dataclass` decorator and should have the following attributes: - `uid` (str): A unique identifier for the history graph. - `dataset_name` (str): The name of th...
codefeedback
You are given a list of integers representing the daily stock prices of a company. Your task is to write a function that calculates the maximum profit that can be obtained by buying and selling the stock on different days. However, you are only allowed to make at most one transaction (i.e., buy one and sell one share o...
codefeedback
You are tasked with creating a program that reads a series of integers from an input file, performs a specific operation on each integer, and then writes the results to an output file. The operation to be performed on each integer is as follows: if the integer is even, it should be divided by 2; if the integer is odd, ...
codefeedback
You are tasked with creating a custom error type in Rust to handle specific error scenarios in a file processing application. Your custom error type should encapsulate different kinds of errors that can occur during file processing, such as file not found, permission denied, or invalid file format. Additionally, you ne...
codefeedback
You are tasked with creating a word guessing game in Python. The game will randomly select a word from a predefined list, and the player must guess the letters of the word within a limited number of attempts. The player will be provided with a partially completed word, and they must guess the remaining letters to compl...
codefeedback
You are given a code snippet that is part of a function. Your task is to complete the function by implementing the missing logic. The function takes an array of integers as input and is expected to return a modified array based on certain conditions. The function signature is as follows: ```python def process_array(ar...
codefeedback
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...
codefeedback
You are tasked with implementing a constraint solver for a simple layout system. The system uses constraints to position UI elements within a view. Each constraint is defined by a pair of attributes, a relation, and an optional constant. The attributes can be top, bottom, leading, trailing, etc., and the relation can b...
codefeedback
You are tasked with implementing a secure login system for a web application. The provided code snippet is a part of the login functionality, which includes capturing user login details and authenticating the user session. The code also ensures that the user is accessing the login page over a secure HTTPS connection. ...
codefeedback
You are tasked with creating a function that calculates the distance between two geographical coordinates using the Haversine formula. The Haversine formula is a well-known equation used to calculate the distance between two points on the Earth's surface given their latitude and longitude. The formula is as follows: \...
codefeedback