Skip to content

Instantly share code, notes, and snippets.

View a-patel's full-sized avatar
👨‍💻
while (!sleep) { learn(); }

Ashish Patel a-patel

👨‍💻
while (!sleep) { learn(); }
View GitHub Profile
@a-patel
a-patel / guards.module.ts
Created November 16, 2018 18:38
Implementing Guard in Angular
import { NgModule } from "@angular/core";
import { AuthenticationGuard } from "./authentication.guard";
@NgModule({
providers: [AuthenticationGuard]
})
export class GuardsModule { }
@a-patel
a-patel / interceptors.module.ts
Created November 16, 2018 18:39
HTTP Interceptor in Angular
import { HTTP_INTERCEPTORS } from "@angular/common/http";
import { NgModule } from "@angular/core";
import { CustomHttpInterceptor } from "./http.interceptor";
@NgModule({
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: CustomHttpInterceptor, multi: true }
]
})
export class InterceptorsModule { }
@a-patel
a-patel / SqlServerHealthCheck.cs
Last active June 16, 2019 20:58
Health Check in ASP.NET Core (Sql Server)
public class SqlServerHealthCheck : IHealthCheck
{
private readonly string _connectionString;
public SqlServerHealthCheck(string connectionString)
{
_connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
// Use dependency injection (DI) to supply any required services to the health check.
}
@a-patel
a-patel / HealthCheck-Startup.cs
Last active September 30, 2019 10:37
Health Check in ASP.NET Core (Sql Server)
public void ConfigureServices(IServiceCollection services)
{
...
// Registers health check services
services.AddHealthChecks()
.AddCheck<SqlServerHealthCheck>("sql");
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
@a-patel
a-patel / validation.service.ts
Created November 16, 2018 19:06
RegEx Validation Service in Angular
import { Injectable } from "@angular/core";
@Injectable({ providedIn: "root" })
export class ValidationService {
private date = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))) ?((20|21|22|23|[01]\d|\d)(([:.][0-5]\d){1,2}))?$/;
private decimal = /^((-?[1-9]+)|[0-9]+)(\.?|\,?)([0-9]*)$/;
private email = /^([a-z0-9_\.\-]{3,})@([\da-z\.\-]{3,})\.([a-z\.]{2,6})$/;
@a-patel
a-patel / token.service.ts
Created November 16, 2018 19:07
Token Service in Angular
import { Injectable } from "@angular/core";
@Injectable({ providedIn: "root" })
export class TokenService {
private token = "token";
clear(): void {
sessionStorage.removeItem(this.token);
}
@a-patel
a-patel / authentication.service.ts
Created November 16, 2018 19:13
Authentication Service in Angular
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Router } from "@angular/router";
import { TokenService } from "../core/services/token.service";
import { SignInModel } from "../models/signIn.model";
@Injectable({ providedIn: "root" })
export class AuthenticationService {
constructor(
private readonly http: HttpClient,
@a-patel
a-patel / ASPNETCore-KeyVault-Program.cs
Created November 17, 2018 10:30
Keeping Secrets Safe in ASP.NET Core with Azure Key Vault
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, builder) =>
@a-patel
a-patel / LiteX-Storage-Controller.cs
Last active September 25, 2019 17:34
LiteX Storage is simple yet powerful and very high-performance storage mechanism and incorporating both synchronous and asynchronous usage with some advanced usage of cloud storage which can help us to handle storage more easier!
/// <summary>
/// Storage (Factory) controller
/// </summary>
[Route("api/[controller]")]
public class StorageFactoryController : Controller
{
#region Fields
// when using single provider
// private readonly ILiteXBlobService _provider;
@a-patel
a-patel / LiteX-Storage-Azure-Startup.cs
Last active November 27, 2018 07:04
LiteX Storage Startup
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// 1. Use default configuration from appsettings.json's 'AzureBlobConfig'
services.AddLiteXAzureBlobService();
//OR
// 2. Load configuration settings using options.
services.AddLiteXAzureBlobService(option =>