Skip to content
  • 0 Votes
    3 Posts
    17k Views
    Mudassar HussainM
    35103323110111
  • 0 Votes
    2 Posts
    1k Views
    zaasmiZ
    @Engrnaveed-Saeed said in Incompatible type in filter using a callable: “I’m encountering an issue where I get an ‘Incompatible type’ error when using a callable with filter(). The callable seems to work fine on its own, but when used within filter(), it throws this error. What could be causing this issue, and how can I resolve it?” The “Incompatible type” error in filter() usually occurs when the callable you’re using doesn’t return a boolean value. The filter() function expects the callable to return True or False for each element, indicating whether that element should be included in the result. Here are a few potential causes and solutions: Callable Not Returning a Boolean Ensure that the callable you’re passing to filter() returns a boolean value (True or False). For example: # Incorrect: The function returns the value itself, not a boolean def my_callable(x): return x # Correct: The function returns a boolean condition def my_callable(x): return x > 0 result = filter(my_callable, [-2, -1, 0, 1, 2]) print(list(result)) # Output: [1, 2] Incompatible Return Type If your callable returns a non-boolean value (e.g., None, a string, or any other type), filter() will treat all non-None values as True but may still raise type errors if the value is not expected. For example: # Incorrect: Returning a string (non-boolean) def my_callable(x): return "valid" if x > 0 else "invalid" # Correct: Return boolean def my_callable(x): return x > 0 Using Lambda or Other Callables Ensure that if you’re using a lambda or other callable types, they also return booleans: # Correct usage with lambda result = filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5]) print(list(result)) # Output: [2, 4] Conclusion To resolve the “Incompatible type” error in filter(), make sure your callable function returns a boolean (True or False) based on the condition that determines whether each item should be included in the result.
  • 0 Votes
    2 Posts
    920 Views
    zaasmiZ
    @zaasmi said in std::print() wrapper with altered format: Here’s a rewritten version of your question: “I’m trying to create a std::print() wrapper that modifies the output format, such as adding a prefix and suffix around the original format. I was able to achieve this using a macro. How can I improve this approach or implement it differently for more flexibility?” #define DECORATED_PRINT(fmt, ...) std::println("prefix " fmt " suffix", __VA_ARGS__) To achieve a std::print() wrapper with a modified format (e.g., adding a prefix and suffix), using a macro is one way, but there are other approaches that might offer more flexibility and better maintainability. Here are a few options: Using a Macro You can use a macro to wrap std::print() and modify the format. Here’s a simple example: #define PRINT_WITH_FORMAT(fmt, ...) std::print("[Prefix] " fmt " [Suffix]\n", ##__VA_ARGS__) While this works, macros have limitations in terms of type safety, debugging, and maintainability, especially for larger projects. Using a Function Template For more flexibility, you can create a function template that wraps std::print() and modifies the format. This way, you avoid the pitfalls of macros while still achieving the same goal: #include <format> #include <iostream> template<typename... Args> void print_with_format(const std::string& fmt, Args&&... args) { std::string formatted_message = std::format("[Prefix] " + fmt + " [Suffix]\n", std::forward<Args>(args)...); std::cout << formatted_message; } Usage: print_with_format("Hello, {}!", "World"); Custom Formatter (Advanced) If you want more control over the formatting process, you can create a custom formatter by extending std::formatter: #include <format> #include <iostream> template <> struct std::formatter<std::string> { constexpr auto parse(auto& ctx) { return ctx.begin(); } auto format(const std::string& s, auto& ctx) { return std::format_to(ctx.out(), "[Prefix] {} [Suffix]", s); } }; void print_with_format(const std::string& message) { std::cout << std::format("{}", message) << '\n'; } This approach gives you deep customization over how different types are formatted. Conclusion • Macros are quick and simple but have limitations in flexibility and maintainability. • Function templates offer a more modern, type-safe, and maintainable solution. • Custom formatters provide advanced control and customization, especially for complex formatting needs. For most use cases, the function template approach strikes a good balance between flexibility and simplicity.
  • 0 Votes
    2 Posts
    917 Views
    zaasmiZ
    @cyberian said in Firefox "A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value ‘undefined’" for Local Server. or Cpanel: with non-Response value ‘undefined’" for Local Server. or Cpanel A ServiceWorker passed a promise to FetchEvent.respondWith The error message “A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value ‘undefined’” usually occurs when a ServiceWorker is not handling requests properly. This can happen if the promise passed to fetchEvent.respondWith() resolves to something other than a Response object or undefined. Here’s how to address this issue, whether on a local server or cPanel: Common Causes and Fixes: 1.Improper Use of respondWith(): Make sure that when using fetchEvent.respondWith(), the promise passed resolves with a valid Response object, not undefined. Example: self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request).then(function(response) { return response || fetch(event.request); }) ); }); In the above code, caches.match(event.request) returns a promise that resolves to a Response object or undefined. If undefined is returned, fetch(event.request) makes a network request, ensuring that a valid Response is always passed. Check if the Fetch Handler is Returning a Valid Response: • Make sure the handler function (e.g., caches.match(), fetch()) always returns something valid, like a cached resource or a network response. • Example of wrong code: event.respondWith( caches.match(event.request).then((response) => { if (response) { return response; } // Forgetting to return a network fetch or response will cause the error. }) ); Fix it by ensuring a response is always returned: event.respondWith( caches.match(event.request).then((response) => { return response || fetch(event.request); }) ); Local Server or cPanel Configuration: • If you’re running the code on a local server or through cPanel, ensure that the server is properly configured to serve the ServiceWorker file (sw.js) with the correct MIME type (usually text/javascript). • Check for proper paths. Ensure that the service-worker.js or similar file is in the correct location and accessible from your site. Example: if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/service-worker.js') .then(function(registration) { console.log('ServiceWorker registered with scope:', registration.scope); }) .catch(function(error) { console.log('ServiceWorker registration failed:', error); }); } Debugging Steps: Check Browser Console: Look for other potential errors that might help pinpoint the issue. Clear Cache: Sometimes the ServiceWorker cache becomes corrupted. Clear the cache and see if the issue persists. • Go to Firefox DevTools > Application > Service Workers > Unregister and clear cache. Update ServiceWorker Script: Ensure the ServiceWorker script is up-to-date and properly handles all fetch requests with valid responses. By following these steps, you should be able to resolve the respondWith error and ensure proper handling of requests in your ServiceWorker.
  • 0 Votes
    2 Posts
    1k Views
    cyberianC
    @Engrnaveed-Saeed said in how to point dns like 2nd level subdomain of subdomain: how to create subdomain in godaddy - youtube how to create subdomain in godaddy without cpanel godaddy subdomain forwarding how to create subdomain in cpanel how to create a subdomain in wordpress godaddy how to create subdomain without cpanel godaddy subdomain mx record google domains To point a second-level subdomain of a subdomain (like level2.level1.example.com) using DNS, follow these steps: Access Your DNS Management System Log in to your DNS hosting provider or control panel where the DNS records for your domain are managed. Add an “A” or “CNAME” Record for the Second-Level Subdomain You can create the DNS entry by adding an A or CNAME record, depending on how you want the subdomain to resolve. For an A Record (Points directly to an IP address): 1. Choose the option to add a new record. 2. Select A Record as the type. 3. In the Name field, input the second-level subdomain in the format level2.level1. This creates a subdomain of a subdomain. 4. Enter the IP address where you want the subdomain to point. 5. Set TTL (time to live) if necessary (default is usually fine). For a CNAME Record (Alias to another domain): 1. Choose the option to add a new record. 2. Select CNAME Record as the type. 3. In the Name field, input level2.level1. 4. In the Value/Target field, enter the domain name (e.g., example.com) to which you want to alias this subdomain. 5. Set the TTL (optional). Ensure the Main Subdomain (level1.example.com) Is Set If level1.example.com does not already exist, make sure to create a DNS record for level1 by adding either an A record or CNAME for it. Save and Propagate After saving the changes, it may take up to 24–48 hours for the DNS changes to propagate fully across the internet. Example: If you want shop.us.example.com to point to a server: • For an A record: • Name: shop.us • Type: A • Value: 192.0.2.1 • For a CNAME record: • Name: shop.us • Type: CNAME • Value: store.example.com Let me know if you need further clarification!
  • 0 Votes
    2 Posts
    4k Views
    cyberianC
    20% Rule for passing a Subject For passing a subject a student is required to meet the following two requirements: A student is required to obtain at least 20% marks in first half i.e. Assignments, Quizzes, Discussions and Midterm collectively and at least 20% in second half i.e. Final Term exam. A student must secure at least 40% marks overall A student will be considered as Pass in the subject if he/she fulfills the above two requirements. Marks distribution: Distribution of marks is according to the Grading Scheme defined by the academics. Student can view subject Grading Scheme in VULMS under “Course Website” heading. Example: Keeping in view the first requirement of 20% rule and following grading scheme: First Half Second Half Net Score Assignments Quizzes GDBs Midterm Final Term First Half + Second Half 10% 3% 2% 35% 50% 100% First half marks = sum of all items like assignments, discussions, midterm, quizzes etc Second half marks = Final term marks. Case 1: More than 20% marks in every half but Net score is less than 40%. First Half First Half Marks out of 50 Second Half Status - Remarks Assignments Quizzes GDBs Midterm Marks Final Term out of 100 Marks out of Marks Marks Marks out of 50 10 out of 3 out of 2 out of 35 6 1 1 10 18 17 35 Fail - Net score less than 40% marks Case 2: Less than 20% marks in first half First Half First Half Second Half Assignments Quizzes GDBs Midterm Marks Final Term Net Score out of 100 Status- Remarks Marks out of Marks Marks Marks out of 50 Marks out of 50 10 out of 3 out of 2 out of 35 3 1 1 4 9 33 42 Fail - First half marks less than 20% Case 3: Less than 20% marks in second half First Half First Half Second Half Assignments Quizzes GDBs Midterm Marks Final Term Net Score out of 100 Status- Remarks Marks out of Marks Marks Marks out of 50 Marks out of 50 10 out of 3 out of 2 out of 35 9 2 2 24 37 8 45 Fail- First half marks less than 20% Case 4: More than 20% marks in every half with overall marks greater than or equal to 40% First Half First Half Second Half Assignments Quizzes GDBs Midterm Marks Final Term Net Score out of 100 Status- Remarks Marks out of Marks Marks Marks out of 50 Marks out of 50 10 out of 3 out of 2 out of 35 9 2 2 24 37 23 45 Pass - Fulfilling the all requirements
Reputation Earning
How to Build a $1,000/Month World CUP LIVE Matches Live Cricket Streaming
Sponsored
File Sharing
Stats

0

Online

3.1k

Users

2.8k

Topics

8.6k

Posts
Popular Tags
Online User
| |