Skip to content

Instantly share code, notes, and snippets.

View touhidrahman's full-sized avatar

Touhid Rahman touhidrahman

View GitHub Profile
@touhidrahman
touhidrahman / view-article-page-state.service.ts
Last active February 6, 2021 16:18
view-article-page-state.service.ts
@Injectable()
export class ViewArticlePageStateService {
private currentState: ViewArticlePageState = initialState
private id: StateAtom<number> = new StateAtom(initialState.id)
private article: StateAtom<Article> = new StateAtom(initialState.article)
private loading: StateAtom<boolean> = new StateAtom(initialState.loading)
private searchTerm: StateAtom<string> = new StateAtom(initialState.searchTerm)
private comments: StateAtom<Comment[]> = new StateAtom(initialState.comments)
private commentsPagination: StateAtom<Params> = new StateAtom(initialState.commentsPagination)
@touhidrahman
touhidrahman / state-atom.ts
Last active February 5, 2021 00:02
Medium article state management with state atoms
import { BehaviorSubject, Observable } from 'rxjs'
import { distinctUntilChanged } from 'rxjs/operators'
export class StateAtom<T> {
value$: Observable<T>
private store: BehaviorSubject<T>
private value: T
private initialValue: T
@touhidrahman
touhidrahman / github-ubuntu.sh
Created October 15, 2018 14:42 — forked from dstroot/github-ubuntu.sh
Setting up github on Ubuntu
#!/bin/bash
###############################################
# To use:
# wget https://raw.github.com/gist/4411254
# chmod 777 github-ubuntu.sh
# ./github-ubuntu.sh
###############################################
echo "*****************************************"
echo " Step 1: Check your keys"
echo "*****************************************"
@touhidrahman
touhidrahman / flatten.ts
Last active October 11, 2018 21:43
Flatten a javascript object in specified structure (see comment block)
/**
* Run file
*
* `tsc flatten.ts && node flatten.js`
*
* Given following object:
{
test: "test1",
same: "same",
nested: {
@touhidrahman
touhidrahman / objectdiff.ts
Last active October 11, 2018 22:16
Compare two similar/identical javascript objects for differences. Returns the changed properties filled with updated value, and unchanged fields with null.
export class ObjectDiff {
isObject(obj: Object): boolean {
return typeof obj === 'object' && !Array.isArray(obj)
}
isArray(obj: Object): boolean {
return Array.isArray(obj)
}