Skip to content

Instantly share code, notes, and snippets.

@kb100824
kb100824 / WKWebViewSizeToFit.swift
Created November 16, 2023 12:16 — forked from pkuecuekyan/WKWebViewSizeToFit.swift
Adjust height of WKWebView frame based on scrollHeight of the webView's content
// Since the WKWebView has no sizeToFit() method, increase the frame height of the webView to
// match the height of the content's scrollHeight
//
// The WKWebView's `navigationDelegate` property needs to be set for the delegate method to be called
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
if webView.isLoading == false {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
if let height = result as? CGFloat {
@kb100824
kb100824 / BrightnessValue.swift
Created August 16, 2023 06:52 — forked from Limon-O-O/BrightnessValue.swift
get brightness value from CMSampleBuffer
func getBrightnessValue(from sampleBuffer: CMSampleBuffer) -> Float {
guard
let metadataDict = CMCopyDictionaryOfAttachments(nil, sampleBuffer, kCMAttachmentMode_ShouldPropagate) as? [String: Any],
let exifMetadata = metadataDict[String(kCGImagePropertyExifDictionary)] as? [String: Any],
let brightnessValue = exifMetadata[String(kCGImagePropertyExifBrightnessValue)] as? Float
else { return 0.0 }
return brightnessValue
}
@kb100824
kb100824 / HookedSession.swift
Created October 26, 2022 06:36 — forked from buranmert/HookedSession.swift
Adding hooks to URLSession
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/
import Foundation
public extension URLSession {
internal typealias RequestInterceptor = HookedSession.RequestInterceptor
@kb100824
kb100824 / CustomUrlProtocolRequestInterceptor.swift
Created August 26, 2022 12:33 — forked from nil-biribiri/CustomUrlProtocolRequestInterceptor.swift
CustomURLProtocol for swizzle network logging.
import Foundation
extension CustomUrlProtocolRequestInterceptor: RequestInterceptor {
public func startRecording() {
URLProtocol.registerClass(CustormUrlProtocol.self)
swizzleProtocolClasses()
}
public func stopRecording() {
URLProtocol.unregisterClass(CustormUrlProtocol.self)
@kb100824
kb100824 / swiftc_help.txt
Created March 30, 2021 10:03 — forked from enomoto/swiftc_help.txt
$ swiftc -help
OVERVIEW: Swift compiler
USAGE: swiftc [options] <inputs>
MODES:
-dump-ast Parse and type-check input file(s) and dump AST(s)
-dump-parse Parse input file(s) and dump AST(s)
-dump-scope-maps <expanded-or-list-of-line:column>
Parse and type-check input file(s) and dump the scope map(s)
-dump-type-refinement-contexts
@kb100824
kb100824 / UIDevice+Ext.swift
Created August 31, 2020 09:16 — forked from SergLam/UIDevice+Ext.swift
Detect iOS device model
public extension UIDevice {
enum DeviceModelName: String {
case undefined
case iPodTouch5
case iPodTouch6
case iPhone4
case iPhone4s
case iPhone5
import UIKit
class CodeTextField: UITextField, UITextFieldDelegate {
let codeLength: Int
var characterSize: CGSize
var characterSpacing: CGFloat
let textPreprocess: (String) -> String
let validCharacterSet: CharacterSet
@kb100824
kb100824 / SRCopyableLabel.swift
Created December 24, 2018 10:11 — forked from steve228uk/SRCopyableLabel.swift
Copyable UILabel
//
// SRCopyableLabel.swift
//
// Created by Stephen Radford on 08/09/2015.
// Copyright (c) 2015 Cocoon Development Ltd. All rights reserved.
//
import UIKit
class SRCopyableLabel: UILabel {
@kb100824
kb100824 / git-key.md
Created September 14, 2018 08:53 — forked from yisibl/git-key.md
如何创建 Git 公钥

如何创建公钥

  1. 首先启动一个Git Bash窗口(非Windows用户直接打开终端)

  2. 执行:

    cd ~/.ssh

    如果返回“… No such file or directory”,说明没有生成过SSH Key,直接进入第4步。否则进入第3步备份!

@kb100824
kb100824 / index.ios.js
Last active August 18, 2016 02:52 — forked from Jpoliachik/index.ios.js
ReactNative LayoutAnimation
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
TouchableOpacity,
LayoutAnimation,
} from 'react-native';