Skip to content

Instantly share code, notes, and snippets.

View AnkitMaheshwariIn's full-sized avatar

Ankit Maheshwari AnkitMaheshwariIn

View GitHub Profile
@AnkitMaheshwariIn
AnkitMaheshwariIn / hide-header.directive.ts
Last active November 29, 2019 18:10
hide-header.directive.ts - this directive will do the actual job to hide header on content scroll in Ionic Framework.
// hide-header.directive.ts - this directive will do the actual job to hide header on content scroll in Ionic Framework.
import { Directive, HostListener, Input, OnInit, Renderer2 } from '@angular/core';
import { DomController } from '@ionic/angular';
@Directive({
selector: '[appHideHeader]'
})
export class HideHeaderDirective implements OnInit {
@AnkitMaheshwariIn
AnkitMaheshwariIn / shared.module.ts
Last active November 30, 2019 07:09
If we want to use the directive ( hide-header.directive ) for more than one directive, we need to create a SharedModule. So that we can add the SharedModule to all the modules we want to use the directive in.
// If we want to use the directive ( hide-header.directive ) for more than one directive, we need to create a SharedModule.
// So that we can add the SharedModule to all the modules we want to use the directive in.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HideHeaderDirective } from '../directives/hide-header.directive';
@NgModule({
declarations: [HideHeaderDirective],
exports: [HideHeaderDirective],
@AnkitMaheshwariIn
AnkitMaheshwariIn / firebase.json
Created December 9, 2019 09:36
For PWA ensure your firebase.json file looks like this:
{
"hosting": {
"public": "www",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"headers": [
{
@AnkitMaheshwariIn
AnkitMaheshwariIn / home.page.ts
Last active December 13, 2019 16:28
AngularFireMessaging service to request user permission requestPushNotificationsPermission()
// home.page.ts
import { Component } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
@AnkitMaheshwariIn
AnkitMaheshwariIn / auth.service.ts
Last active June 29, 2020 11:40
Creating the Auth Service. Our service will be a central place that allows us to login, signup or logout users, so we’ll define methods for these 3 actions. All the authentication logic will be in the AuthService, which will allow us to create components that doesn’t need to implement any auth logic and will help keep our components simple.
// auth.service.ts
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AuthService {
user: Observable<firebase.User>;
@AnkitMaheshwariIn
AnkitMaheshwariIn / app.component.ts
Created December 16, 2019 11:00
Create a component that allow us for logging in, signing up or logging out using AngularFire Service ( https://gist.github.com/AnkitMaheshwariIn/5342f81a3c30a4ebe6b307822288b403 )
/*
file-name: app.component.ts
The important code for logging-in, signing-up or logging-out are:
— import 'AuthService' at line no. 17
— declare variable 'email' and 'password' at line no. 25-26
— inject service 'authService' at line no. 45
— method for signup() at line no. 57
— method for login() at line no. 62
— method for logout() at line no. 67
@AnkitMaheshwariIn
AnkitMaheshwariIn / app.component.html
Last active December 20, 2019 12:13
Create a component that allow us for logging in, signing up or logging out using AngularFire Service ( https://gist.github.com/AnkitMaheshwariIn/5342f81a3c30a4ebe6b307822288b403 ) and Component ( https://gist.github.com/AnkitMaheshwariIn/c14c69c1d327407bb08208e1eef28cee )
<!--
file-name: app.component.html
The important code for logging-in, signing-up or logging-out are from line no. 08 to 29
— rest you can manage yourself based on user is logging-in or logging-out |
you can any time check user logging-in/out status using *ngIf="!(authService.user | async)"
-->
<ion-app>
<ion-content padding>
<h1 *ngIf="authService.user | async">
Welcome {{ (authService.user | async)?.email }}!
@AnkitMaheshwariIn
AnkitMaheshwariIn / home.page.ts
Created December 17, 2019 12:14
Code to copy to clipboard using capacitor.
/*
file-name: home.page.ts
The code for copyToClipboard() are at line no. 34-39
*/
import { Component } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { Plugins } from '@capacitor/core';
@Component({
selector: 'app-home',
@AnkitMaheshwariIn
AnkitMaheshwariIn / home.page.ts
Last active December 18, 2019 08:03
Adding the Geolocation Plugin using Ionic Capacitor in PWA. The Geolocation API provides simple methods for getting and tracking the current position of the device using GPS, along with altitude, heading, and speed information if available.
/*
file-name: home.page.ts
The code to getCurrentPosition() is at line no. 44-47
The code to watchPosition() is at line no. 50-54
*/
import { Component } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { Plugins } from '@capacitor/core';
const { Geolocation, Clipboard } = Plugins;
@AnkitMaheshwariIn
AnkitMaheshwariIn / index.ts
Last active December 18, 2019 12:01
Image Resizing in Firebase using Firebase Cloud Storage Functions.
import * as functions from 'firebase-functions';
// What this function does -> Image Resizing With a Firebase Cloud Storage Function
// The single most common Cloud Function use-case for a storage bucket is to resize images to thumbnails in the background.
// Note: various modifications done in this code to get this code working without errors.
import { Storage } from '@google-cloud/storage';
const gcs = new Storage();