Skip to content

Instantly share code, notes, and snippets.

Avatar
🦊
Foxing

riz automaticalldramatic

🦊
Foxing
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am automaticalldramatic on github.
  • I am reeseone (https://keybase.io/reeseone) on keybase.
  • I have a public key ASDcrqAF-d20V6sFhvrFoQqWZH8QdE7o_lDOm2EDLFt7awo

To claim this, I am signing this object:

View SyncCards.ts
export interface ObservablePaginatedResult {
cards: Observable<Array<SomeCards>>;
stop: () => void;
}
// returns an observable to subscribe to for changes and a method to stop listening to the snapshot
public SyncCards(pageSize: number = this.DefaultPageSize): <ObservablePaginatedResult> {
// an internal subject to handle streaming until the connection is closed. The buffer size of 1 fits my scenario and is up to the readers discretion
const cards$: ReplaySubject<Array<SomeCards>> = new ReplaySubject<SomeCards[]>(1);
View sortByDesc.ts
// this method accepts the property to order by. In our example, this would be priority
// sortByDesc('priority')
sortByDesc(prop: string) {
return this.returnedCardsArr.sort((a, b) => a[prop] < b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
}
// also a slightly verbose way of keeping only unique IDs replacing the ones received from the new call - cause the data also might have changed.
for (const card of c) {
if (!this.uniqueMap.has(card.id)) {
this.uniqueMap.set(card.id, true);
View snapshotWatchers.ts
private snapshotWatchers: Array<() => void> = [];
private syncRequest: Partial<ObservablePaginatedQuery>;
private syncCards() {
// assume some code here to initialise variables, create a service instance et al
// syncRequest is a class variable
this.syncRequest = WatchPaginatedCards();
this.syncRequest.cards.pipe().subscribe(
View WatchPaginatedCards.ts
// I updated the interface
export interface ObservablePaginatedResult {
cards: Observable<Array<SomeCards>>;
nextPage: IterableIterator<() => void>; // the method returned by iterator should be called to stop listening for changes on this page
}
public WatchPaginatedCards(pageSize: number = this.DefaultPageSize): <ObservablePaginatedQuery> {
const cards$: ReplaySubject<Array<SomeCards>> = new ReplaySubject<SomeCards[]>(1);
View keybase.md

Keybase proof

I hereby claim:

  • I am automaticalldramatic on github.
  • I am rizwaniqbal (https://keybase.io/rizwaniqbal) on keybase.
  • I have a public key ASBIwoVK08YsA2ZKfvShz-SYOLALs9SwVTOdzEDXrSgbtAo

To claim this, I am signing this object:

@automaticalldramatic
automaticalldramatic / postgres-brew.md
Created Nov 11, 2019 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)
View postgres-brew.md

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@automaticalldramatic
automaticalldramatic / app.yaml
Last active Sep 6, 2019
A cloudbuild that works for me with private packages
View app.yaml
env: flex
runtime: go1.12
main: cmd/some-service-name/main.go
@automaticalldramatic
automaticalldramatic / golang-nuts.go
Last active Sep 3, 2019 — forked from ryanfitz/golang-nuts.go
two ways to call a function every 2 seconds
View golang-nuts.go
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl
@automaticalldramatic
automaticalldramatic / list-struct.go
Last active Aug 21, 2019
List out all the values in a struct
View list-struct.go
// testing output
reflectedStruct := reflect.ValueOf(event)
// in case you want to list all values stored at the location of this pointer to a struct
if reflectedStruct.Kind() == reflect.Ptr {
reflectedStruct = reflectedStruct.Elem()
}
You can’t perform that action at this time.