Skip to content

Instantly share code, notes, and snippets.

@ItaruTran
ItaruTran / save-working-code.ps1
Last active February 1, 2023 03:32
Save and restore work-in-progress code 🚧
$ErrorActionPreference = "Stop"
$PREFIX='WIP'
$IGNORE_FILE='.working.gitignore'
$SAVED_IGNORE_FILE='.project.gitignore'
$is_restore = $args[0] -eq '-r'
if ($is_restore) {
@ItaruTran
ItaruTran / log-manager.js
Last active July 6, 2022 09:51
Create and control log level by env (Example: `LIMIT_LOG=abc-module.*= verbose; main= info; x-module.api= warn`)
import { loggers, format, transports } from 'winston';
import { inspect } from 'util';
const myFormat = format.printf((info) => {
const { level, message, label, timestamp } = info;
const extra = info[Symbol.for('splat')];
let text = `${timestamp} [${label}] ${level}: ${message}`;
if (extra) {
for (let index = 0; index < extra.length; index++) {
@ItaruTran
ItaruTran / README.md
Created May 27, 2022 11:09 — forked from Thong-Tran/README.md
Modify document by vitual printer

Modify document by vitual printer

Modify document when printing in Windows by create virtual printer

@ItaruTran
ItaruTran / README.md
Created May 27, 2022 11:09 — forked from Thong-Tran/README.md
Set up auto build and distribute flutter app on Appcenter

Auto deploying flutter app via Appcenter

Configure project

  • Active AndroidX if it isn’t already.
  • Create and checkout to new branch (appcenter currently only listen trigger from commit code on branch)
  • Setup android:
    • Comment those lines in file android/.gitignore

gradle-wrapper.jar

@ItaruTran
ItaruTran / README.md
Created May 27, 2022 11:09 — forked from Thong-Tran/README.md
Set up ec2 with pm2, nginx

Deploy EC2 windows server core with nginx, nodejs

Note:

  • setup-ec2-windows.ps1 doesn't have SSH's setup script because of some bug. You need to set it up manually after deployment

Deploy stack

  • Create file opts.yml with options:
    • MyIP: ip for access to server
    • KeyName: aws key pair for ec2
@ItaruTran
ItaruTran / gsheet-add-data.ts
Created May 27, 2022 11:07 — forked from Thong-Tran/gsheet-add-data.ts
Use Google cloud function for stream data from firebase to gsheet
import * as functions from 'firebase-functions';
import { OAuth2Client } from 'google-auth-library';
import { google, sheets_v4 } from 'googleapis';
import admin from 'firebase-admin';
// Use firebase functions:config:set to configure your watchedpaths object:
// googleapi.client_id = Google API client ID,
// googleapi.client_secret = client secret, and
// googleapi.sheet_id = Google Sheet id (long string in middle of sheet URL)
// watchedpaths.data_path = Firebase path for data to be synced to Google Sheet
@ItaruTran
ItaruTran / README.md
Created May 27, 2022 11:07 — forked from Thong-Tran/README.md
Run locust workers

Run locust workers

python .\locust-workers.py -h
usage: locust-workers.py [-h] [-p path] [-s num] [-f LOCUSTFILE]

Run locust workers

optional arguments:
 -h, --help show this help message and exit
@ItaruTran
ItaruTran / pyproject.toml
Created May 27, 2022 11:04 — forked from Thong-Tran/pyproject.toml
High performance Fastapi on Windows
[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = "^3.7"
fastapi = {extras = ["all"], version = "^0.52.0"}
uvicorn = "^0.11.5"
orjson = "^3.2.2"
@ItaruTran
ItaruTran / latest-user-property.sql
Created May 27, 2022 11:04 — forked from Thong-Tran/latest-user-property.sql
Custom query for firebase event use in google datastudio
SELECT
event_date, event_timestamp, event_name, app_info.id, user_pseudo_id,
max(
if(user_property.key = "user_status", user_property.value.string_value, NULL)
) user_status
FROM
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY user_pseudo_id ORDER BY event_timestamp DESC ) as rn
FROM `project-id.dataset-id.events_*`
@ItaruTran
ItaruTran / parse-i18n.py
Created May 27, 2022 11:03 — forked from Thong-Tran/parse-i18n.py
Parser and generate i18n for typescript
#!/usr/bin/python3
import sys
if sys.version_info < (3, 6):
print("Must be using Python 3.6 or higher")
exit(1)
from typing import List
import os