Skip to content

Instantly share code, notes, and snippets.

@tuanngominh
tuanngominh / django_with_vscode.sh
Last active September 13, 2018 07:47
Setup django with vscode
# Goals:
# - Setup django with virtual environment so can lint correctly in VScode
# Steps:
# Using venv instead of virtualenv
# Install package, run server in VSCode's python terminal
# Enable django for pylint, add to VSCode's setting: "python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
# References
# - https://github.com/Microsoft/vscode-python/issues/1185
@tuanngominh
tuanngominh / common-python-command.sh
Last active September 13, 2018 05:18
Common python command
# Create a virtual environment for a project:
cd repos
virtualenv project1
# To begin using the virtual environment, it needs to be activated:
source project1/bin/activate
# From now on, any package that you install using pip will be placed in the project1 folder,
# isolated from the global Python installation.
# Install packages as usual, for example:
@tuanngominh
tuanngominh / setup.sh
Last active September 16, 2018 06:50
setup python3 on mac OS X, High Sierra
# Install homebrew, check https://brew.sh/#install
# Install python3 with homebrew
brew install python
# View guide to link python to python3
brew info python
# From the guide, link python to python3 by adding /usr/local/opt/python/libexec/bin to PATH in
vi ~/.zshrc
@tuanngominh
tuanngominh / pragmatic-share-type-angular-cloud-function.ts
Last active June 19, 2018 04:10
Pragmatic solution for sharing type between angular and firebase cloud function
// cloud function
import {type1} from `../../feature1`; //relative import
// angular
import {type1} from `@app/shared/feature1`
// angular's tsconfig.json
{
"compilerOptions": {
"paths": {
@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": {
@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 / 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 / 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 / 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
},