Skip to content

Instantly share code, notes, and snippets.

View touhidrahman's full-sized avatar

Touhid Rahman touhidrahman

View GitHub Profile
export interface CustomEvent {
key: string;
payload: unknown;
}
@Injectable({ providedIn: 'root' })
export class EventBusService {
private eventsSubject = new Subject<CustomEvent>();
@touhidrahman
touhidrahman / tailwind.directive.ts
Last active May 14, 2021 11:36
Tailwind Directive All
/** tailwind.directive.ts */
import { Directive, HostBinding, Input } from '@angular/core'
import { APP_TAILWIND_STYLES } from '@core/values/styles'
@Directive({
selector: '[tailwind]',
})
export class TailwindDirective {
private twClasses = ''
@touhidrahman
touhidrahman / medium-tw-directive-styles.ts
Created May 14, 2021 11:35
Tailwind Directive Styles Object
export const APP_TAILWIND_STYLES: { [key: string]: string } = {
button: `
hover:bg-indigo-500
px-6 py-2
tracking-wider
text-indigo-50
uppercase
bg-indigo-400
rounded
`,
import { Directive, HostBinding, Input } from '@angular/core'
import { APP_TAILWIND_STYLES } from '@core/values/styles'
@Directive({
selector: '[tailwind]',
})
export class TailwindDirective {
private twClasses = ''
@HostBinding('class')
<div tailwind="layoutCenter" class="py-12">
<button [tailwind]="'button buttonSecondary'">My Button</button>
<!-- or -->
<button tailwind="button buttonSecondary">My Button</button>
</div>
@touhidrahman
touhidrahman / supabase.service.ts
Created July 29, 2021 23:38
supabase.service.ts
import { Injectable } from '@angular/core'
import { environment } from '@environment/environment'
import { AuthChangeEvent, createClient, Session, SupabaseClient } from '@supabase/supabase-js'
@Injectable({
providedIn: 'root',
})
export class SupabaseService {
private supabase: SupabaseClient
@touhidrahman
touhidrahman / supabase-query-helper.type.ts
Last active July 29, 2021 23:55
supabase-query-helper.type.ts
export type FilterOperator =
| 'eq' | 'neq'
| 'gt' | 'gte'
| 'lt' | 'lte'
| 'like' | 'ilike'
| 'is' | 'in'
| 'cs' | 'cd'
| 'sl' | 'sr'
| 'nxl' | 'nxr'
| 'adj' | 'ov'
@touhidrahman
touhidrahman / base.service.ts
Last active March 5, 2022 02:42
base.service.ts (supabase)
export class BaseService<T> {
protected resource: string // table name
constructor(protected supabase: SupabaseService, resource: string) {
this.resource = resource
}
findById(id: number, select = '*'): Observable<T> {
const query = this.supabase.table(this.resource).select(select).match({ id }).single()
return from(query).pipe(map((res) => res.body as T))
@touhidrahman
touhidrahman / product.service.ts
Last active July 30, 2021 01:29
product.service.ts - supabase base service implementation
import { Injectable } from '@angular/core'
import { BaseService } from '@core/services/base.service'
import { SupabaseService } from '@core/services/supabase.service'
import { Product } from '@features/products/types/product'
const TABLE_PRODUCT = 'products'
@Injectable({
providedIn: 'root',
})
@touhidrahman
touhidrahman / autosize-textarea.directive.ts
Last active August 17, 2021 21:06
autosize-textarea.directive.ts
import { Directive, ElementRef, HostListener, Input } from "@angular/core";
@Directive({
selector: "[appTextareaAutosize]"
})
export class TextareaAutosizeDirective {
@Input() minRows = 2;
@Input() maxRows = 4;
private offsetHeight = 0;