Skip to content

Instantly share code, notes, and snippets.

View KanshuYokoo's full-sized avatar

kkaannnssshh KanshuYokoo

View GitHub Profile
@KanshuYokoo
KanshuYokoo / Sequence+keypathUtils.swift
Created April 13, 2020 16:31
utilities with swift keypath, sorting, map, min, max
extension Sequence {
func sorted<T: Comparable>(by keyPath:KeyPath<Element, T>) -> [Element]{
return sorted {a, b in
return a[keyPath: keyPath] < b[keyPath:keyPath]
}
}
func map <T> (_ keyPath: KeyPath<Element, T>) -> [T] {
return map {$0[keyPath: keyPath]}
}
@KanshuYokoo
KanshuYokoo / SwiftUIArcView.swift
Created April 2, 2020 12:21
SwiftUI shape Example, Arc
import SwiftUI
struct ArcView: View {
var body: some View {
Arc(startAngle: .degrees(0), endAngle: .degrees(110), clockwise: true)
.stroke(Color.blue, lineWidth: 5)
.frame(width: 300, height: 300, alignment: .center)
}
}
@KanshuYokoo
KanshuYokoo / SwiftUIToastView.swift
Created April 2, 2020 11:44
SwiftuI ToastView example
import SwiftUI
struct ToastView: View {
@State private var liked: Bool = false
var body: some View {
VStack {
LikeButton(liked: $liked)
}
.toast(isShowing: $liked, text: Text("Hello toast!"))
@KanshuYokoo
KanshuYokoo / SwiftUITriangleView.swift
Created April 2, 2020 10:00
SwiftUI Shape example, Triangle
import SwiftUI
struct TriangleView: View {
static let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255)
static let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255)
var body: some View {
Triangle()
.fill(LinearGradient(
gradient: .init(colors: [Self.gradientStart, Self.gradientEnd]),
startPoint: .init(x: 0.5, y: 0),
@KanshuYokoo
KanshuYokoo / obective-c device token
Created January 25, 2020 14:57
ios device token: obective-c
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
NSUInteger dataLength = deviceToken.length;
const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (int i = 0; i < dataLength; ++i) {
[hexString appendFormat:@"%02x", dataBuffer[i]];
}
let token = [hexString copy];
@KanshuYokoo
KanshuYokoo / bash P1
Created December 25, 2019 17:59
bash terminal set to show git branch. it is supposed to be write in bashrc or bash_profile
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\h:\W:\$(parse_git_branch)$"
@KanshuYokoo
KanshuYokoo / DeviceInfos.swift
Created June 11, 2019 07:19
ios device types
import Foundation
import UIKit
struct DeviceInfos {
static let IS_IPAD = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad)
static let IS_IPHONE = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone)
static let IS_RETINA = (UIScreen.main.scale >= 2.0)
static let SCREEN_WIDTH = (UIScreen.main.bounds.size.width)
static let SCREEN_HEIGHT = (UIScreen.main.bounds.size.height)
static let SCREEN_MAX_LENGTH = SCREEN_WIDTH >= SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT
static let SCREEN_MIN_LENGTH = SCREEN_WIDTH <= SCREEN_HEIGHT ? SCREEN_WIDTH : SCREEN_HEIGHT
@KanshuYokoo
KanshuYokoo / dynamicalyFitfontSize
Created May 5, 2019 18:20
swift ios, fit the font size of UILabel
textlabel.adjustsFontSizeToFitWidth = true
textlabel.minimumScaleFactor = 0.5
@KanshuYokoo
KanshuYokoo / isKeyValue
Created April 20, 2019 12:31
NSMutableDictionary is Key value pair existing the dictionary. swit
extension NSMutableDictionary {
func isExist(forKey key: String) -> Bool {
return self[key] != nil
}
func isKeyValue<T: Equatable> (value: T, forKey key: String) -> Bool {
if(!isExist(forKey: key)){
return false
}
let val = self[key] as! T
return val == value
@KanshuYokoo
KanshuYokoo / ios swift keyChainMabager
Created March 28, 2019 18:05
ios swift keyChainMabager for GenericPassword
class KeyChainManager {
static func saveGenericPassword(service:String, account:String, password:String) -> Void {
let account = userNameTextField.text
let passwordUtf8 = password.data(using: String.Encoding.utf8)!
let addquery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account!,
kSecAttrService as String: service ,
kSecValueData as String: passwordUtf8!]