Skip to content

Instantly share code, notes, and snippets.

@tuanngominh
tuanngominh / auth.js
Last active June 15, 2017 11:09
google cloud storage auth with firebase project
const gcs = require("@google-cloud/storage")({
 keyFilename: "serviceAccountKey.json"
});
@tuanngominh
tuanngominh / upload.js
Created June 15, 2017 11:13
google cloud storage upload
const bucket = gcs.bucket("bucket-name");
bucket.upload("/tmp/temp.csv", {
destination: "csv-folder/file.csv"
}, function(err, file) {
if (!err) {
// done
}
});
@tuanngominh
tuanngominh / cloud-functions-local-emulator.sh
Last active August 26, 2017 09:33
google cloud functions local emulator
#!/bin/sh
functions-emulator deploy \
--trigger-event=ref.write \
--trigger-provider=google.firebase.database \
--trigger-resource=sources/net-conversion/client-for-test-schema-and-big-query/s-4/schema \
--data='{"message":"Hello World"}'
@tuanngominh
tuanngominh / dom-input-focus-in-angular-with-native-element.ts
Last active December 6, 2024 18:44
input focus in angular using nativeElement
import { Component, ElementRef, ViewChild, AfterContentInit } from '@angular/core';
@Component({
selector: 'custom-form',
template: `
<form>
<input
placeholder="Name"
#nameInput
/>
@tuanngominh
tuanngominh / dom-input-focus-in-angular-through-renderer2.ts
Last active August 28, 2017 10:59
input focus in angular through renderer
import { Component, AfterContentInit, Renderer2 } from '@angular/core';
@Component({
selector: 'custom-form',
template: `
<form>
<input
placeholder="Name"
id="name-input"
/>
@tuanngominh
tuanngominh / firebase-dinosaurs-sample-database.json
Created September 25, 2017 07:59
firebase dinosaurs sample database
{
"dinosaurs": {
"bruhathkayosaurus" : {
"appeared" : -70000000,
"height" : 25,
"length" : 44,
"order" : "saurischia",
"vanished" : -70000000,
"weight" : 135000
},
@tuanngominh
tuanngominh / firebase-order-by-child.js
Last active September 25, 2017 09:03
Get ordered children in order in clientside with 'once()'
// WORKS
// firebase API - with once('value')
firebase().database().ref('/dinosaurs').orderByChild('height').once('value', function (snapshot) {
snapshot.forEach(function(child) {
console.log(child.val())
});
});
// firebase API - with once('child_added')
firebase().database().ref('/dinosaurs').orderByChild('height').once('child_added', function (snapshot) {
console.log(snapshot.val());
@tuanngominh
tuanngominh / combineLatest.ts
Last active October 29, 2018 07:41
combineLatest with realtime database
// rxjs 5.4
// angularfire2-4.0.0-rc.1
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import 'rxjs/add/observable/combineLatest';
import {Observable} from 'rxjs/Observable';
@Injectable()
@tuanngominh
tuanngominh / catch.ts
Last active October 3, 2017 06:30
Return observable from catch operator
// rxjs 5.4, ngrx 4.0.0, angular 4.0.0
import {Injectable} from '@angular/core';
@Injectable()
export class Task1Effects {
@Effect() task1$: Observable<Action> = this.actions$
.ofType('TASK1')
.switchMap((action: Action1) =>
this.service1.doSomething(action.param1)
.map((result) => new Action1Success(result))
@tuanngominh
tuanngominh / ideal-share-type-angular-cloud-function.ts
Last active June 19, 2018 04:10
Ideal solution for sharing type between angular and firebase cloud function
// cloud function
import {type1} from `@app/shared/feature1`
// angular
import {type1} from `@app/shared/feature1`
// angular's tsconfig.json
{
"compilerOptions": {
"paths": {