Steps:
Open your projects app/build.gradle file and add the plugin by adding apply plugin: ‘kotlin-kapt’ just above the line with android { as shown below:
apply plugin: 'kotlin-kapt'
android {
Now, we enable data binding by adding
dataBinding{
enabled true
}
inside android { } And then add kapt com.android.databinding:compiler:3.1.4’ to the dependencies.
Finally the build.gradle file should have the following configuration:
apply plugin: 'kotlin-kapt'
android {
dataBinding{
enabled true
}
}
dependencies {
kapt 'com.android.databinding:compiler:3.1.4'
}
The project is now configured for data binding. To use data binding let’s take the example of the empty project that can be created using Android Studio. Here I will show you after the configuration what you need to do.
First wrap your existing layout file inside a layout tag. Move the xmlns attributes to the layout tag. And also add a data tag inside layout tag. Example:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Build your project. Now in your MainActivity.kt, you can create the binding variable as
private lateinit var binding: ActivityMainBinding
The type of the binding variable is after the name of the xml layout’s filename. Here the layout file name is activity_main.xml. Therefore the binding datatype is ActivityMainBinding. This is obtained by removing the underscore and writing the filename in CamelCase with Binding appended.
Now we can initialize the variable as
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
The project is configured for data binding. Let’s take a simple example of databinding. We will create a variable inside data tag in the layout xml.
<data>
<variable
name="message"
type="String" />
</data>
And then we can use the variable inside the views. For example:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{message}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Now in the MainActivity.kt file we can mutate the variable. as
binding.message = "Data Binding Example"
The final activity_main.xml file is :
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="message"
type="String" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{message}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
and the final MainActivity.kt file is
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.message = "Data Binding Example"
}
}
You can run and verify it.
I hope this was helpful to you to get started in Android DataBinding. There is more to explore and learn. Check out Android docs for more. I also keep writing blog posts like this. So don’t forget to visit this blog again.
]]>If you have any questions or suggestion please feel free to write to me.
One quick note here. The tips I am going to share are written from a developer’s perspective. That means, to implement some of it you might have to know some programming and server configuration. However, if you don’t know someone from your team might be able to help do it.
With a hope that these would help you with your website’s SEO.
<img src="example.jpg" alt="Example" title="Example" />
<a title="Example Website" href="http://example.com">Link</a>
<script async src="script.js"></script>
However, for CSS, I use a trick that I found here. The code is as follows: ```html
```
12. Create proper robots file, an example is as follows:
```txt
User-Agent: *
Disallow: /readme.md
# Directories
Disallow: /zohoverify/
# Sitemap
Sitemap: http://parasnath.com.np/sitemap.xml
User-Agent: Googlebot
Allow: /*.js*
Allow: /*.css*
Allow: /*.jpg*
I know, I haven’t covered all that I have done with my blog. I will keep elaborating on the points I have made above in my later posts. In the meantime I will list some of the tools I use for my SEO here:
]]>OWASP Top 10 Proactive controls is a list of security technique that should be considered for every software development. They top 10 controls are listed as follows in the order of their importance, first being the topmost priority.
Leverage security frameworks and libraries
A developer writing an application might not have sufficient knowledge, time or budget to properly implement or maintain security features. Therefore, secure coding libraries and frameworks should be leveraged as much as possible. The embedded security in such libraries and frameworks help guard against security-related design and implementation flaws.
Encode and Escape data
This is the main attack points used for SQL injection. Data should be properly encoded before they are used in the target like in the Database query so that the inputs are safe. And while displaying the data back to the users, they can be escaped so that the data appears as the user expects.
Validate all inputs
This is a programming technique to ensure only the correct format of data enters the system. These can be done with the help of regex matches.
Implement digital identity
The implementation of digital identity refers to the implementation of a proper authentication system so that the system knows who the user is.
Enforce access controls
Enforcing access controls refers to the implementation of proper authorization i.e. to allow or deny specific requests to a user, program or process.
Protect data everywhere
A software system might collect data like passwords, card numbers, health records, personal details, etc. These kinds of data should be protected. Proper hashing and encryption should be done so that they are not compromised by a third party.
Implement Security Logging and Monitoring
Logging is commonly used by developers for diagnostic purposes. The same tools and patterns can be used to log security information like authentication, authorization, etc. So that they can be monitored.
These are the basic things a developer should practice. It should be taken as the baseline standard and not as the comprehensive security steps to be followed. I will be discussing more security controls that needs to be followed to secure your software in my upcoming posts.
You can find the full document here.
]]>Today while I was updating npm I got into a similar situation. The error was as follows:
error: failed to commit transaction (conflicting files)
npm: /usr/lib/node_modules/npm/lib/utils/stringify-package.js exists in filesystem
// lines clipped ...
Errors occurred, no packages were upgraded.
I searched the internet for a while then I stumbled upon this issue. It is the solution by n0noob. The solution is to use –overwrite=’*‘.
So the final command would be
sudo pacman -S npm –overwrite=’*’
And this solved my problem. This applies to Arch Linux and other distros based on Arch Linux.
]]>Caution: Use –overwrite=’*’ at your own risk. This command might result in an unusable system. Use it only if you know what you are doing.
I will write the monthly review by organizing it in three sections. The first section will be ‘what went well?’ where I will be listing what activities went well the last month. The next section will be ‘what could have been improved?’. This is the section where I evaluate the activities I performed and see where I could have done better and what went wrong. It will also be a section to have a takeaway from the month gone. The final section would be ‘For next month’ where I want to share what I want to achieve in the next month. So, let’s get started.
This year started pretty well. January was a month with a ton of excitement. I had a lot of learnings. This month I performed the following activities.
For the next month, February, I plan to do the following activities:
Keep an eye for the next month’s monthly review here.
]]>WordPress has features like Customizable design, Responsive design, SEO friendliness, high security, high performance, powerful media management, ease of use, accessibility, etc. It is very extensive and has over 54,000 plugins. It is, therefore, a platform of choice not just for hobby blogs but also biggest news sites online and online stores.
WordPress can be viewed in the following 4 component architecture:
WP Core
WP Core is a set of code that provides the backbone of WordPress. WP Core includes the main WordPress Framework files, configurations, admin panel, etc.
WP Theme
It is the visual aspect that is for external users. It contains a set of files that determine the look and feel of the WordPress website.
WP Plugin
It is the third party customization aspect to add features and functionalities upon the existing WordPress functionalities.
WP Media
It is a set of files such as images, audios, videos, etc. It is a storage directory for the media files that are uploaded from the dashboard.
WordPress Security is a huge importance for any WordPress website owner. No software is 100% secure. Bugs and vulnerabilities can be discovered as time passes. Therefore, regular patches are done to the existing software system. So, one of the ways to have a secure website is to have the latest software running. For this, WordPress has an update/upgrade feature that needs to be done on a regular basis.
However, update/upgrade does not go well every time. There are times when the update/upgrade fails and the website goes down. Here I will discuss the two kinds of problems that we face in such a case which are discussed as follows:
Stuck at maintenance mode During the update/upgrade of WordPress themes and plugins, WordPress downloads the required update files. Before it starts applying the changes to the instance of WordPress installation, it switches to maintenance mode and once the update is complete, it switches back to production mode. Switching to maintenance mode is important to do the update in a seamless manner without letting the visitors know what is going behind the scene. Also, during the update, the application might reveal information that might impose security risk on the web application. Switching to maintenance mode is done by creating a .maintenance file in the root directory of the WordPress maintenance directory. To remove the maintenance mode, all we need to do is delete the file ‘.maintenance’.
Another update is currently in progress
The second kind of problem you might face is ‘Another update is currently in progress’. This happens when WordPress update is started but it never completes. In such a case, you will see that you still have an outdated WordPress. But the upgrade button doesn’t let you upgrade it. It displays the message. ‘Another update is currently in progress’. To fix this issue, you need to access the database system, In your {tbl_prefix}_options table search for option_name=’core_updater.lock’ and delete. After the deletion, you will now be able to upgrade the WordPress installation to the latest version.
$ ls
This is the most basic usage. It will list the files and directories. However, this will not display the files or folders that are hidden.
Hidden file is a file that starts with a ‘dot’, example ‘.file3’
To list all files including the hidden files use -a. Example
$ ls -a
To create a directory:
$ mkdir foldername
To create a text file:
$ touch filename
To read the contents of a file:
$ less filename
To read the first few lines of a file:
$ head filename
To read the last few lines of a file:
$ tail filename
To copy a file:
$ cp file1 newfile
To move a file:
$ mv file1 newfile
To delete a file:
$ rm filename
To copy a directory
$ cp -r dir1 dir2
To change directory:
$ cd directoryname
To go up one directory:
$ cd ..
To go to the $HOME directory
$ cd
$HOME is the login directory of the user. Usually it is /home/username
Network
Now, let’s learn about some of the network commands.
The first command you need to learn is the ping command to check the connectivity. The most common use is to check if you are connected to your router or the internet. Example:
$ ping google.com
Let’s find out the IP address of the computer to do so, use the ip command as follows:
$ ip addr
Download a file from the internet using the wget command:
$ wget url_of_file
Monitoring
Let’s now look at some of the monitoring commands.
Let’s find out the memory usage of the system. We will see the total RAM available and it’s use space along with details of swap space. For this purpose, we use the free command as follows:
$ free
Next, let’s find the total disk usage of our system. This will show you the different disk partitions, their size, and usage information
$ df -h
Now let’s look at the open process along with the information like process id, the user who created the process, etc.:
$ ps aux
You can also use the top command to monitor the current process, memory usage, etc.
$ top
All the commands discussed above run the same way in almost all the Linux Distros and Unix based machines.
$ ./configure
$ make
$ make install
It’s always a good idea to look at the README file available along with the source code to know the exact installation steps.
However, if you want to use the default package manager available in the Linux System you are using. Then the software installation using the command line will be done using different commands in different distros of Linux. So, let’s take a look at a few of the common distros:
$ sudo apt install gimp
To remove gimp
$ sudo apt remove gimp
$ sudo yum install gimp
To uninstall gimp:
$ sudo yum remove gimp
$ pacman -S gimp
To uninstall a package, use
$ pacman -Rns gimp
Please let me know in the comments down there if there is any specific command you want to know about.
]]>In this post, I am going to show you how you can set up a LAMP server along with reverse proxy using Nginx. The system I am using here is CentOS 8. Here, we will not just install the packages and but also enable SELinux and configure it to work with the LAMP setup. So, we need to set SELinux to enforcing which can be done by running the following command:
# setenforce 1
Now that you have enabled SELinux in your Linux system, Let’s install the Apache server by installing httpd package.
# yum install httpd -y
We don’t want to run Apache in port 80 because we want to run Nginx at port 80 so we configure Apache to run at port 81. For this purpose, edit /etc/httpd/conf/httpd.conf and change line ‘Listen 80’ to ‘Listen 81’. Now start httpd
# systemctl enable --now httpd
The next step is to install MySQL. In our case, we will be using the MariaDB server which is a fork of MySQL. To install MariaDB run:
# yum module install mariadb -y
Now start the database server:
# systemctl enable --now mariadb
After installation, it is suggested to secure MySQL by running ‘mysql_secure_installation’:
Now its time to install PHP.
# yum module install php -y
To allow PHP connect to MariaDB install php-mysqlnd:
# yum -y install php-mysqlnd
Also, allow Apache to connect to MariaDB through the network by running the following command:
# setsebool -P httpd_can_network_connect_db on
For PHP based projects the SELinux policy should be httpd_sys_rw_content_t
# semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/*.php
Now that, we have install LAMP, we will install Nginx and configure reverse proxy:
# yum install nginx -y
Start Nginx and set it to start at boot
# systemctl enable - now ngnix
To configure the reverse proxy, in your nginx.conf file you can add
server {
/ {
proxy_pass http://localhost:81/
index index.html index.html
}
}
Let’s configure the firewall to open the ports 80 and 443 on the system with the following command:
# firewall-cmd - add-service=http - add-service=https - permanent
# firewall-cmd - reload
SELinux disables any web server to connect to the network. To enable network connection, we need to set sebool httpd_can_network_connect to on. We use -P option for persistence change across a system reboot.
# setsebool -P httpd_can_network_connect on
This can be verified with the command
# getsebool httpd_can_network_connect
The output is as follows:
]]>flutter_project/
- android/
- build/
- fonts/
- ios/
- lib/
Now that you have added the font files to the project, update the pubspec.yaml file as follows:
fonts:
- family: NameOfFont
fonts:
- asset: fonts/NameOfFont.ttf
- asset: fonts/NameOfFont-Black.ttf
- family: NameOfSecondFont
fonts:
- asset: fonts/NameOfSecondFont.ttf
Now that the fonts are added, we can set a font as the default font for the whole app by adding the following line to MaterialApp
theme: ThemeData(
fontFamily: 'NameOfFont'
),
If you want to use it to a specific widget, you can do as follows:
Text(
'Text with custom font',
style: TextStyle(fontFamily: 'NameOfFont'),
);