teleren/devto huggingface dataset:
Git - Staging and Snapshoting
Tags: git
Published: 2021-10-15 11:54:48

---
title: Git - Staging and Snapshoting
published: true
date: 2021-05-02 06:26:02 UTC
tags: Git
canonical_url: https://lagandlog.com/logs/git-staging-and-snapshoting
cover_image: https://lagandlog-uploads.s3.amazonaws.com/git_staging_8aa75b5553.jpg
---

Staging and snapshotting are important topics because these commands will be used by us daily.

**Installation and setup were covered in the previous log.**

1. [Local Setup](https://lagandlog.com/logs/git-local-setup)

Git is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows. Let's have look at only commands that required to stage and commit to your working branch.

## Working with Git stage and commit

```
git status
```

- show modified files in the working directory.

```
 git add [file] (or) git add . 
```

- you can add the file one by one to the stage or use ( . ) to add all your files at once to the stage.

```
 git reset [file] (or) git reset . 
```

- unstage a file while retaining the changes in the working directory or reset all files using ( . ) at the end.

```
 git diff
```

- check the changes made compared with the previous commit for the unstaged files.

```
git diff --staged
```

- check the changes made in stages files before commit.

## Commit your code

```
 git commit -m "[descriptive message]" 
```

- this command commits your staged files with changes to the repository, you should give a descriptive message about the commit.

## Happy Coding 👾

AMA on [Twitter](https://twitter.com/sasiKdharan)
Responsive Registration Form in HTML & CSS
Tags: registrationform, sigupform, registerform, htmlcss
Published: 2021-05-02 06:15:11

**Q: How do I create a Signup or Registration form using HTML and CSS?**
A: To Create a fully responsive registration form like n the image, you just have to read the following article and watch the video tutorial.

Hello Readers, today in this blog I will create a Responsive Registration Form using HTML and CSS. Earlier blog I have shared How can we create a simple login page using HTML and CSS?. Now I'm going to build a registration form.

**What do you mean by the Registration of Signup Form?**
Registration form is the form that contains various input fields of different input details where the user needs to fill his/her details to submit for a particular webpage. There are various types of registration but the main purpose of this type of form is to collect user's information or details.

As you can see on the given image of the signup of the registration form. Normally you can add 6 to 10 input fields on the signup form. Many people are confused about what they should include in the signup or registration form. You can add the following elements in your signup or registration form.

Company Logo
First and last name
User name or Email
Phone number
Country/ Region/ State
Date and Time
Gender Selection
Button

**Responsive Registration Form or Page | Source Code**
You can download all source code from the given link. <a href="https://www.codinglabweb.com/2021/01/responsive-registration-form-in-html-css.html">Click Here To Download All Source Code</a>
Node.js 异步
Published: 2021-05-02 06:08:34

```javascript
setTimeout(function() {
},time)

function callback() {
  console.log("This is the test.")
}
function callback_test(time, callback) {
  setTimeout(function(){
    console.log("test")
    let result = 0
    callback(0)
  },time)
}
```
```javascript
/*
需求：异步的按顺序去读取1.txt、2.txt、3.txt文件的内容
假设 1.txt内容为111 、2.txt内容为222、3.txt内容为333
*/
var  fs = require('fs');、
 fs.readFile('./files/1.txt','utf8',function(err,data){
   if(err){
     throw err;
   }
   console.log(data);
 })

 fs.readFile('./files/1.txt','utf8',function(err,data){
   if(err){
     throw err;
   }
   console.log(data);
 })

 fs.readFile('./files/1.txt','utf8',function(err,data){
   if(err){
     throw err;
   }
   console.log(data);
 })
/*
 结果：111 222 333。（好像满足需求啊）
*/

/* 
问题：上面的代码虽然正常按照顺序读取了文件，因为文件的内容都非常少，io读取耗时少，但当2.txt内容较多时候，2.txt的内容是最后输出的。因为他们都是异步操作，不知道谁先读取完。 这得取决于异步任务IO的耗时。
*/

/*
常规解决办法：
在第一个异步任务读取成功之后再读取第二个异步任务，
第二成功后，在读取第三个异步任务
*/
//读取第一个异步任务
fs.readFile('./files/1.txt','utf8',function(err,data){
  if(err){
    throw err;
  }
  console.log(data);
  //读取第二个异步任务
  fs.readFile('./files/2.txt','utf8',function(err,data){
    console.log(data);
    //读取第三个异步任务
    fs.readFile('./files/3.txt','utf8',function(err,data){
      console.log(data);
    })
  })
})

/* 
结果： 111 222 333 （这必须按照顺序输出的，结果杠杆的）  
*/

/*
问题：
以上按照顺序执行多个异步任务产生的问题：`回调地狱`问题（层层包裹进行回调，代码也不够优雅）
*/

/* 
解决办法：采用es6,提供的promise来解决上述产生的问题。
*/
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jic93p3uvdnzyhlv1rjv.png)
 
```javascript
let test = new Promise((resolve, reject)=>{
  if(true) {
    return resolve("secceed.")
  } else {
    return reject("failed")
  }
})

let test001 = function method(resolve, reject) {
  if(false) {
    resolve("1")

  }else {
    reject("2")
  }
}

new Promise(test001).then(()=> console.log("secceed")).catch(()=>console.log("failed"))

// new Promise(test001).then(
//     function() {
//       console.log("succeed！！！")
//     }
//   )
// .catch(
//   function() {
//     console.log("failed！！！")
//   }
// ) 
```
C Programming Questions and Answers
Tags: c, programming
Published: 2021-05-02 06:05:43

Shortly after starting a university in the middle of last year, I created a separate GitHub repository for C Programming.

I created this repository to put Questions and Answers related to c programming in the Introduction to Programming module, which is our first-year first-semester module.

Here is the link to that Repository [C-programming](https://github.com/ThusharaX/C-programming/)

Thank You!

{% github ThusharaX/C-programming %}
Dynamic Programming Vs Greedy method
Published: 2021-05-02 06:04:18

##Dynamic Programming:
It just solves problems by combining the sub problems to solutions only of the sub problems were independent.
It can be used for solving both mathematical optimization method and computer programming method.
For example,it can be used for finding the shortest path in graph.
The algorithm used is:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ton0dn7c5vgq69auw3m8.png)

##Greedy Method:
Greedy method solves problems step by step which leads to global optimization solution.
Algorithm for greedy is:
Greedy(D,n)
//In Greedy approach D is domain
//from which solution is to be obtained of size n
//Initially assume
      solution<-0
      for i<-1 to n do{
             s<-select(D)
             if(Feasible solution,s))then
               Solution<-Union(Solution,s)
}
return solution
iText PDF + SpringBoot RestAPI – Extract MySQL Data to PDF File
Tags: mysql, pdf, itext, springboot
Published: 2021-05-02 05:58:42

https://grokonez.com/spring-framework/spring-boot/pdf-file-with-itext-springboot-restapi-extract-mysql-data-to-pdf-file

iText PDF + SpringBoot RestAPI – Extract MySQL Data to PDF File

In the tutorial, we show you how to create a SpringBoot RestAPIs application that uses Spring JPA & iText library to extract data from MySQL records to a PDF file in table format.

Related posts:
- <a href="https://grokonez.com/spring-framework/use-spring-jpa-postgresql-spring-boot">How to use Spring JPA with PostgreSQL | Spring Boot</a>

<!--more-->
<h2>Technologies</h2>
- SpringBoot
- iText 5.0.6
- MySQL
<h2>Practice</h2>
Project Structure ->

<img src="https://grokonez.com/wp-content/uploads/2018/10/spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-project-structure.png" alt="spring-boot-spring-jpa-export-data-pdf-table-file-by-itext-mysql-project-structure" width="315" height="252" class="alignnone size-full wp-image-15197" />
<h3>Create SpringBoot project</h3>
Use SpringToolSuite to create a SpringBoot project with below dependencies:

<pre><code class="language-html">&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;      
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;      
&lt;dependency&gt;
    &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
    &lt;artifactId&gt;itextpdf&lt;/artifactId&gt;
    &lt;version&gt;5.0.6&lt;/version&gt;
&lt;/dependency&gt;   
&lt;dependency&gt;
    &lt;groupId&gt;mysql&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
<h3>Customer Model</h3>
<code>Customer.java</code> ->

More at:

https://grokonez.com/spring-framework/spring-boot/pdf-file-with-itext-springboot-restapi-extract-mysql-data-to-pdf-file

iText PDF + SpringBoot RestAPI – Extract MySQL Data to PDF File
Crud RestAPIs with NodeJS/Express, MongoDB using Mongoose
Tags: mongoose, mongodb, express, restapi
Published: 2021-05-02 05:51:43

https://grokonez.com/node-js/crud-restapis-with-nodejs-express-mongodb

Crud RestAPIs with NodeJS/Express, MongoDB using Mongoose

In the tutorial, we show how to build CRUD RestAPIs with NodeJS/Express and MongoDB using Mongoose.

Related posts:
- <a href="https://grokonez.com/node-js/nodejs-restapis-how-to-create-nodejs-express-restapis-post-get-put-delete-requests">NodeJs/Express RestAPIs – POST/GET/PUT/DELETE requests</a>
- <a href="https://grokonez.com/java-integration/nodejs-express-mongodb-one-to-many-related-models">NodeJs/Express MongoDB One-to-Many related models</a>

<!--more-->
<h2>Goal</h2>
<strong>Prerequisites</strong>: <a href="https://grokonez.com/node-js/nodejs-restapis-how-to-create-nodejs-express-restapis-post-get-put-delete-requests">Create NodeJs/RestAPIs tutorial</a>

-> Project structure:

<pre><code class="language-javascript">
/nodejs-restapi
	/app
		/controllers
			customer.controller.js
		/routes
			customer.routes.js
	/node-modules
	package.json
	server.js
</code></pre>

<strong>Objective</strong>:	design, create models and interact with MongoDB by Mongoose.

-> The tutorial will create a project as below structure:

<pre><code class="language-javascript">
/nodejs-restapi-mongodb
	/app
		/config
			mongodb.config.js
		/controllers
			customer.controller.js
		/models
			customer.model.js
		/routes
			customer.routes.js
	/node_modules
	package.json
	server.js
</code></pre>
<h2>Mongoose</h2>
Mongoose is a MongoDB object modeling tool that provides a schema-based solution to model data. Mongoose is installed in your project (package.json) by commandline:

More at:

https://grokonez.com/node-js/crud-restapis-with-nodejs-express-mongodb

Crud RestAPIs with NodeJS/Express, MongoDB using Mongoose
NodeJS – use Mongoose to save Files/Images to MongoDB
Tags: node, mongoose, mongodb
Published: 2021-05-02 05:45:21

https://grokonez.com/node-js/nodejs-use-mongoose-to-save-files-images-to-mongodb

NodeJS – use Mongoose to save Files/Images to MongoDB


In the tutorial, we will show how to build a NodeJS application to save files/images to MongoDB database using Mongoose.

Related posts:
- <a href="https://grokonez.com/node-js/crud-restapis-with-nodejs-express-mongodb">Crud RestAPIs with NodeJS/Express, MongoDB using Mongoose</a>

<!--more-->
<h2>Mongoose save files/images to MongoDB</h2>
Firstly, we define a Mongoose model for files/images with <strong>Buffer</strong> data as below:

<pre><code class="language-javascript">
const ImageSchema = mongoose.Schema({
    type: String,
    data: Buffer
});
</code></pre>

To read/write data of file/image, we use <code>fs.readFileSync('/path/to/file')</code> and <code>fs.writeFileSync('/path/to/file', image.data)</code> functions of NodeJS file-system module.

Below segment code is used to store file/image to MongoDB:

<pre><code class="language-javascript">
// Connecting to the database
mongoose.connect(dbConfig.url)
.then(() => {
	
	// empty the collection
    Image.remove(err => {
		if (err) throw err;
		console.log("Removed all documents in 'images' collection.");
		var imageData = fs.readFileSync('/path/to/file');
		
		// Create an Image instance
		const image = new Image({
			type: 'image/png',
			data: imageData
		});

	    // Store the Image to the MongoDB
		image.save()
		.then(img => {
			// Find the stored image in MongoDB, then save it in a folder
			Image.findById(img, (err, findOutImage) => {
				if (err) throw err;
				try{
					fs.writeFileSync('/path/to/file', findOutImage.data);
				}catch(e){
					console.log(e);
				}
			});
		});
	})
	
})</code></pre>
<h2>Practice</h2>
We build a NodeJS project as below structure:

More at:

https://grokonez.com/node-js/nodejs-use-mongoose-to-save-files-images-to-mongodb

NodeJS – use Mongoose to save Files/Images to MongoDB
Hooray!
Tags: reason, beginners, javascript
Published: 2021-05-02 03:30:23

Determined to support, motivated by helping, and proud of other’s improvement and growth. Friendly, caring, understanding and empathic, that’s how I saw __Awesomity Lab__ and __Code of Africa__ teams!  

Building one’s career and experience isn’t that easy, is it?
And we won’t get experience without experiencing things, will we? 
 
Most of the people don’t care about what someone is capable of but care about what the experience that person has!

Different story when it comes to __Code of Africa__ and __Awesomity Lab__!
It all begins with a simple challenge, and they rise a __dead phoenix from ashes__!  

From basic skills like understanding your values to communication skills and then to building a massive web/mobile app!  

I had no experience in working with teams and integrating my frontend with secure APIs, I had no idea of how to manage huge data and track the process of the data procession!

But two months changed me! Took me from count-down and to-do app to the level where I can build and manage data of medium social media app! Two months took me from one level to another!  

My heart is full of thanks! I wish I could do the same to others, __InshAllah__!  

I highly thank __Awesomity Lab__ and __Code of Africa__, everyone from their team and my intern mates who were there when I messed things up!  

I really take those two companies as a great motivation and example to other companies out there!  

I take __Awesomity Lab__, specifically, as an inspiration to all of Rwandan youth!  

Words can’t explain things the way there are, but at least express our inner feelings and happiness, mine at this point is __gratitude__, __inspired__, and __surprised__!  

Thank you again, [Awesomity Lab](https://awesomity.rw/) and [Code of Africa](https://www.codeofafrica.com/EN), You are my heroes now and always!  

``God bless you!
``
Data.js mini framework for beginners
Published: 2021-05-02 05:42:04

![Data.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1p2y5b5y33j6zswull3t.png)
## What is [Data.js](http://datajs.simplesite.com/)?
Data.js is a mini-framework that runs on Node.js. It is mainly programmed to work with arrays. This framework is able to display arrays in different formats and again give information about how much information is in the array. Its syntax is very simple.
## In Data.js we create a program called "subgroup of numbers"
We can download Data.js from [github](https://github.com/Jahongir2007/data.js). The location of the downloaded folder: (all [guides](https://github.com/Jahongir2007/data.js/blob/main/README.md))
```
|___bin
      |___data.js
      |___test.js
|___LICENSE
|___README.md
```
We attach the data.js file in the bin folder to our program (Of course we can copy the bin folder from the uploaded folder to the folder we are creating).
```js
const Data = require(".\bin\data.js"); //importing data.js
```
## Now it's your turn to create the program:
```js
const Data = require(".\bin\data.js");
var app = new Data([25,9,16,100],{
   get: "false",
   getLenght: false,
   join: false,
   copy: false,
   constructor: false,
   entries: false,
   reverse: false,
   sort: false,
   fill: false,
   shift: false,
   map: Math.sqrt,
   pop: false
});
```
Output:
```
[5,3,4,10] 
```
Sequelize One-To-One association – NodeJS/Express, MySQLs
Tags: sequelize, node, express, mysql
Published: 2021-05-02 05:30:32

https://grokonez.com/node-js/sequelize-one-to-one-association-nodejs-express-mysql

Sequelize One-To-One association – NodeJS/Express, MySQL

In the <a href="https://grokonez.com/node-js/sequelize-orm-build-crud-restapis-with-nodejs-express-sequelize-mysql">post</a>, we got started with Sequelize ORM. Today we're gonna create Sequelize One-To-One association models with NodeJS/Express, MySQL.

Related posts:
- <a href="https://grokonez.com/node-js/sequelize-orm-build-crud-restapis-with-nodejs-express-sequelize-mysql">Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL</a>
- <a href="https://grokonez.com/node-js/sequelize-one-to-many-association-nodejs-express-mysql">Sequelize One-To-Many association – NodeJS/Express, MySQL</a>
- <a href="https://grokonez.com/node-js/sequelize-many-to-many-association-nodejs-express-mysql">Sequelize Many-to-Many association – NodeJS/Express, MySQL</a>

<!--more-->
<h2>Sequelize One-to-One association</h2>
<strong>Note</strong>: When calling a method such as <code>Customer.hasOne(Address)</code>, we say that the Customer model is the <strong>source</strong> and the Address model is the <strong>target</strong>.

We define 2 models:

<pre><code class="language-javascript">
Customer = sequelize.define('customer', {
  /* attributes */
});

Address = sequelize.define('address', {
	/* attributes */
});
</code></pre>

How to create One-to-One association between them?
-> Sequelize provides 2 ways:

- <strong>belongsTo</strong>

<pre><code class="language-javascript">
Address.belongsTo(Customer); // Will add a customerId attribute to Address to hold the primary key value for Customer.
</code></pre>

- <strong>hasOne</strong>

More at:
https://grokonez.com/node-js/sequelize-one-to-one-association-nodejs-express-mysql

Sequelize One-To-One association – NodeJS/Express, MySQL
LeetCode 213. House Robber II (javascript solution)

Tags: algorithms, javascript
Published: 2021-05-02 05:06:02

###Description:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

###Solution:
Time Complexity : O(n)
Space Complexity: O(n)

```javascript
var rob = function(nums) {
    // Handle base case
    if(!nums.length) return 0
    if(nums.length===1) return nums[0]
    if(nums.length===2) return Math.max(nums[0], nums[1])
    
    // Return the max between the subarray if we starting robbing at the first house or if we started robbing at the second house
    return Math.max(helper(nums.slice(0, nums.length-1)), helper(nums.slice(1)))
};

// Helper function follows same logic as house rober 1
function helper(segment) {
    if(!segment.length) return 0
    if(segment.length===1) return segment[0]
    if(segment.length===2) return Math.max(segment[0], segment[1])
    const dp = [segment[0], Math.max(segment[0], segment[1])]
    for(let i = 2; i < segment.length; i++) {
        dp[i] = Math.max(segment[i]+dp[i-2], dp[i-1])
    }
    return dp[dp.length-1]
}

```
Sequelize CRUD MariaDB example | Build CRUD Node.js/Express RestAPIs example
Tags: sequelize, crud, mariadb, node
Published: 2021-05-02 04:53:28

https://grokonez.com/node-js/sequelize/sequelize-crud-mariadb-example-build-crud-node-js-express-restapis-example

Sequelize CRUD MariaDB example | Build CRUD Node.js/Express RestAPIs example

Sequelize is a promise-based ORM for Node.js v4 and later. In the tutorial, we will show how to build CRUD RestAPIs with Node.js/Express, Sequelize, MariaDB.

Related posts:

- <a href="https://grokonez.com/node-js/sequelize-orm-build-crud-restapis-with-nodejs-express-sequelize-mysql">Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL</a>
- <a href="https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-upload-files-download-files-to-mysql-with-node-js-express-restapis-using-multer-sequelize-orm">Angular 6 HttpClient – Upload Files/Download Files to MySQL with Node.js/Express RestAPIs – using Multer + Sequelize ORM</a>
- <a href="https://grokonez.com/frontend/angular/angular-6/angular-6-httpclient-node-js-express-sequelize-mysql-get-post-put-delete-restapis">Angular 6 HttpClient Crud + Node.js Express Sequelize + MySQL – Get/Post/Put/Delete RestAPIs</a>
- <a href="https://grokonez.com/node-js/gridfs/nodejs-upload-download-files-to-mongodb-by-stream-based-gridfs-api-mongoose">NodeJS – GridFS APIs Upload/Download Files to MongoDB – Mongoose</a>
- <a href="https://grokonez.com/frontend/angular/angular-6/angular-6-client-upload-files-download-files-to-postgresql-with-springboot-restapis-example">Angular 6 Client – Upload Files/Download Files to PostgreSQL with SpringBoot RestAPIs example</a>
- <a href="https://grokonez.com/node-js/sequelize-one-to-one-association-nodejs-express-mysql">Sequelize One-To-One association – NodeJS/Express, MySQL</a>

<!--more-->
Related pages:
<ul>
<li><a href="https://grokonez.com/nodejs-tutorial">Node.js Tutorial</a></li>
<li><a href="https://grokonez.com/angular-tutorial">Angular Tutorial</a></li>
</ul>
<h2>Overview</h2>
<h3>Project Design</h3>
<img src="https://grokonez.com/wp-content/uploads/2018/08/nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb-architecture-project.png" alt="nodejs-express-rest-apis-post-get-put-delete-request-sequelize-crud-apis-mariadb + architecture-project" width="701" height="325" class="alignnone size-full wp-image-14300" />
<h3>Sequelize ORM</h3>
<h4>Installation</h4>
<pre><code class="language-javascript">
$ npm install --save sequelize
$ npm install --save mysql2
</code></pre>
<h4>Setup Connection</h4>
<pre><code class="language-javascript">
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
  host: 'host',
  dialect: 'dialect',
  operatorsAliases: false,
 
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  }
});
</code></pre>
<h4>Sequelize Model</h4>

More at:

https://grokonez.com/node-js/sequelize/sequelize-crud-mariadb-example-build-crud-node-js-express-restapis-example

Sequelize CRUD MariaDB example | Build CRUD Node.js/Express RestAPIs example