Posts

Showing posts from March, 2020

Attach extra EBS volume to your AWS EC2 instance

You create your new volume from the "Volumes" menu in your EC2 management console. You attach your new volume to your ec2 instance by right clicking the new volume and choose attach.

From the "Attachment Information", you can see where it is being attached, such as "/dev/sdf".

Or you can then see your new volume inside your EC2 instance:

$ cat /proc/partitions  major minor  #blocks  name
 202        1    8388608 xvda1  202       80   20971520 xvdf

Use the lsblk command to view your available disk devices and their mount points (if applicable) to help you determine the correct device name to use. $ lsblkNAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTnvme1n1       259:0    0  100G  0 disk nvme0n1       259:1    0    8G  0 disk ├─nvme0n1p1   259:2    0    8G  0 part /└─nvme0n1p128 259:3    0    1M  0 part $ sudo fdisk -l
Disk /dev/nvme1n1: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 b…

Amazon FSx | File Storage | Amazon Web Services

Amazon FSx for Windows File Server provides a fully managed native Microsoft Windows file system so you can easily move your Windows-based applications that require file storage to AWS.

https://aws.amazon.com/fsx

Add Permanent Routes in CentOS

Method One : Using nmcli command line tool nmcli connection show nmcli connection modify "connection-name" +ipv4.routes "network address/prefix gateway" nmcli connection up "connection-name"
Example: sudo nmcli connection modify "Bond connection 1" +ipv4.routes "172.31.0.0/16 192.168.0.1" sudo nmcli connection reload sudo nmcli connection up "Bond connection 1" sudo nmcli connection show
After running the above commands, you can see the changes in the file: sudo vim /etc/sysconfig/network-scripts/route-Bond_connection_1 It is the same as method 2, directly making changes to the file.
Method Two : Manually Create Configuration File configuration file inside the /etc/sysconfig/network-scripts/ directory using the following format.
route-connectioname
For example, if the name of the network connection is "Bond connection 1", then The name of the configuration file should be
route-Bond_connection_1
sudo cat /etc/syscon…

Changing domain name servers

Due to the decentralized structure of the domain name system, it can take up to 48 hours for your custom name servers to take effect everywhere. The DNS records will then be deactivated.

Resolving problems with mixed content

If you enable HTTPS for your web site but your site's HTML still references images, CSS, or JavaScript over HTTP, then your site is serving mixed content. Serving mixed content may make your site less secure and cause trouble loading assets.

To remove your site's mixed content, make sure all your assets are served over HTTPS by changing http:// to https:// in your site's HTML.

Assets are commonly found in the following locations:


If your site uses Jekyll, your HTML files will probably be found in the _layouts folder.CSS is usually found in the <head> section of your HTML file.JavaScript is usually found in the <head> section or just before the closing </body> tag.Images are often found in the <body> section.

Tip: If you can't find your assets in your site's source files, try searching your site's source files for http in your text editor

TreeSet provides an implementation of the Set interface that uses a tree for storage. Objects are stored in a sorted and ascending order.

Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.

Jakarta Server Faces

Jakarta Server Faces defines an MVC framework for building user interfaces for web applications, including UI components, state management, event handling, input validation, page navigation, and support for internationalization and accessibility.

Apache Groovy is an object-oriented programming language for the Java platform.

Apache Groovy is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk, and it extends Java by providing concise and compelling syntax.

Kubernetes drastically changes the code deployment process, making it possible to seamlessly roll out new releases with no downtime.

Kubernetes is also a crucial tool for the adoption of the Hybrid Cloud environment which means same code can run on developer machines as well as on-premise on different cloud environments like AWS, GCP, and Microsoft Azure.

Docker is an open-source tool for automating the deployment of applications on the cloud or physical servers.

Docker allows developers and system admins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
Docker works in collaboration with the cloud, Linux, and Windows vendor, and many companies focusing on IT automation, Docker is nicely poised to take advantage of that.

Advantage of Dependency Injection

makes the code loosely coupled so easy to maintainmakes the code easy to test

Coronavirus Can Linger on Steel and Plastic for up to 3 Days, Study Finds

A string is traditionally a sequence of characters, either as a literal constant or as some kind of variable.

Java Currency Formatter

Windows 10 Host File Location

Location of the Host File
In Windows operating systems, the location of the host file is at the following address:

C:\Windows\System32\Drivers\etc

Educational Resources For Kids, Parents, And Teachers

Online Learning for Kids www.brainpop.com BrainPop is a group of educational websites with over 1,000 short animated movies for students in grades K-12, together with quizzes and related materials, covering the subjects of science, social studies, English, math, engineering and technology, health, and arts and music.
Mystery Science https://mysteryscience.com Mystery Science offers open-and-go lessons that inspire kids to love science. The hook, visuals, and activity have all been prepared for you. Less prep, more learning.

The United States is suspending routine visa services in most countries

WASHINGTON: The United States is suspending routine visa services in most countries because of the coronavirus pandemic, the State Department announced late Wednesday.

It said embassies and consulates in "most countries worldwide... will cancel all routine immigrant and nonimmigrant visa appointments as of March 18, 2020."

It did not specify which countries would be exempted from the suspension, which was in response to "worldwide challenges" related to the deadly pandemic.

也就是说从3月18日起,美国已经开始在全世界绝大多数国家范围内暂停常规非移民签证申请预约服务。

目前已经明确得知美国驻韩国领事馆已经全部暂停了常规签证申请预约服务。

而驻华的领事馆签证处目前还没有相关公告。由于这条新闻也是刚刚出来,不排除驻华领馆没有及时更新公告的可能。

The world as we know it will change forever in the wake of the coronavirus pandemic

It's important that the United Nations keep track of all citizens around the world

Bill Gates says that all World Citizens need a digitally registered identification card

Spring Boot supports the following embedded servlet containers

Tomcat 9.0

Jetty 9.4

Undertow 2.0

You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.

One-time job on Linux

at utility is very simple to use, and you can fire off a one-time job without a lot of fuss. Run at time < script.sh and at will run the script and then exit. For example:

at 8am -f script.sh

Will run the script at 8 a.m. -- if it's past 8 a.m., then it will run the job tomorrow. And that's it; the job will run once. If you want to see what's scheduled, just use the atq command to see what you will be running.  Note that the -f option specifies a file for the command input, whereas you can also just provide the commands via standard input (such as using the < script.sh method).

Anacron is a periodic command scheduler just like cron.

The only difference between Anacron and cron is that Anacron does not need your computer to be always running. You can schedule your tasks to run at any time. When your computer is off, the task will be executed the next time you turn the computer on.

Use the following command to install in Ubuntu:

sudo apt-get install anacron
Anacron works similar to cron. You can add your job to the /etc/anacrontab file.
The syntax to add a job is

period   delay-after-computer-start   job-identifier   command
# These replace cron's entries
1       5       cron.daily      run-parts --report /etc/cron.daily
7       10      cron.weekly     run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly    run-parts --report /etc/cron.monthly

The disadvantage of anacron is that it only deals with tasks on a daily, weekly or monthly schedule. You can’t use it for a hourly or minutes schedule.

Set Automatic Update on Amazon EC2

First install yum-cron using the command below:

sudo yum install yum-cron

Inside /etc/yum/yum-cron.conf
# Whether updates should be downloaded when they are available.
download_updates = yes

# Whether updates should be applied when they are available.  Note
# that download_updates must also be yes for the update to be applied.
apply_updates = yes

Enable and start:
sudo systemctl start yum-cron.service

sudo systemctl enable yum-cron.service

Stack examples

Scoop A command-line installer for Windows

Scoop installs the tools you know and love
scoop install curl
https://scoop.sh/

The ANSI SQL specification includes the except operator for performing the except operation.

If you are using Oracle Database, you will need to use the non-ANSI-compliant minus operator instead.

The ANSI SQL specification includes the intersect operator for performing intersections.

To test whether an SQL expression is null, you need to use the is null operator

An expression can be null, but it can never equal null.Two nulls are never equal to each other.


Different types of SQL tables

Permanent tables (i.e., created using the create table statement)Derived tables (i.e., rows returned by a sub-query and held in memory)Temporary tables (i.e., volatile data held in memory)Virtual tables (i.e., created using the create view statement)

MySQL Sandbox with the Sakila sample database

You can go to https://www.katacoda.com/mysql-db-sandbox/scenarios/mysql-sandbox to access the MySQL Sandbox, which has the Sakila sample database loaded in a MySQL instance.
You’ll have to set up a (free) Katacoda account. Then, click the Start Scenario button.

See also:
https://dev.mysql.com/doc/index-other.html

Programming Interviews Books

Programming Interviews Exposed by John Mongan and Noah Kindler; Cracking the Coding Interview by Gayle McDowell; Daily Coding Problem by Lawrence Wu and Andrew Miller.

A cycle cannot exist in a tree.

Trees are similar to graphs, but the key point that differentiates a tree from the graph is that a cycle cannot exist in a tree.

The following are the two types of arrays:

One-dimensional arrays (as shown above)
Multi-dimensional arrays (arrays within arrays)

@SpringBootApplication annotation includes Auto- Configuration, Component Scan, and Spring Boot Configuration.

If you added @SpringBootApplication annotation to the class, you do not need to add the @EnableAutoConfiguration, @ComponentScan and @SpringBootConfiguration annotation. The @SpringBootApplication annotation includes all other annotations.

Example:


The entry point of the spring boot application is the class contains @SpringBootApplication annotation and the main method.

Spring Boot automatically scans all the components included in the project by using @ComponentScan annotation.
Spring Boot automatically configures your application based on the dependencies you have added to the project by using @EnableAutoConfiguration annotation. For example, if MySQL database is on your classpath, but you have not configured any database connection, then Spring Boot auto-configures an in-memory database.


Import the AWS Root and Regional certs into your truststore

keytool -import -keystore trust-store-rds.jks -storepass changeit -noprompt alias "aws-rds-root" -file rds-ca-2019-root.pem

keytool -import -keystore trust-store-rds.jks -storepass changeit -noprompt -alias "aws-rds-us-east-1" -file rds-ca-2019-us-east-1.pem

How to import/open Spring Boot sample in IDE

The spring boot demos do not include specific IDE settings, as they are independent of the IDE.

Spring boot uses maven as build tool, so you can import the project as existing maven project.

Find missing elements in a Integer array containing numbers.java

The java.util.BitSet.nextClearBit(int fromIndex) method returns the index of the first bit that is set to false that occurs on or after the specified starting index.

find missing number in array of size n containing numbers from 1 to n only.java

Java program illustrating Bitset Class

Block an IPv4 IP Address using firewalld on Linux

sudo firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.18.188 reject' --permanent

success

sudo firewall-cmd --reload

success

Trump says coronavirus will 'go away'

Harvard moves classes online

Harvard tells students don't return after spring break because of Coronavirus.

A graph database (GDB) is a database that uses graph structures for semantic queries with nodes, edges, and properties to represent and store data.

A key concept of the system is the graph (or edge or relationship). The graph relates the data items in the store to a collection of nodes and edges, the edges representing the relationships between the nodes. The relationships allow data in the store to be linked together directly and, in many cases, retrieved with one operation. Graph databases hold the relationships between data as a priority. Querying relationships within a graph database is fast because they are perpetually stored within the database itself. Relationships can be intuitively visualized using graph databases, making them useful for heavily inter-connected data.

Build resilience.

A man who never failed, will succumb if hit hard enough.
Early in his adult life, a man should
take a couple of  life slaps in order to understand the concept of consequences.


Firewall support for NFS on CentOS

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload

Fixed Alpine ssh-keygen: not found

apk update && \
      apk add --no-cache \
      openssh-keygen

In Python, we can use heapq.heapify to turn a list into a heap in linear time

Reset password for Azure Linux VM

Image
If "Reset password" provided by Azure doesn't work, it is likely because the Guest agent required to enable the VMAccessForLinux extension to change password is not responsive.

There is a workaround of running the echo command in the run command blade.


echo "<>" | passwd --stdin <USERNAME>

replace <> with the actual password

replace <USERNAME> with the real username.

MX Resource Record Sets and Sender Policy Framework

For each MX resource record set, checks for a TXT resource record set that contains a corresponding SPF value. The SPF (Sender Policy Framework) value specifies the servers that are authorized to send email for your domain. This helps reduce spam by detecting and stopping email address spoofing. (Resource record sets that use the experimental SPF type are no longer recommended.)

RSS Feed URL of a Blogger (Blogspot) Blog

Configuring Vim with a Vimrc file for Python

How to fix Jenkins Unable to read /var/lib/jenkins/config.xml after upgrading

Stop jenkins service

$ sudo service jenkins stop

Move JENKINS_HOME/config.xml to another file for backup

$ sudo mv /var/lib/jenkins/config.xml /var/lib/jenkins/config.xml.bak

Start jenkins service

$ sudo service jenkins start

How To activate the EntityManagerFactory on Glassfish server

To activate the EntityManagerFactory, the application needs to be disabled and enabled when database connection is stable:

./asadmin disable myapp
./asadmin enable myapp

Tomcat-on-Docker-example.Dockerfile

Announcing PowerShell 7.0 | PowerShell

PowerShell 7 is the latest major update to PowerShell, a cross-platform (Windows, Linux, and macOS) automation tool and configuration framework optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. PowerShell includes a command-line shell, object-oriented scripting language, and a set of tools for executing scripts/cmdlets and managing modules.
https://devblogs.microsoft.com/powershell/announcing-PowerShell-7-0/

Enable OpenJ9’s SharedClasses Cache

The Eclipse OpenJ9 JVM offers Spring applications significant benefits when deployed as part of a cloud-native runtime. OpenJ9 comes with improvements to memory overhead and startup times, achieved through shared classes and an aggressive focus on memory footprint.

To benefit from the startup time improvements, enable OpenJ9's SharedClasses Cache (which enables dynamicAOT), by setting the following JVM options:

-Xshareclasses -Xscmx50M -Xquickstart

The Eclipse OpenJ9 JVM offers Spring applications significant benefits

The Eclipse OpenJ9 JVM offers Spring applications significant benefits when deployed as part of a cloud native runtime. OpenJ9 comes with improvements to memory overhead and startup times, achieved through shared classes and an aggressive focus on memory footprint.

https://www.eclipse.org/openj9/

Java reserved words

abstract
assert
boolean
break
byte
case
catch
char
class
const
continue
default
do
double
else
enum
extends
final
finally
float
for
goto
if
implements
import
instanceof
int
interface
long
native
new
package
private
protected
public
return
short
static
strictfp
super
switch
synchronized
this
throw
throws
transient
try
void
volatile
while

Docker is powerful and simple to use.

Docker allows developers to create portable, self-contained images for the software they create. These images can be reliably and repeatedly deployed. You can get a lot of value out of Docker very easily, but to get the most out of Docker there are some concepts that are important to understand. How you build your Docker image has a measurable impact when you are doing continuous integration and continuous delivery. 

AdoptOpenJDK - Open source, prebuilt OpenJDK binaries

AdoptOpenJDK binaries are available for download in the following types of installation package:

Archive files
Installers
The binaries are supported on the architectures and operating systems listed in Supported Platforms. If you're migrating to AdoptOpenJDK, you can learn about the differences between Oracle JDK and AdoptOpenJDK in our Migration Guide and any steps that you might need to take. For example, how to use IcedTea-Web as an alternative to Web Start.
https://adoptopenjdk.net/installation.html

Install Go (Golang) On Fedora

sudo dnf -y install go

Popular DevOps tools for continuous integration and continuous deployment

The notable DevOps tools for continuous integration include Jenkins, GitLab CI, TeamCity, Bamboo, Codeship, CircleCI, and Travis CI. The popular DevOps tools for continuous deployment include Azure Pipelines for Deployment, Jenkins, Bamboo, DeployBot, Shippable, ElectricFlow, and TeamCity. 

Fixed Argument list too long

find /path -type f -print | xargs rm

Removing docker images

docker rmi image_id_1 image_id_2 image_id_3

If you want to remove the dangling images, you can use the prune option:

docker image prune
If you want to remove both unused and dangling images at once, you can use prune with option -a:

docker image prune -a

To remove all docker images, you need to first stop all the running containers.

docker ps -a -q | xargs docker rm
Now you can delete all the images this way:

docker images -a -q | xargs docker rmi -f

Set Your Default Linux Distribution on Windows 10

To view your installed Linux distributions, type the following command and hit Enter:

wslconfig /l
The Linux distribution ending with "(Default)" is your default Linux distribution.

To set your default Linux distribution, run the following command, where Name is the name of the Linux distribution:

wslconfig /setdefault Name
For example, to set Ubuntu as your default Linux distribution, run the following command:

wslconfig /setdefault Ubuntu

The Tomcat server is the most widely used open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies.

Apache Tomcat software powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations.
The sample TomCat application we will be using for this exercise is included in a git repository so that you can run through this tutorial easily.
In Tomcat, we have to move the war file to the CATALINA_BASE/webapps directory. Tomcat will then install it automatically and deploy the application for you.

The JVM interprets the bytecode just as a CPU would interpret assembly-language instructions.

At runtime, the JVM reads and interprets .class files and executes the program's instructions on the native hardware platform for which the JVM was written. The JVM is a piece of software written specifically for a particular platform. The JVM is the heart of the Java language's "write-once, run-anywhere" principle. Your code can run on any chipset for which a suitable JVM implementation is available. JVMs are available for major platforms like Linux™ and Windows®, and subsets of the Java language have been implemented in JVMs for mobile phones and hobbyist chips.

How to remove IE from Windows 10

Open Control Panel.
Click on Programs.
Click Turn Windows features on or off.
Clear the Internet Explorer 11 option.
Click OK.
Click Yes to confirm.
Click Restart

Java Truststore

The Java truststore is a file that contains the root certificates for Certificate Authorities (CA) that issue certificates such as GoDaddy, Verisign, Network Solutions, and others.
The truststore comes bundled with the JDK/JRE and is located in $JAVA_HOME/lib/security/cacerts.
The truststore is used whenever our Java code establishes a connection over SSL.

MongoDB show databases

Connect to the MongoDB shell and then execute show dbs command to list all the currently available database on MongoDB server.

> show dbs

UFW example

To allow all incoming SSH connections run this command:

sudo ufw allow ssh
An alternative syntax is to specify the port number of the SSH service:

sudo ufw allow 22
Allow Incoming SSH from Specific IP Address or Subnet
To allow incoming SSH connections from a specific IP address or subnet, specify the source. For example, if you want to allow the entire 18.18.18.0/24 subnet, run this command:

sudo ufw allow from 18.18.18.0/24  to any port 22
Allow Incoming Rsync from Specific IP Address or Subnet
Rsync, which runs on port 873, can be used to transfer files from one computer to another.

To allow incoming rsync connections from a specific IP address or subnet, specify the source IP address and the destination port. For example, if you want to allow the entire 18.18.18.0/24 subnet to be able to rsync to your server, run this command:

sudo ufw allow from 18.18.18.0/24 to any port 873

Checking status of ufw and enabling it

To see whether ufw is running, we issue the following command:

sudo ufw status

setup default rules:

sudo ufw default allow outgoing

sudo ufw default deny incoming

Delete rules in UFW Ubuntu Firewall using ufw delete command

Delete Firewall rules by rule number

ufw status numbered ufw delete 2