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
//
// ContentView.swift
// Emoji Animation hero picker
//
// Created by Moussa on 3/4/2024.
//
import SwiftUI
struct ContentView: View {
@sebjvidal
sebjvidal / SceneDelegate.swift
Created June 27, 2023 18:14
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)
@krabs-github
krabs-github / JavaScript - Determine if Hex Color is Light or Dark.js
Last active June 18, 2024 19:44
[JavaScript - Determine if Hex Color is Light or Dark] JavaScript - Determine if Hex Color is Light or Dark #JavaScript
function lightOrDark(color) {
// Check the format of the color, HEX or RGB?
if (color.match(/^rgb/)) {
// If HEX --> store the red, green, blue values in separate variables
color = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
r = color[1];
g = color[2];
@JSerZANP
JSerZANP / ContentView.swift
Created March 4, 2021 14:01
communication between native(swiftUI) and wkwebview
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
var webView: WKWebView?
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.webView = webView
}
@sindresorhus
sindresorhus / esm-package.md
Last active July 5, 2024 10:12
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
import Foundation
struct Post: Decodable {
let id: String
let title: String
let body: String
}
struct GraphQLResult<T: Decodable>: Decodable {
let object: T?

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
import SwiftUI
import PlaygroundSupport
struct ShareSheet: View {
var body: some View {
VStack(spacing: 0) {
SheetHeaderView()
.padding()
Divider()
@nelvson
nelvson / postgres-docker.sh
Last active June 25, 2021 07:30
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
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props