Skip to content

Instantly share code, notes, and snippets.

View kamwing's full-sized avatar
🥑
Work smarter not harder

Ngai Kam Wing kamwing

🥑
Work smarter not harder
View GitHub Profile
@kamwing
kamwing / SceneDelegate.swift
Created June 28, 2023 08:42 — forked from sebjvidal/SceneDelegate.swift
Custom UINavigationBar Height
// MARK: - SceneDelegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let navigationController = UINavigationController(navigationBarClass: NavigationBar.self, toolbarClass: nil)
(navigationController.navigationBar as! NavigationBar).preferredHeight = 88
navigationController.setViewControllers([ViewController()], animated: false)
@kamwing
kamwing / mac-setup-redis.md
Created February 4, 2023 17:16 — forked from tomysmile/mac-setup-redis.md
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
import Foundation
struct Post: Decodable {
let id: String
let title: String
let body: String
}
struct GraphQLResult<T: Decodable>: Decodable {
let object: T?
@kamwing
kamwing / setup.md
Created October 12, 2022 12:12 — forked from akella/setup.md
My Setup
@kamwing
kamwing / stripe-keys-and-ids.tsv
Created August 21, 2021 22:17 — forked from fnky/stripe-keys-and-ids.tsv
Stripe keys and IDs
Prefix Description Notes
sk_live_ Live secret key Secret key in a live environment.
pk_live_ Live public key Public key in a live environment.
pst_live_ Live Connection token Connection token in a live environment.
sk_test_ Test secret key Pecret key in a test environment.
pk_test_ Test public key Public key in a test environment.
pst_test_ Test Connection token Connection token in a test environment.
ac_ Platform Client ID Identifier for an auth code/client id.
acct_ Account ID Identifier for an Account object.
ch_ Charge ID Identifier for a Charge object.
@kamwing
kamwing / Guardian JWT.md
Created July 7, 2021 08:44 — forked from nikneroz/Guardian JWT.md
Elixir + Phoenix Framework + Guardian + JWT. This is tutorial and step by step installation guide.

Elixir + Phoenix Framework + Guardian + JWT + Comeonin

Preparing environment

We need to generate secret key for development environment.

mix phoenix.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hf

Let's generate User model and controller.

@kamwing
kamwing / postgres-docker.sh
Created June 25, 2021 07:30 — forked from nelvson/postgres-docker.sh
Backup a postgres db on Docker
# backup both tables and data
docker exec -t CONTAINER pg_dumpall -c -U USERNAME > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
# backup data only
docker exec -t api_postgres_1 pg_dumpall -c -U prisma -a > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
# apply backup
cat your_dump.sql | docker exec -i CONTAINER psql -U USERNAME

Backup and Restore Postgres databases

https://www.postgresqltutorial.com/postgresql-backup-database/

Backup a specific database use pg_dump

docker exec -t your-db-container pg_dump -U strapi -W -F t database-name > mypostgres_strapi_`date +%d-%m-%Y"_"%H_%M_%S`.sql

Backup all databases use pg_dumpall

docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Backup:
docker exec -t -u postgres your-db-container pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat your_dump.sql | docker exec -i your-db-container psql -Upostgres
@kamwing
kamwing / paste.js
Created October 8, 2020 02:42 — forked from cesarfigueroa/paste.js
Paste onto a [contenteditable] element as plain text
document.querySelector('[contenteditable]').addEventListener('paste', function (event) {
event.preventDefault();
document.execCommand('inserttext', false, event.clipboardData.getData('text/plain'));
});