Skip to content

Instantly share code, notes, and snippets.

View ylem's full-sized avatar

WEI LU ylem

  • CoreMeta.tech
  • Manchester
View GitHub Profile
@ylem
ylem / CustomTabBar.swift
Last active April 10, 2023 20:40
Custom TabBar
import SwiftUI
struct CustomTabBar: View {
@State private var selectedTab: TabItem = .home
private let height: CGFloat = 80
var body: some View {
ZStack(alignment: .bottom) {
selectedTab.view
.frame(maxWidth: .infinity, maxHeight: .infinity)
@ylem
ylem / InputTextView.swift
Last active April 10, 2023 20:42
InputTextView with indicator border
import SwiftUI
@available(iOS 15.0, *)
struct InputTextView: View {
private let placeholder: String?
private let text: Binding<String>
private let isError: Binding<Bool>
@FocusState private var isFocused: Bool
init(
@ylem
ylem / auth.kt
Created March 30, 2023 11:30
OAuth in Kotlin
import android.util.Base64
import com.google.gson.GsonBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import okhttp3.*
import java.io.IOException
@ylem
ylem / auth.swift
Last active April 10, 2023 20:43
OAuth login
import Foundation
import Combine
class OAuthLogin {
static let shared = OAuthLogin()
let baseURL = "https://your-auth-server.com"
let clientID = "your-client-id"
let clientSecret = "your-client-secret"

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@ylem
ylem / tips
Created January 16, 2021 18:44
AWS/Terraform tips
1: create a new API:
* Create policy
* Create role
* Create Lambda ( try to use ```terraform plan``` to create .zip file)
* Create APIGateway
Done
2: ERROR - Terraform: Error locking state: Error acquiring the state lock
@ylem
ylem / country_code.json
Last active September 17, 2019 23:15
List of all countries with their 2 digit codes (ISO 3166-1)
[{
"Code": "AF",
"Name": "Afghanistan"
}, {
"Code": "AX",
"Name": "Åland Islands"
}, {
"Code": "AL",
"Name": "Albania"
}, {
#server side:
#server live directory: /var/www/domain.com
#server repository: /var/repo/site.git
1. clone project from git/bitbucket into /var/www/domain.com or init the folder by "git init".
2. go to /var/repo/site.git and init the folder as git bare
$git init --bare
--bare means that our folder will have no source files, just the version control.
@ylem
ylem / CenterItemInCollectionView.playground
Last active October 22, 2024 04:04
Scrolling item on a horizontal UICollectionView, stopped item on center of screen.
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class WLCollectionCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ylem
ylem / uploadImage.m
Created January 26, 2017 18:39
Upload image by NSURLSession
/**
* Generate a mutable URLRequest with authorisation Token (if has) and User-Agent
*
* @param url NSURL object
* @param method GET, POST, PUT or DELETE
* @return NSMutableURLRequest object, can be modify (add more values) later.
*/
- (NSMutableURLRequest *)requestUrl:(NSURL *)url method:(NSString *)method {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData