Skip to content

Instantly share code, notes, and snippets.

View sangwin's full-sized avatar
🎯
Focusing

Sangwin Gawande sangwin

🎯
Focusing
View GitHub Profile
@sangwin
sangwin / js-singleton-function.js
Last active May 27, 2022 06:32
Singletons are used to create an instance of a class if it does not exist or else return the reference of the existing one. This means that singletons are created exactly once during the runtime of the application in the global scope.
var Singleton = (function () {
var instance;
function createInstance() {
var object = new Object("I am the instance");
return object;
}
return {
getInstance: function () {
const add = (function () {
let counter = 0;
return function () {counter += 1; return counter;}
})();
add();
// Example Explained
// The variable add is assigned to the return value of a self-invoking function.
@sangwin
sangwin / app.module.ts
Created May 28, 2022 08:07
Manual Bootstrapping Components In Angular Modules
import { ApplicationRef, DoBootstrap, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { SecondaryComponent } from './secondary/secondary.component';
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent, SecondaryComponent],
entryComponents: [AppComponent, SecondaryComponent]
@sangwin
sangwin / app-routing.module.ts
Last active May 30, 2022 06:43
Modules Custom Preloading, Eager Loading and Lazy Loading In Angular Demo
import { NgModule, Injectable } from '@angular/core';
import { RouterModule, Routes, PreloadingStrategy, Route } from '@angular/router';
import { Observable, of, timer } from 'rxjs';
import { flatMap } from 'rxjs/operators'
// Modules will current route will load immediately
const routes: Routes = [
{
path: 'auth',
@sangwin
sangwin / countries.json
Last active May 31, 2022 06:21
Countries List with name, Region code, capital, region, currency, language, flags
[
{
"name": "Afghanistan",
"code": "AF",
"capital": "Kabul",
"region": "AS",
"currency": {
"code": "AFN",
"name": "Afghan afghani",
"symbol": "؋"
@sangwin
sangwin / india-states.json
Created May 31, 2022 06:21
Indian states with capital, code, name, coordinates and district list
[
{
"id": "1",
"type": "Union Territory",
"capital": "Mayabunder",
"code": "AN",
"name": "Andaman and Nicobar Islands",
"districts": [
{
"id": "1",
@sangwin
sangwin / india-cities.json
Created May 31, 2022 06:40
Indian Cities list with name and state
[
{
"id": "1",
"name": "Mumbai",
"state": "Maharashtra"
},
{
"id": "2",
"name": "Delhi",
"state": "Delhi"
@sangwin
sangwin / countries-flags.json
Created May 31, 2022 06:46
Countries list with respective code and flag emoji
[
{
"name": "Ascension Island",
"code": "AC",
"emoji": "🇦🇨",
"unicode": "U+1F1E6 U+1F1E8",
"image": "https://cdn.jsdelivr.net/npm/country-flag-emoji-json@2.0.0/dist/images/AC.svg"
},
{
"name": "Andorra",
@sangwin
sangwin / validators.ts
Last active May 31, 2022 08:13
Custom validators, email, max minlength, password for Reactive forms in Angular
// Custom validators, email, max minlength, password for Reactive forms in Angular
// Form Group
this.reactiveForm = this.formBuilder.group({
first_name: ['', [Validators.required,Validators.minLength(3),Validators.maxLength(50)]],
last_name: ['', [Validators.required,Validators.minLength(3),Validators.maxLength(50)]],
phone: ['', [Validators.required,ValidationService.checkLimit(5000000000,9999999999)]],
email: ['', [Validators.required, ValidationService.emailValidator]]
});
@sangwin
sangwin / php-email.php
Last active May 31, 2022 08:37
PHP email function with to, cc, from, header, subject, html message
<?php
$to = "someone@example.com, someone2@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>Sample HTML email</title>
</head>
<body>