Github link: https://github.com/adi501/react-js-example
3 December 2021
Ternary operator example in react js
substring function in react js
Github link: https://github.com/adi501/react-js-example
Reactjs code snippets
Reactjs code snippets
How to install: https://marketplace.visualstudio.com/items?itemName=xabikos.ReactSnippets
Below is a list of all available snippets and
the triggers of each one. The ⇥ means the TAB key.
|
Trigger |
Content |
|
rcc→ |
class component skeleton |
|
rrc→ |
class component skeleton with
react-redux connect |
|
rrdc→ |
class component skeleton with
react-redux connect and dispatch |
|
rccp→ |
class component skeleton with prop
types after the class |
|
rcjc→ |
class component skeleton without
import and default export lines |
|
rcfc→ |
class component skeleton that
contains all the lifecycle methods |
|
rwwd→ |
class component without import
statements |
|
rpc→ |
class pure component skeleton with
prop types after the class |
|
rsc→ |
stateless component skeleton |
|
rscp→ |
stateless component with prop
types skeleton |
|
rscm→ |
memoize stateless component
skeleton |
|
rscpm→ |
memoize stateless component with
prop types skeleton |
|
rsf→ |
stateless named function skeleton |
|
rsfp→ |
stateless named function with prop
types skeleton |
|
rsi→ |
stateless component with prop
types and implicit return |
|
fcc→ |
class component with flow types
skeleton |
|
fsf→ |
stateless named function skeleton
with flow types skeleton |
|
fsc→ |
stateless component with flow
types skeleton |
|
rpt→ |
empty propTypes declaration |
|
rdp→ |
empty defaultProps declaration |
|
con→ |
class default constructor with
props |
|
conc→ |
class default constructor with
props and context |
|
est→ |
empty state object |
|
cwm→ |
componentWillMount method |
|
cdm→ |
componentDidMount method |
|
cwr→ |
componentWillReceiveProps method |
|
scu→ |
shouldComponentUpdate method |
|
cwup→ |
componentWillUpdate method |
|
cdup→ |
componentDidUpdate method |
|
cwun→ |
componentWillUnmount method |
|
gsbu→ |
getSnapshotBeforeUpdate method |
|
gdsfp→ |
static getDerivedStateFromProps
method |
|
cdc→ |
componentDidCatch method |
|
ren→ |
render method |
|
sst→ |
this.setState with object as
parameter |
|
ssf→ |
this.setState with function as
parameter |
|
props→ |
this.props |
|
state→ |
this.state |
|
bnd→ |
binds the this of method inside
the constructor |
|
disp→ |
MapDispatchToProps
redux function |
Convert String to Number in react js
Github link: https://github.com/adi501/react-js-example
19 October 2021
Rearrange an array in order – largest,smallest, 2nd largest , 2nd smallest,... nth largest, nth smallest
Input is Array of integers. task is to check if any duplicates is there need to print like "Invalid Input". if duplicates not there we need to print like.
1st Largest Number, 1st smallest number, 2nd largest number, 2nd smallest number,....nth largest number, nth smallest..
You can see Examples in below:
Example 1:
Input: arr[] = [5, 8, 1, 4, 2,2, 9, 3, 7, 6]
Output: Invalid Input
Example 2:
Input: arr[] = [1,3,4,2,5,7,9,8,6]
Output:
9
1
8
2
7
3
6
4
5
Solution in C#.net
using System;
using System.Linq;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int[] input1 = new int[] { 1, 2, 3, 4, 5, 7, 8, 9, 6 };
BigAndSmallNumbers(input1);
Console.ReadKey();
}
public static void BigAndSmallNumbers(int[] input1)
{
bool duplicate = false;
for (int i = 0; i < input1.Length; i++)
{
for (int j = i + 1; j < input1.Length; j++)
{
if (input1[i] == input1[j])
{
duplicate = true;
}
}
}
if (duplicate == false)
{
Array.Sort(input1);
Array.Reverse(input1);
int n = input1.Length;
int ArrIndex = 0;
int[] output = new int[input1.Length];
for (int i = 0, j = n - 1; i <= n / 2 || j > n / 2; i++, j--)
{
if (ArrIndex < n)
{
output[ArrIndex] = input1[i];
ArrIndex++;
}
if (ArrIndex < n)
{
output[ArrIndex] = input1[j];
ArrIndex++;
}
}
foreach (var a in output)
{
Console.WriteLine(a);
}
}
else
{
Console.WriteLine("Invalid Input");
}
}
}
}
18 October 2021
How to install missing node modules in react js
npm install
npm install: it will install all dependencies that are specified in the package.json
14 October 2021
usesqlserver not found .net core
First install the Microsoft.EntityFrameworkCore.SqlServer using NuGet Package like below
PM > Install-Package Microsoft.EntityFrameworkCore.SqlServer
Then, import the namespace in file
using Microsoft.EntityFrameworkCore;
28 September 2021
How to update models in VS 2019 from database in Entity Framework in ASP.NET Core
- Go to Tools -> Nuget Package Manager -> Package Manager Console (as below image)
- Next go to Package Manager Console and add below script and run as below image. To Update already created models via Scaffold-DbContext we need to use "Force" param as below script
Scaffold-DbContext "Server=ServerName;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force
1 August 2021
How to enable CORS in ASP.NET Core
open startup.cs page .net core project
In ConfigureServices() method:
public void ConfigureServices(IServiceCollection services)
{
--------
services.AddCors();
--------
}
In Configure() method:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
--------
app.UseCors(builder =>
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
);
--------
}
22 July 2021
Exponent operator in javascript
Output:
16
Github link : https://github.com/adi501/JavaScriptExamples.git
Template string in javascript
Output:
Hello world
Github link : https://github.com/adi501/JavaScriptExamples.git
Multiline string example in Javascript
Output:
this is a
multiline string
example
Github link : https://github.com/adi501/JavaScriptExamples.git
Default parameters in javascript
Output:
100
200
Github link : https://github.com/adi501/JavaScriptExamples.git
Arrow function in javascript
Output: 7
Github link : https://github.com/adi501/JavaScriptExamples.git
13 July 2021
How to find recently executed queries in SQL Server
select dest.text as Query,deqs.last_execution_time
from sys.dm_exec_query_stats as deqs
cross apply sys.dm_exec_sql_text(deqs.sql_handle) as dest
order by deqs.last_execution_time desc
(or)
select dest.text as Query,deqs.last_execution_time
from sys.dm_exec_query_stats as deqs
cross apply sys.dm_exec_sql_text(deqs.sql_handle) as dest
where dest.text like '%dm_exec_query_stats%'
order by deqs.last_execution_time desc