In 2014, during the Hacker Way conference, Facebook introduced Flux architecture as an alternative to MVC.
Flux architecture is a software design pattern that helps manage the flow of data in complex applications.
It provides s unidirectional data flow, which makes it easier to understand, maintain, and debug applications.
1. What is Flux architecture
Flux is an architectural pattern proposed by Facebook.
These are four parts: Actions, Dispatcher , Stores, Views
Actions: Contains all information necessary to do some action
Dispatcher: Is a Single Object that broadcast (actions) to all stores
Stores: Manages the state ( data ), the store is an event emitter
Views: Is the user interface component, Views listen for store changes
2. Flux architecture with QML
Views: Are QML files
Actions: Is a Data type that include event name and data
Dispatcher: Is Singleton design pattern that is control center forward actions to all stores
Stores: Use C++ models with QML
The following application creates a Data Object class with Q_PROPERTY values that will be accessible as named roles when a QList<DataObject*> is exposed to QML
3. Why do we should use Flux architecture
Today, there are two popular architectures : MV*( Model-View-Control, Model-View-Presenter, …) and flux
Comparison table between MVC and Flux architecture
VBA stands for Visual Basic Application, which is a basic programming application in Microsoft Office. For someone who doesn't know about programming or IT, we will be a little confused when hearing about the concept of of VBA, right? However, it's actually more accessible than you think.
Laravel - Some tips to optimize Laravel's performance
Laravel has been a famous framework since 2011. This framework can help us develop a project faster than it did with a lower effort. But one of the most important things when we use a framework is performance.
Luckily, Laravel has supported many helpful features to optimize performance (Redis, Memcache, DB support, etc).
There are many factors that can negatively affect your web application, including poor code quality, inefficient server configurations, and insufficient resources.
However, we can use some tips to improve your website.
1. Update to the latest version of PHP and Laravel
It seems quite obvious but it is the simple way to improve your web application. This may be a challenge with a large legacy application while updating the version. But using the latest version can help us with numerous benefits: new features, bug fixes, and security.
2. Using the Artisan Command
One of the best features in Laravel is called Artisan. Artisan is a command-line tool. It will improve your web performance if you use it in the right way. The easy way is that you can cache the route as well as config with a command line.
php artisan config: cache
php artisan route: cache
Route Caching: This is a critical tool, especially for applications that have a large number of routes. With caching, Laravel only refers to the file where the cached routes are stored (bootstrap/cache/routes.php) instead of rendering all the routes in your website (This will cause slow performance).
Config Caching: Similar to route caching, it will find all data of the config file and variables of .env file then store it in bootstrap/cache/config.php
Remember that you need to run the command above if you have changed any in the config file or route file. To clear the cache, you can run these commands:
php artisan config: clear
php artisan route: clear
3. Remove unused service
The key goal of Laravel is to bring an easy development process to the developers.
When launching Laravel, it will auto-load many service providers listed within the config/app.php file to help you get started with your project.
In addition, many developers don’t want to follow the default framework settings. So it’s necessary to delete unused services to improve your project performance.
4. Eager Loading
All of the queries in Laravel are lazy queries when you execute. It only fetches the required data. Sometimes, this will increase the number of queries and cause low performance for your website. You will run up to N+1 queries to find your response.
To resolve the N+1 queries problem, Laravel provides us with a feature that can use eager loading to load the data to help us improve performance.
Let's compare the source code of two loading modes:
Lazy Loading: You will need to execute multiple queries to find the response you need.
$books = Book::all(); // Get all books
foreach($books as $book) {
echo $book->author->name // Executing query to find author link with book
}
Eager Loading: You only need to execute once.
$books = Book::with('author')->get(); // Get all books link with author
foreach ($books as $book) {
echo $book->author->name // Not execute query again to find
}
Conclusion
Laravel is a fast-growing PHP framework, that has many useful features to support users to improve the performance of their websites.
Hopefully, some tips that I introduced above can help you somewhat in optimizing your website performance.
If you’re coding Laravel with VS Code, extensions are the most important factor that we need to install before starting the project.
Following are some of the best VS Code extensions for Laravel developers. These extensions will help you boost your productivity and ease your development.
1. Laravel Blade Snippet
This extension adds the syntax highlight which supports your VS Code.
Some key features of the extension:
Blade syntax highlight.
Blade snippets.
Blade formatting.
Emmet works in blade template.
To change the setting of Laravel Blade Snippet, go to Preferences and select Settings, then config in JSON file like the following
"emmet.triggerExpansionOnTab": true,
"blade.format.enable": true,
There are some syntaxes that Laravel Blade Snippet supports:
Trigger
Snippet
b:php
@php
// code
@endphp
b:section
@section
// code
@endsection
b:include
@include(...)
b:if
@if (condition)
// code
@endif
b:if-else
@if (condition)
// code
@else
// code
@endif
b:for
@for (...)
// code
@endfor
b:foreach
@foreach (...)
// code
@endforeach
2. Laravel Extra Intellisense
This extension supports autocomplete these features:
Route names and route parameters.
Views and variables.
Configs.
Translations and translation parameters.
Laravel mix function.
Validations rules.
View sections and stacks.
Env.
Route Middlewares.
Asset.
Blade directive.
It helps us find the name of that config easily so that we don’t need to search in the directory tree. We only enter the key that we remember and this extension will remind us of another.
3. Laravel goto view
This is a simple extension. It can help you quickly jump to another file view, no matter where you are.
If you want to jump to another, we use the keystrokes “Ctrl + Click” or “Alt + Click”. Besides that, in case you want to customize more extensions, you can go toPreferences > Settings > Extensions/Laravel goto view configuration, and then add the extension that you want to customize. Here is the configuration JSON:
"laravel_goto_view.extensions": [
".blade.php",
".vue",
]
4. Laravel goto Controller
Finding a controller can be difficult when your application grows with a number of different controllers. Then, using this extension will help you reduce the time spent searching, you can quickly jump to the controller from the route config file without having to find the exact controller name.
The usage is the same as keystrokes in the Laravel goto view to jump to the respective controller file from the routes file.
Conclusion
These extensions will help you to boost productivity. It helps us save a lot of time and make the development project easier. Thus, using extensions in a project is always useful.
If you are excited about all the mentioned extensions above, you can take a look at the Laravel Extension Pack for Visual Studio Code. If you are interested in more extensions, I suggest you try these extensions: Laravel Blade Spacer, Laravel Artisan, Laravel Model Snippets, PHP Intelephense, PHP Constructor, etc.
Why Testers and Developers Have Different Mindsets
Testers and developers play crucial roles in software development, but their mindsets differ significantly. Developers focus on creating and building the software, while testers focus on detecting issues. This difference in focus leads to distinct mindsets that influence their approach to work.
Developer Mindset:
Creativity and Problem-Solving: Developers are creative problem-solvers who enjoy tackling complex challenges. They approach programming with an analytical mindset, devising smart solutions to technical problems. They enjoy the challenge of transforming ideas into working software.
Attention to Detail and Precision: Developers meticulously craft code, ensuring accuracy and consistency. They strive for high-quality code that is efficient, reliable, and maintainable. Attention to detail is essential to prevent bugs and maintain software integrity.
Focus on Functionality and Features: Developers prioritize creating software that meets the specified requirements and delivers the desired features. They typically work closely with the requirements provided by business analysts or product owners.
Tester Mindset:
Critical Thinking and Suspicion: Testers adopt a critical mindset, questioning assumptions and challenging the status quo. They approach testing with a healthy dose of skepticism, seeking out potential defects and inconsistencies. This mindset is essential to uncover hidden issues and ensure software quality.
Attention to Edge Cases and Unexpected Behavior: Testers excel at identifying edge cases and challenging the boundaries of the software. They meticulously explore various scenarios and inputs, anticipating potential issues that might arise under unusual conditions. This approach ensures that the software can handle real-world usage scenarios effectively.
Emphasis on Usability and User Experience: Testers not only evaluate the functional aspects but also consider the software from the user's perspective, ensuring that it is easy to use, intuitive, and user-friendly. They focus on identifying usability issues, such as confusing interfaces or lack of clarity, to enhance the overall user experience.
In summary, the differing mindsets of testers and developers reflect their distinct roles in the software development process. Developers are driven by creativity, problem-solving, and attention to detail, while testers prioritize critical thinking, edge case analysis, and usability considerations. Combining the strengths of both roles helps create a more comprehensive and reliable end product.
Visual Studio Code is a useful programming tool, it supports almost all popular programming languages: Python, JavaScript, HTML, CSS, TypeScript, C++, Java, PHP, Go, SQL, Ruby, ...
Another thing regarding language support is that documentation for popular programming languages in homepage. Shows that the development direction of this editor is aimed at all programmers, regardless of what programming language or field they use in the programming industry.
It can be said that it is one of the software with the richest extension store with thousands of extensions of all types such as programming languages, themes, services,...
VS Code extensions let you add languages, debuggers, and tools to your installation to support your development workflow.
In my work, I have found some extensions to be particularly useful, so I would like to share them with everyone below.
The first: I will introduce about install
+ Find and install an extension:
In the Extensions, input 'code' the search box to filter the Marketplace offerings to extensions with 'code' in the title or metadata.
You can see this extension and choose what you want use.
Some useful application for developers:
1.Git Graph
- Introduce:
View a Git Graph of your repository, and easily perform Git actions from the graph.
Normally we will use some tools like Tortoise Git, Source Tree, Git Base to manage our git,
track commits, merge requests, see git branches, people committing code,...
The purpose is to know where the information about these branches will come from, when they committed, and who committed them in a clear diagram with easy-to-see colors.
To meet this need, we will have an extension called Git Graph, we can use the extension to review all necessary information without using other external tools.
If Git Graph helps us review all the information through the commit schedule.
But it has a limitation: to view information, we need to click on the menu of this extensions , and only view each file.
On the contrary, GitLens can help us see information about each line of code: who wrote this line of code, what date it was committed, branch name, version ,...
We just need to click the cursor directly on that line of code to see the information
- Install: Menu Extensions-> Search GitLens -> Click Install Button
3. Rainbow Tags
- Introduce:
Rainbow Tags are extremely useful Extensions, especially for web programmers, for pages with too much html code.
It is difficult for us to check the opening and closing of tags, parent tags, and child tags.
Rainbow Tags will help us review code easily, the tags are colored differently for each level, there will be no color overlap if the same type of tag
Then we will easily see the opening and closing of this tab. Color will make us feel more interested in programming
- Install: Menu Extensions-> Search Rainbow -> Click Install Button
4. Lines of Code (LOC)
- Introduce:
At the end of the project, we will have an extremely important job: to summarize the number of lines of code of that project.
This is for the purpose of accurately evaluating and making statistics about our projects to report to superiors, customers, to evaluate KPIs, Sales,...
And Lines of Code will support us very well in this.
Lines of Code can be listed by file or by entire project: total number files, number code, number of comment lines, number of blank lines
The results are exported as json files and txt files
- Install: Menu Extensions -> Search Lines of Code -> Click Install Button
For Vue programmers, a great excel file creation library with full format is required. It's Excel4node.
Excel4node is a node.js module that allows you to create and manipulate Microsoft Excel spreadsheets.
It's easy to use as generating Excel files with complex formatting, formulas, and charts, hide sheet, protection sheet,...
Strength
1. Simple: it is simple to makes it easy to generate Excel files in just a few lines of code.
2. Formulas: can add and edit formulas in your spreadsheet.
3. Charts: can create charts and graphs in your Excel files.
4. Flexibility: allows to create and modify Excel files with a variety of formatting options, including cell alignment, font style and color, and background color.
Weakness
1. Read: don't support function read file in lib, must use other lib to read.
2. Environment: some time, when export at other environment and get it to read have problem.
Demo
I would like to show you how to use it in Vuejs.
The first : We need to install package excel4node
+ Open cmd of windows and go to project: I use project Demo in here D:\.
cmd : D:\Demo\web>npm i excel4node
+ Import the library into the project : To use this library, We need import it to project.
// Require library var xl = require('excel4node');
+ Create file excel with sheet name [sheet 1] with 5 column and 3 row have special template
+ Create css common apply for excel : border color 000000, style thin , font-size = 11, font family MS PGothic
+ Apply column B to column F , Line 2 to line 5
// Apply
ws1.cell(2, 2, 5, 6, false).style(styleBorder)
+ Add data to column
B2 :
. have text : Text demo 1
. (text bold) : text is bold
. text red) : text is red color C2 :
. have text : Text demo 2
. (text bold) : text is bold
. text red) : text is red color
D2 :
. have text : Text demo 3 E2 :
. have text : Text demo 4 F2 :
. have text : Text demo 5
+ Finally we will get the excel file as expected :
Column B to column F , line 2 to line 5 : have border
Column B to column E , line 2 to line 5 : have background #fcd5b4
Column B and column C , line 2 have text data as format
Nowadays, developing a software project requires many processes. To reduce time and improve product quality. One of the most widely applied processes today is CI/CD.
So what is the meaning of CI/CD? What are the benefits of the CI/CD process?
Let's find out together!
1. What is CI/CD?
The CI/CD (Continuous Integration/Continuous Delivery) process is a method used to deploy software regularly by applying automated methods during the software development process. The main idea of CI/CD is to continuously perform software integration, migration, and deployment on a regular basis.
This process includes the following steps:
Build: Build based on the source code and add new features.
Test: In-depth testing of newly changed features and code.
Deliver: Codes and features that have been tested will be put into the testing environment.
Deploy: New changes and features are deployed in the final product to users.
The CI/CD process helps integration happen faster and the finished product is delivered to users in the shortest time.
Currently, CI/CD has been widely applied to the workflow of businesses in the IT field, along with DevOps and Agile.
2. Why use CI/CD?
The CI/CD process helps automate software development and faster product deployment. It helps software development teams test, integrate, and deploy products continuously and synchronously. This enables software development teams to focus on creating higher-quality products while reducing the time and cost of product development.
The benefits of a CI/CD process include:
Increase productivity: CI/CD processes enable software development teams to focus on creating higher-quality products while reducing product development time and costs.
Minimize errors: The CI/CD process helps software development teams check and handle errors during product development quickly and effectively.
Increased stability: CI/CD processes enable software development teams to continuously test and verify product stability, ensuring that the product always performs well.
Increase reuse: The CI/CD process enables software development teams to create reusable components that are tested and verified for stability, saving time and costs in the process. product development process.
3. Disadvantages.
Although the CI/CD process has many benefits, there are also some disadvantages.
Here are some disadvantages of the CI/CD process:
Security: CI/CD pipelines can encounter security issues, including security vulnerabilities and issues related to identity management.
Resources: The CI/CD process requires many resources, including servers, tools, and human resources.
Implementation difficulties: Deploying a CI/CD pipeline can present many difficulties, including integrating tools and managing software versions.
Difficulty of change: Changing the CI/CD process can be fraught with difficulties, including changing tools and managing software versions.
4. Software\tools commonly used for CI/CD process.
Currently, there are many tools used for the CI/CD process.
Here are some common tools used in the CI/CD process:
Jenkins: Jenkins is a popular open-source tool for deploying CI/CD.
GitLab CI/CD: GitLab offers CI/CD integration within its source code management platform.
Travis CI: Travis CI is a CI/CD integration service commonly used in the open-source software development community.
CircleCI: CircleCI is a CI/CD integration tool widely used in enterprises.
TeamCity: TeamCity is a CI/CD integration tool developed by JetBrains.
Conclusion:
CI/CD is closely related to Agile and DevOps. The combination of CI/CD, Agile, and DevOps creates a flexible, optimized, and high-performance software development process.
Hopefully, through this post, you will have an overview of what CI/CD is and the benefits of CI/CD.
[Reference Source]
https://www.portainer.io/blog/best-ci/cd-concepts-for-devops (Source of images)
Some Tips And Tricks In Javascript Help You Code Easier
JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.
To help everyone handle things more simply in JavaScript, I would like to introduce some tips and tricks that I have learned.
1. Every and some function:
every function returns a boolean value. If all elements in the array satisfy the condition, it returns true. Besides, some function only checks if there exists at least one element in the array that meets the condition and returns true.
const numberArray1 = [2, 4, 6, 8, 10];
const numberArray2 = [2, 4, 5, 8, 10];
const isEvenNumber = (number) => {
return number % 2 === 0;
}
console.log(numberArray1.every(isEvenNumber)); // return true (because all elements in this array satisfy the condition)
console.log(numberArray2.every(isEvenNumber)); // return false (because there is an element 5 that does not satisfy the condition)
console.log(numberArray1.some(isEvenNumber)); // return true (there exists an element that satisfies the condition)
console.log(numberArray2.some(isEvenNumber)) // return true (there exists an element that satisfies the condition)
2. Convert from Number to Boolean:
Declaring a variable with a boolean value, in addition to the usual declaration (giving the value of the variable true or false), can be done in the following way.
const isTrue = !0;
const isFalse = !1;
const alsoFalse = !!0;
console.log(isTrue); // return true
console.log(isFalse); // return false
console.log(alsoFalse); // return false
3. Convert to String type:
With other programming languages, we can convert numbers to strings using the toString() function. Although Javascript is the same, there is another faster way to do it.
const string = 1 + '';
console.log(string); // return '1'
4. Convert to Number type:
In Javascript, there are many ways to convert from String to Number. For example, parseInt(),... But there is a shorter way to do this, which is to use the ( + ) operator.
const value = '10';
value = +value;
console.log(value); // return 10
console.log(typeof value); // return 'number'
5. Convert from Decimal to Integer:
If you want to convert from a decimal number to an integer, you can use Object Math functions like Math.floor(), Math.ceil() or Math.round(). But the fastest way to do this is to use the bitwise OR ( | ) operator.
console.log(10.9 | 0); // return 10
console.log(10.1 | 0); // return 10
6. Use splice() instead of delete:
When using the delete method, an application replaces an item with undefined instead of removing it from the array. So it is better to use splice() to remove an item from an array.
There are many situations where you have to combine two or more data sets from different sources. In such cases, there are ways to do this in JavaScript.
An important note is that duplicate keywords will be overwritten on previous objects.
Conclusion:
Like any other programming language, JavaScript has many tips and tricks to handle Objects, Arrays, etc., allowing us to write our programs simpler and more beautifully without using functions, and verbose methods. Hope it will be of some help to those of you who are learning Javascript.
Tips to communicate and work effectively with Japanese
Working in a Japanese company and coming into contact with the Japanese side, surely you will gradually get used to the personality and working style of Japanese people. However, each person's personality and working style are different, so getting along with everyone is not easy.
The purpose of this post is to share a little of my experience in nearly 10 years of supporting project members to communicate with Japanese members (members of parent company).
For me, to communicate and work effectively with the Japanese side, we need to pay attention to the following points:
Always in time
Punctuality is a habit that is deeply ingrained in each individual and gradually becomes an implicit rule, a basic consciousness. Japanese people always avoid bothering others. Therefore, being late for an appointment is considered impolite behavior, causing harm to others. Being on time is the right thing to do in every situation.
Therefore,
Pay attention to the time in everything.
Remember the meeting time and always arrive at least 10 minutes before.
Whatever time you report to do (release, submit report, etc.), remember to do it on time. In a force majeure situation, at the time you discover that you cannot respond in time at the reported time, you must immediately contact the Japanese side and explain the situation (reason, cause, etc.) fully.
Create a habit of greeting
The greeting in different situations will have different ways of saying it, and Japanese greetings are extremely important in daily life and communication. Therefore, we must pay attention when communicating with Japanese people, remember to say the greeting no matter what you do.
For example,
When sending email or chat message:
Type
Japanese
English
Opening greeting
お疲れ様です
Thanks for your effort
お忙しいところ失礼致します
I apologize for the inconvenience
昨日は遅くまでお疲れ様でした
Thank you for staying up late yesterday
Closing greetings
以上、よろしくお願いいたします
Thank you very much for your understanding
ご検討をお願いします
Please consider this
ご連絡お待ち申し上げます
We look forward to hearing from you
When meeting online:
Type
Japanese
English
Opening greeting
おはようございます
Good morning
お疲れ様です
Thanks for your effort
お久しぶりです
Long time no see
Closing greetings
ありがとうございました
Thank you very much
お疲れ様でした
Thanks for your hard work
失礼いたします
Excuse me
Don't be surprised to hear the word “Sorry” a lot
While Vietnamese people only thank when they receive a favor and apologize when they cause something really annoying to others. For Japanese people, constantly using the phrase "Sorry" is a daily habit, their minimum politeness. Therefore, you do not need to be surprised when the story always starts.
申し訳ございませんが、(I'm really sorry but …)
Therefore, when working with Japanese people, do not think too deeply about the word "Sorry", consider it just a word used to say hello.
Listen patiently and don't be afraid to confirm
With the above mindset of avoiding offending others, Japanese people rarely say "No" to people who are not close to them. Instead, they often talk in circles and hope to receive the other person's understanding when communicating. They do not express their feelings and thoughts clearly but always keep those feelings within a very vague limit. Therefore, it is not easy to know what the other person is thinking or feeling.
For example, when making a request, they won't say "I want you to do this" right away but will explain the context surrounding the request. And they won't say directly "you should do this", but they will say "I think we should do this". That's why many times the interpreters are confused after hearing the request, not knowing what they want them to do in the end. At that time, your job is to confirm the request again if you do not understand the request clearly.
For example, you can confirm that "So we understand that we will do ABC, right?" If they confirm that you got it right, then just do it. If you make a mistake, they will explain again until you understand what they want.
Please listen patiently and confirm if you do not understand clearly.
Should not directly say "No"
If you pay attention, you will see that it is very rare for Japanese people to answer you "No" right away, because they care about your feelings, so instead of bluntly saying "No", they will be more flexible. They will say "I think it's unlikely, but I'll reconsider" for example.
To respond to this gentle behavior, we should do the same, right? For example, when receiving a request, even if you know 80% of it is "impossible", instead of bluntly answering "No, we can't do it, it's too unreasonable", please answer that "I understand your request, but because we need more research, we cannot answer you right away. Please give me some time, we will reply to you as soon as we have the results of the investigation."
Why do you need to do that, because if you immediately answer "We can't", firstly, with a blunt "No" answer they will be shocked, secondly if they ask you again "Why can't you do it? Can you explain right at that time why it's not possible? Can you give a basis for what you say?”
Therefore, based on the investigation results, it will help them understand your "impossible".