Skip to content

Instantly share code, notes, and snippets.

View rafaeldcastro's full-sized avatar

rafaeldcastro rafaeldcastro

View GitHub Profile
@rafaeldcastro
rafaeldcastro / util.service.ts
Created May 24, 2021 16:10
Utilities service
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class UtilsService {
/**
* Turn somthing like this: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCA..."
* into a BLOB
@rafaeldcastro
rafaeldcastro / event-emitter.service.ts
Created May 20, 2021 13:09
Not an "angular" way to handle notifications/subscribes, but come in handy.
import { Injectable } from '@angular/core';
import { EventEmitter } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class EventEmitterService {
private static emitters: { [notificationName: string]: EventEmitter<any> } = {}
static get(notificationName: string): EventEmitter<any>{
if (!this.emitters[notificationName])
@rafaeldcastro
rafaeldcastro / storage.service.ts
Last active August 15, 2021 09:04
Angular - Ionic | Storage service using @ionic/storage. Wich is a reasonable abstraction to use IndexedDB
import { Injectable } from '@angular/core';
import { APP_CONSTANTS } from '@constants/app.constants';
import { Storage } from '@ionic/storage';
@Injectable({
providedIn: 'root'
})
export class StorageService {
private _storage: Storage | null = null;
@rafaeldcastro
rafaeldcastro / localstorage.service.ts
Last active May 20, 2021 13:11
Angular LocalStorage Service
import { Injectable } from '@angular/core';
import { APP_CONSTANTS } from '@constants/app.constants';
@Injectable({
providedIn: 'root'
})
export class LocalStorageService {
constructor() { }
@rafaeldcastro
rafaeldcastro / token.interceptor.service.ts
Last active January 10, 2023 13:39
Angular - Token HTTP Interceptor
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
/**SERVICES */
import { AuthService } from '@pages/auth/shared/services/auth/auth.service';
@Injectable({
providedIn: 'root'
})
@rafaeldcastro
rafaeldcastro / gist:96ce2b580b643c6ecf2a17632c7d2ef7
Created May 5, 2021 17:19
Remove all duplicates from an Array of objects
/*
arr = [ {id: 1, name: 'Foo'}, {id: 1, name: 'Foo'}]
*/
let noDuplicates = arr.filter((obj_a, index, self) =>
index === self.findIndex((obj_b) => (
obj_a.attr === obj_b.attr //CHANGE attr for any attribute, like id
))
)