CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

05 May, 2024

Can you defer evaluation of a variable used in a view removal transition?

 Programing Coderfunda     May 05, 2024     No comments   

I've got a parent view that presents one of a couple of views, depending on the value of an observed variable.


In the simple example below, RainbowView is presented when the @Published variable "settings.showRainbow" is true.


The RainbowView sets "settings.showRainbow" to false when the user taps one of the colours of the rainbow, which causes the parent view to remove it, and display another view. The tap location is also set by RainbowView.


When RainbowView is removed, its removal transition animation is to zoom in around the location where the user tapped.


It works perfectly ... except, of course, that the value of the removal transition's .scale anchor, the variable "tapLocation", is set when the view is presented, rather than when it is removed.


What I'd like, is for SwiftUI to wait to capture the anchor location until the point in time where the view is about to be removed.


Does anyone know if this is possible? I could make the child view responsible for animating itself when it's about to be dismissed (which works OK), but I would prefer to have the parent view be responsible for the removal animation.


Here's a code snippet:
if settings.showRainbow {
RainbowView()
.transition(AnyTransition
.asymmetric(
insertion: .opacity,
removal: .scale(scale: 24,
anchor: tapLocation)))
} else {
OtherView()
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Firebase Functions V2 - Use custom domain for http calls [duplicate]

 Programing Coderfunda     May 05, 2024     No comments   

I'm using Firebase functions v2 and I would like to use a custom domain name for HTTP calls. I already searched before posting but all answers are for Firebase functions v1.


Here is the function showed in the Firebase console:

https://-ltnwgqwdfq-uc.a.run.app />


And here is what I would like to achieve:

https://.my-domain.com />


Here is what I tried:


In firebase.json file
{
"hosting": {
"rewrites": [
{
"source": "/api/function-name",
"function": {
"functionId": "function-name"
},
{
"source": "!/@(api)/**",
"destination": "/index.html"
}
]
}
// [...]



I deployed only the hosting part and when I try to run the google cloud function it works well:

https://function-name-ltnwgqwdfq-uc.a.run.app />


But impossible to run the custom domain name function (it redirects me to a 404 HTML page):

https://my-domain.com/function-name
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Two div blocks on same line

 Programing Coderfunda     May 05, 2024     No comments   

How to center on the same "line" two div blocks?



First div:






Second div:
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

04 May, 2024

Uncaught TypeError: Cannot read property 'filter' of undefined

 Programing Coderfunda     May 04, 2024     No comments   

My custom filter is giving me an error.



Uncaught TypeError: Cannot read property 'filter' of undefined



code :

angular.module('PatientApp', []).filter('ageFilter', function() {
// birthday is a date
function calculateAge(birthday) {
var dateOut = new Date(birthday);
dateOut.setDate(dateOut.getDate() + 1);
var ageDifMs = Date.now() - dateOut .getTime();
// miliseconds from epoch
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
return function(birthdate) {
return calculateAge(birthdate);
};
});
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

any alternative to using execCommand("removeformat")

 Programing Coderfunda     May 04, 2024     No comments   

I am trying to add a button that removes format of selected text.
There are several wysiwyg editors available, but I am researching it's implementation from scratch.
execCommand("removeformat") doesn't strip certain tags (h2) but works with (b, em). We can strip each tag.


For example we have


12345





we can select "234" and usind window.getSelection()
we could transform it to


1


234


5





But there is a lot of edge cases. And it is hard to check every case.
If we have a nested DOM structure, it’s difficult to tell using text nodes which tag should be copied from and to which if we select "hello" here.

3 hello 5




the output will could be

3

hello

5




If we selected whole text node we can remove some tags.
123



to
123



It is quite hard to understand how we convert these nodes especially when we selected several text nodes.
We can get text nodes using this approach How to get nodes lying inside a range with javascript?



Are there any libraries that provides those methods
bold, unbold text and removeFormatting or an algorithm.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Different output in VisualStudio and Codeblocks

 Programing Coderfunda     May 04, 2024     No comments   

I need a linear interpolation in 2D array. The output in Codeblocks is correct, but in VisualStudio is not.


I got 2 main functions.




*

Linear interpolation in 1D array:
Function is Y(X) and the result is Y(x).


*

Linear interpolation in 2D array:
Function is Y(X1, X2) and the result is Y(x, y).






And function to test it.
#include
#include
#include

double lin_int(int size, double* X, const double* Y, double x){
int i;
if (x >= *(X + size-1)){
return *(Y + size-1);
} else
if (x = x && *(X + i - 1) *(X1+m) && y > *(X2+n)) return *(Y+m*n-1); //по X1 и X2 больше оба значения x, y - возвращаем Y[m][n]
if (x < *(X1)) x = *(X1); //по X1 значение x меньше X1[0] - ставим x = X1[0]
if (y < *(X2)) y = *(X2); //по X2 значение y меньше X2[0] - ставим y = X2[0]
if (x > *(X1+m-1)) x = *(X1+m-1); //по X1 значение x больше X1[m] - ставим x = X1[m]
if (y > *(X2+n-1)) y = *(X2+n-1); //по X2 значение y больше X2[n] - ставим y = X2[n]
for (i = 0; i < n-1; i++){
if (x == *(X1 + i)){ //Проверка что мы в узле X1
in_X1 = true;
break;
} else
if (x > *(X1 + i) && x < *(X1 + i + 1)) break; //Если не в узле, фиксируем индекс предыдущего узла
}
for (j = 0; j < m-1; j++){
if (y == *(X2 + j)){ //Проверка что мы в узле X2
in_X2 = true;
break;
} else
if (y > *(X2 + j) && y < *(X2 + j + 1)) break; //Если не в узле, фиксируем индекс предыдущего узла
}

if (in_X1 && in_X2) { //Если попали в два узла сетки, возвращаем уже известное значение
return *((Y + i*n) + j);
} else
if (in_X1) { //Если в узле только по X1, возвращаем lin_int между узлами X2
return lin_int(n, X2, (Y+i*n), y);
} else
if (in_X2) { //Если в узле только по X2, возвращаем lin_int между узлами X1
x1 = *((Y+i*n)+j);
x2 = *((Y+(i+1)*n)+j);
if (*(X1+i+1) == *(X1+i)){
return x1 + (x2-x1) * (x-*(X1+i)) / (*(X1+i)*2); //два совпадающих значения в узлах
}
return x1 + (x2-x1) * (x-*(X1+i)) / (*(X1+i+1) - *(X1+i));
} else { //Если ни в какой узел не попали
if (*(X1+i+1) == *(X1+i)){
return x1 + (x2-x1) * (x-*(X1+i)) / (*(X1+i)*2); //два совпадающих значения в узлах
}
x1 = lin_int(n, X2, (Y+i*n), y); //Если не попали ни в какой узел, вычисляем x1, x2 и возвращаем lin_int между ними
x2 = lin_int(n, X2, (Y+(i+1)*n), y);
return x1 + (x2-x1) * (x-*(X1+i)) / (*(X1+i+1) - *(X1+i));
}
}

void test_lin_int_mass(void){
double X1[4] = { 0.3, 1.0, 4.0, 10.0 };
double X2[3] = { 0.0, 90.0, 180.0 };
double Y[4][3] =
{/* 0 90 180 */
/*0.3*/ {1.0, -0.107, -0.5},
/*1.0*/ {1.3, -0.3, -0.7},
/*4.0*/ {1.5, -0.2, -0.6},
/*10.*/ {1.53, -0.253, -0.5}
};

double i,j;
for (i=0; i
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Getting a wrong output all the time

 Programing Coderfunda     May 04, 2024     No comments   

I was just trying out a code for finding whether a number is an Armstrong number or not. But it was getting the same output for all the inputs even it is a Armstrong number. So I used an online compiler and it worked.
#include
#include

int main() {
int originalNum, num, lastDigit, digits, sum;

/* Input number from user */
printf("Enter any number to check Armstrong number: ");
scanf("%d", &num);

sum = 0;
originalNum = num;

/* Calculate the number of digits in the input number */
for (digits = 0; originalNum > 0; digits++) {
originalNum /= 10;
}

originalNum = num;

/* Compute the sum of the cubes of individual digits */
while (originalNum > 0) {
lastDigit = originalNum % 10;
sum += pow(lastDigit, digits);
originalNum /= 10;
}

/* Check if the sum equals the original number */
if (sum == num) {
printf("%d is an Armstrong number.\n", num);
} else {
printf("%d is not an Armstrong number.\n", num);
}

return 0;
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Moonshine is an Open-source Admin Panel for Laravel

 Programing Coderfunda     May 04, 2024     No comments   

---



Moonshine is an open-source package for Laravel offering an admin panel you can use for MVPs, back-office applications, and content management systems. You can make an admin panel with authorization and CRUD in minutes.


Moonshine Demo Admin



Moonshine is a tool for rapid development using the package's CMS features, and other features that make you productive using familiar tools like Blade, Livewire, and Alpine:



* Moonshine helps you create functionality rapidly

* There is no binding to models; you can take whatever data you like

* Form and table builder

* Lightweight and easy to use AlpineJs

* Tailwind CSS and Blade, familiar to the vast majority of Laravel developers

* Ability to use Blade and Livewire components

* Convenient template builder, change colors and overall design






To start with Moonshine, chect out the Installation guide. The documentation is another good place to start, along with the MoonShine 2 video guide.



The post Moonshine is an Open-source Admin Panel for Laravel appeared first on Laravel News.


Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

03 May, 2024

Bag: Immutable Value Objects for Laravel (and PHP)

 Programing Coderfunda     May 03, 2024     No comments   

Hey folks,

I recently published a new package called Bag that provides immutable value objects for Laravel (and PHP in general). It relies on Laravel Collections and Validation and some other parts of the Laravel framework.

It's heavily inspired by spatie/laravel-data, so if you're familiar with it but are interested in the safety of immutable value objects, then you should definitely check out Bag. For a more detailed comparison of the two libraries, check out the Why Bag? page. Full docs can be found here.

I'm gearing up for a 1.0 release (see: the roadmap) and would love y'alls feedback. Feel free to either comment here, or open up issues on the GitHub repo.

You can install it using composer require dshafik/bag.

Thanks for reading, I'll leave you with Bag's cute little mascot:


https://preview.redd.it/tv90hmgt61yc1.png?width=1280&format=png&auto=webp&s=b5bb623104f2993b1ce03fb17633887b4dc69bb0 submitted by /u/dshafik
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What do you use to make API documentation?

 Programing Coderfunda     May 03, 2024     No comments   

I have previously used some packages, which basically generated documentation by getting those giant ugly docblocks above each controller method. What is the standard today? I think ideally I would like to have a directory with json/yaml file for each request/resource, maybe the chance to reuse files that hold responses, and a cli command that generates a pretty page, which search and everything. submitted by /u/iShouldBeCodingAtm
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

I'm still unsure how DeferrableProvider improves performance

 Programing Coderfunda     May 03, 2024     No comments   

Referring to the documentation, it states:

Deferring the loading of such a provider will improve the performance of your application, since it is not loaded from the filesystem on every request.

Based on my understanding, consider this example: class RiakServiceProvider extends ServiceProvider implements DeferrableProvider { public function register(): void { $this->app->singleton(Connection::class, function (Application $app) { return new Connection($app['config']['riak']); }); } public function provides(): array { return [Connection::class]; } }

If laravel instantiates the RiakServiceProvider class and calls the register method (regardless of whether I resolve the Connection::class out of the container), how does it optimize the performance of the application? submitted by /u/foremtehan
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Filament Context Menu

 Programing Coderfunda     May 03, 2024     No comments   

Filament Context Menu Plugin lets you add right-click context menus for faster actions on pages & tables.

Read More submitted by /u/aymanalhattami
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

NativePHP Windows Builds are Here

 Programing Coderfunda     May 03, 2024     No comments   

---



Windows support for NativePHP was announced, which means that you can now build applications for the Windows platform. Windows builds are working, and with that, all platforms will get new versions of PHP to work with.



I know many of you have been patiently waiting for this. Over the months, we've racked up quite a few issues as folks have attempted to find some way to get Windows builds working.


I totally get this enthusiasm, Windows support was always on the cards, but we stated early on that Windows support was going to take a while longer for one main reason: a lack of static builds of PHP for Windows with enough extensions baked in to support booting a Laravel application.



To start building for Windows, update to the latest version of nativephp/electron via Composer:
composer require nativephp/electron



You can now build for Windows even while on another OS using the OS argument via the build command:
php artisan native:build win



Along with Windows support, this release introduces broader support for multiple versions of PHP. This release enables full Laravel 11 support using PHP 8.2 or PHP 8.3 to develop your applications. NativePHP binaries are expected to happen more regularly.


You can learn more about this release from the GitHub discussion. 



The post NativePHP Windows Builds are Here appeared first on Laravel News.


Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

02 May, 2024

Why does S3.deleteObject not fail when the specified key doesn't exist?

 Programing Coderfunda     May 02, 2024     No comments   

Using the AWS SDK for Node, why do I not get an error when trying to delete an object that doesn't exist (i.e. the S3 key is wrong)?



If I specify a non-existent bucket on the other hand, an error is produced.



If you consider the following Node program, the Key parameter lists a key which doesn't exist in the bucket, yet the error argument to the callback is null:

var aws = require('aws-sdk')

function getSetting(name) {
var value = process.env[name]
if (value == null) {
throw new Error('You must set the environment variable ' + name)
}
return value
}

var s3Client = new aws.S3({
accessKeyId: getSetting('AWSACCESSKEYID'),
secretAccessKey: getSetting('AWSSECRETACCESSKEY'),
region: getSetting('AWSREGION'),
params: {
Bucket: getSetting('S3BUCKET'),
},
})
picturePath = 'nothing/here'
s3Client.deleteObject({
Key: picturePath,
}, function (err, data) {
console.log('Delete object callback:', err)
})
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Is there a way to get a model's many to many relationship by reference?

 Programing Coderfunda     May 02, 2024     No comments   

I'm constantly exhausting my PHP's memory limit. I believe it's due to loading too many models into memory. My current setup is works something like this: I have 75 models that have many other related models (~243) that belong to many other related models (~6) with pivot data.

Once we get down to it, I'm looking at 120k+ models loaded into memory. That last set of models being a majority of those but I know there are tons upon tons of duplicates in there.

Is there anyway to call these relationships by reference with eloquent? submitted by /u/pitcherc
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

NativePHP now supports Windows!

 Programing Coderfunda     May 02, 2024     No comments   

submitted by /u/simonhamp
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Is Laravel the most complete out-of-the-box framework?

 Programing Coderfunda     May 02, 2024     No comments   

I do a lot of full-stack solo projects for clients. Simple stuff for the most part, nothing crazy. Mainly for clients who want something more custom and more advanced than a typical Wordpress/Shopify site, but don’t have the capacity to hire a boutique agency or an internal team. So they end up with skilled freelance work as a happy medium.

Most projects involve authentication, database optimization, occasionally caching if a high volume site, and occasionally store-based state management if there is a lot of custom functionality. I use Tailwind and Blade for the front-end views, and write my own controllers and database schema.

So far, I am loving Laravel. Coming from React and Next.Js, it is a breath of fresh air. I can easily scan a page and know exactly what the propose of the functions are, and how they should look. In contrast, most React applications I open look like JavaScript soup for the first 10 minutes while I orient myself.

I never knew I needed separation of concerns and functional programming, but coming from JavaScript frameworks, it is so much easier to develop this way. I only have to focus on one thing at a time, and solutions are usually very straightforward to conceptualize since each function is usually only responsible for a few actions. As an added bonus there aren’t properties being passed down through multiple layers of components which makes debugging much easier.

I don’t think I’ll ever go back to JavaScript frameworks (maybe Svelte or Solid), but this framework has truly made programming fun again.

Are there any other frameworks that can really compete with Laravel from an ecosystem standpoint? It has minimal amount of dependencies, good performance, excellent debugging tools, excellent routing and rendering features, an excellent ORM, and many more features that would have been external dependencies in other frameworks.

I can’t believe it took me this long to find Laravel. I thought it was just a back-end framework and had never really looked into it before a few weeks ago, but I am certainly glad that I did.

Taylor Orwell, you are a God among men. Thanks to you I never have to wonder what tech stack is best for a project anymore, the answer will always be Laravel. Does anyone have a “buy me a coffee” link for him? He definitely deserves it. Probably the only time I’ve been so in awe of a single developer other than when I first played Stardew Valley by Eric Barone. submitted by /u/techdaddykraken
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Replicate Laravel PHP Client

 Programing Coderfunda     May 02, 2024     No comments   

---



The Replicate Laravel package is a PHP client for the Replicate API, an API to run and fine-tune open-source AI models. Here's a quick example from the package's readme of using the Replicate Laravel client:
use HalilCosdu\Replicate\Facades\Replicate;

$response = Replicate::createModel($data)

// Response methods
$response->body(); // string
$response->json($key = null, $default = null); // mixed
$response->object(); // object
$response->collect($key = null); // Illuminate\Support\Collection
$response->status(); // int
$response->successful(); // bool
$response->redirect(); // bool
$response->failed(); // bool
$response->clientError(); // bool
$response->header($header); // string
$response->headers(); // array



At the release of this post, the Replicate Laravel client has the following endpoints:



* Account

* Models

* Predictions

* Trainings

* Model collection

* Deployments

* Model hardware

* And more...






For usage examples, see the complete Replicate API documentation. The Replicate API lets you generate images, text, videos, music, speech, and more using thousands of community models. To start using Replicate Laravel in your own applications, check out this package on GitHub at halilcosdu/laravel-replicate.



The post Replicate Laravel PHP Client appeared first on Laravel News.


Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

30 April, 2024

Dismissibles for Laravel. Handle recurring modals/popups/notifications with ease.

 Programing Coderfunda     April 30, 2024     No comments   

​


https://preview.redd.it/h3zi0m63nmxc1.jpg?width=1254&format=pjpg&auto=webp&s=91a09bcfca986f45ded401b894c80d26973c36bb

Hi, all. I just released my first package: Dismissibles for Laravel. Hopefully it helps some people save time and manage recurring dismissibles with ease! Let me know what you think. submitted by /u/Rellix77
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Laravel-excel Failed to load as a DOM Document 100% Worked

 Programing Coderfunda     April 30, 2024     Excel, Laravel     No comments   

  User the export file and controller function 

..

        libxml_use_internal_errors(true);

..Good To Go


 public function view(): View
    {
       
        $invoices = History::with('abc')->get();
     

        libxml_use_internal_errors(true);      


        return view('export.soaap',compact('invoices'));
       
    }


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

failed to load storage framework cache laravel excel

 Programing Coderfunda     April 30, 2024     Excel     No comments   

   User the export file and controller function 

..

        libxml_use_internal_errors(true);

..Good To Go


 public function view(): View
    {
       
        $invoices = History::with('abc')->get();
     

        libxml_use_internal_errors(true);      


        return view('export.soaap',compact('invoices'));
       
    }


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Failed to load C:\xampp\htdocs\amb\storage\framework\cache\laravel-excel\laravel-excel-qstLPEJphn1YP2RNamob7mesa927XVjT.html as a DOM Document

 Programing Coderfunda     April 30, 2024     Excel, Laravel     No comments   

 User the export file and controller function 

..

        libxml_use_internal_errors(true);

..Good To Go


 public function view(): View
    {
       
        $invoices = History::with('abc')->get();
     

        libxml_use_internal_errors(true);      


        return view('export.soaap',compact('invoices'));
       
    }


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Listing pods associated with a deployment

 Programing Coderfunda     April 30, 2024     No comments   

How do I get a list of all pods associated with a deployment? In the GUI, it's as simple as clicking on the deployment and checking the pods tab. However, I can't find a way using the CLI.


I've tried using a script that uses string matching to check if the pod name begins with the deployment name, but it's not really sufficient due to the possibility of deployments beginning with the same string.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

disable global middleware from some pages - nuxt 3

 Programing Coderfunda     April 30, 2024     No comments   

When you set the middleware as global, and let's say myMid.global.ts, there are some pages on which I do not want this middleware to work. I searched and found a way using route name, and I want a better way. For example, on the page where I do not want it to work, I put, for example:


some-ex-page.vue :


definePageMeta({
myMid : false
});





Or anything else. Most pages need this middleware, but there are pages that do not. I do not think it is a good idea to go through all of these pages and manually enter the name of the middleware:


some-ex-page.vue :


definePageMeta({
middleware : ["myMid"]
});





Or, for example, there is a way to add a new property to the page. In the middleware, I can check that if this property exists, I will avoid working from this page.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

29 April, 2024

HTML::Element endtag generates end tags for and

 Programing Coderfunda     April 29, 2024     No comments   

I'm using the following Perl code to traverse and format some HTML:
#!/usr/bin/env perl
use v5.38;
use HTML::TreeBuilder;
my $indent = 3;
my $content = do {local $/; };
my $tree = HTML::TreeBuilder->new();
$tree->parse_content($content);
visit($tree);

sub visit($x) {
my $depth = $x->depth;
my $in = ' ' x ($indent * $depth);
foreach my $e ($x->content_list) {
# element
if (ref ($e)) {
say $in . $e->starttag;
visit($e);
say $in . $e->endtag;
}
# text
else {
say $in . $e;
}
}
}
__DATA__







5/5/61 Bob & Jerry - Arroyo Lounge, Stanford University, Palo Alto, CA




(Robert Hunter and Jerry Garcia; source: McNally, Jackson research)





5/26/61 Bob & Jerry - Barbara Meier's 16th birthday party, Menlo Park, CA



Follow The Drinking Gourd, John Henry, Santy Anno*, Poor Paddy Works On The Railway


(*included on
Before The Dead
;
birthday doodle for Barbara by Jerry
;
the master tape

)







My problem is that each
is output as:






Both
and cause new lines to be rendered. I was surprised that endtag generated anything at all in the case of tag br (and img).


I avoided using HTML::Tree::traverse because the doc discourages its use:



[I]f you want to recursively visit every node in the tree, it's almost
always simpler to write a subroutine does just that, than it is to
bundle up the pre- and/or post-order code in callbacks for the
traverse method.



There are no examples given, so the above is what I cooked up.


Am I using starttag and endtag correctly? Should I detect when I'm displaying a tag that doesn't take an end tag and avoid calling endtag? What's the right/best/simplest way to traverse an HTML tree and prettify it?


Update:


As suggested by Stephen Ullrich, I tried to use as_HTML() for formatting:
#!/usr/bin/env perl
use v5.38;
use HTML::TreeBuilder;
say "\%HTML::Element::optionalEndTag= ",
join ', ', keys %HTML::Element::optionalEndTag;
my $content = do {local $/; };
my $tree = HTML::TreeBuilder->new();
$tree->parse_content($content);
# don't encode any entities; indent with three spaces;
say $tree->as_HTML('', ' ');
__DATA__







5/5/61 Bob & Jerry - Arroyo Lounge, Stanford University, Palo Alto, CA




(Robert Hunter and Jerry Garcia; source: McNally, Jackson research)





5/26/61 Bob & Jerry - Barbara Meier's 16th birthday party, Menlo Park, CA



Follow The Drinking Gourd, John Henry, Santy Anno*, Poor Paddy Works On The Railway


(*included on
Before The Dead
;
birthday doodle for Barbara by Jerry
;
the master tape

)







Output:
%HTML::Element::optionalEndTag= dt, dd, li, p





5/5/61 Bob & Jerry - Arroyo Lounge, Stanford University, Palo Alto, CA
(Robert Hunter and Jerry Garcia; source: McNally, Jackson research)


5/26/61 Bob & Jerry - Barbara Meier's 16th birthday party, Menlo Park, CA
Follow The Drinking Gourd, John Henry, Santy Anno*, Poor Paddy Works On The Railway
(*included on Before The Dead ; birthday doodle for Barbara by Jerry ; the master tape )








Unfortunately, this isn't "pretty" enough. I don't understand why the indenting leaves off after the first couple of levels. However, I do note that it doesn't generate or , despite the fact that neither of these tags is mentioned in %HTML::Element::optionalEndTag!
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to prevent Firebase Authentication creating a new user implicitly on first sign-in?

 Programing Coderfunda     April 29, 2024     No comments   

I have a Firebase backed React Native application which allows customers to sign in via email/password, Google ID or Apple ID. It's mainly working fine but I've noticed a UX problem which stems from the behaviour of the signInWithCredential method which creates a new user implicitly on first sign in.



You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.

https://firebase.google.com/docs/auth/web/manage-users#create_a_user />


This seems handy and meant my "register" or "sign up" function was basically the same as my "login" function.


However from the customer's perspective it's confusing. E.g. if they come to the app and forget they used email/password to sign-up and click "Sign in with Google", click accept in the OAuth popup, then they get logged in to a brand new account they've never used before and of course their previous data/history/purchases are absent.


If a new customer signs in via OAuth, I want to receive the auth/user-not-found error as listed in the API docs here so that I can present the "normal" UX of saying "You don't have an account with those credentials, please sign up first" or similar to apply some friction and help the user to realise they're on the wrong path. i.e. I want sign up to be completely independent from sign in and prevent accidental, spurious accounts being created.


BTW I understand (and have tested) that if a customer subsequently uses a second provider which shares the same email address already registered, then Firebase does some clever stuff to migrate or unify the accounts. But I can't be sure a customer's Google ID would match the email they used with an email/password account creation (e.g. work vs personal or other reasons) so there would still be duplicate/spurious accounts. There's also the "one account per email" option to tweak this)


I actually find it curious that there don't seem to be any discussions about this, as the lack of a "don't auto-register" flag prevents a typical UX supporting a clear difference between "new here? signup" onboarding vs. "got an account? login" for existing customers. So perhaps I'm missing something obvious.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Laravel vs. Next.js: Addressing Client Inquiries

 Programing Coderfunda     April 29, 2024     No comments   

Hey everyone,

Clients often inquire why I tend to favor Laravel over other frameworks for certain projects. Honestly, it often comes down to personal preference rather than a strictly technical decision. I simply have a fondness for Laravel's extensive ecosystem of packages, which not only streamlines development but also provides a robust backend solution.

That being said, there are instances where I could easily use Next.js for all aspects of a project. However, despite its versatility, I find myself gravitating towards Laravel for its familiarity and the comfort it brings to my workflow.

I'm curious to hear if clients have asked you why you choose Laravel and how do you articulate its benefits to them?

Looking forward to hearing your thoughts! 🚀 submitted by /u/One-Philosophy-1362
[link] [comments]
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How do I run a scheduled AWS Fargate task as a one-off?

 Programing Coderfunda     April 29, 2024     No comments   

For a system I'm building, I have set up an AWS scheduled Fargate task through the python cdk. This task is started every hour and retrieves events from the past hour from some external endpoint to further process. This scheduled task works to satisfaction.


Now, I want to also be able to run this task on demand. This will be for initial loads where (much) more than one hour of event data is to be retrieved, or for corrective loads when the sheduled task has failed for any reason. These will probably not need to happen more than about once each two months.

---



Is there a way I can create a one-off task, preferably with altered environment variables, from my already-defined scheduled Fargate task? This one-off task should then be able to be started ad-hoc from the AWS dashboard.

---



As it stands, I can manually start a new one-off task from the task definition I created for the scheduled Fargate task. But this requires the user (which won't always be me) to specify all sorts of parameters like selecting the vpc, subnets, and environment variable overrides. I'd rather reuse those specified for the scheduled fargate tasks, or have them stored somewhere, so that these don't need be entered manually. Is this possible?


Related questions




I feel my question is similar to this one, but the page linked to in that answer does not really tell me how to accomplish a one-off or "standalone" task through the cdk.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Send message via CANBus

 Programing Coderfunda     April 29, 2024     No comments   

After some years developing for mobile devices, I've started developing for embedded devices, and I'm finding a new problem now.
This embedded device has the same peripherals as a mobile phone, ie, WiFi, BT, USB, etc. but it also has a CANBUS connector, and I need to communicate through it.


The problem I'm facing is that I don't find much information of how to do this.


I would appreciate if anyone who has experienced with it could show me the way of doing it, at least, how can I start with it. The basic functionality that I need to achieve is to send a basic message through CANBUS from the embedded.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

11 April, 2024

Create Reusable Blade Components in Laravel

 Programing Coderfunda     April 11, 2024     No comments   

In Laravel, reusable Blade components provide a convenient way to encapsulate UI elements and logic for reuse across your application. Let's walk through creating and using reusable Blade components in Laravel: 1. **Create a Component:** To create a Blade component, you can use the `make:component` Artisan command: ```bash php artisan make:component Button ``` This command will generate a new Blade component class in the `app/View/Components` directory. 2. **Define Component Logic:** Open the generated component class (`Button.php` in this case) and define the logic for your component. This includes properties, methods, and rendering logic. ```php <?php namespace App\View\Components; use Illuminate\View\Component; class Button extends Component { public $type; public $text; public function __construct($type = 'primary', $text) { $this->type = $type; $this->text = $text; } public function render() { return view('components.button'); } } ``` 3. **Create the Blade View:** Next, create the Blade view file for your component. By default, Laravel expects this file to be located in `resources/views/components`. So create a file named `button.blade.php` in that directory. ```blade <button class="btn btn-{{ $type }}">{{ $text }}</button> ``` 4. **Use the Component:** You can now use your component in any Blade view by using its tag name. For example: ```blade <x-button type="primary" text="Click me" /> ``` This will render a button with the specified type and text. 5. **Passing Data to Components:** You can pass data to your component by adding public properties to the component class. These properties can be set when you include the component in your Blade views. 6. **Reusing Components:** You can reuse your component across your application wherever needed. Simply include the component tag with the desired properties. By following these steps, you can create reusable Blade components in Laravel to keep your UI code organized and DRY (Don't Repeat Yourself).

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Meta

Popular Posts

  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • Credit card validation in laravel
      Validation rules for credit card using laravel-validation-rules/credit-card package in laravel Install package laravel-validation-rules/cr...
  • iOS 17 Force Screen Rotation not working on iPAD only
    I have followed all the links on Google and StackOverFlow, unfortunately, I could not find any reliable solution Specifically for iPad devic...
  • C++ in Hindi Introduction
    C ++ का परिचय C ++ एक ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग लैंग्वेज है। C ++ को Bjarne Stroustrup द्वारा विकसित किया गया था। C ++ में आने से पह...
  • Python AttributeError: 'str' has no attribute glob
    I am trying to look for a folder in a directory but I am getting the error.AttributeError: 'str' has no attribute glob Here's ...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • July (2)
  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda