Skip to content

Instantly share code, notes, and snippets.

View KelvinJin's full-sized avatar
🎯
Focusing

Jin Wang KelvinJin

🎯
Focusing
  • Uthoft
  • Melbourne
View GitHub Profile
@swiftui-lab
swiftui-lab / showSizes.swift
Last active October 27, 2024 07:11
A debugging modifier for SwiftUI views (showSizes)
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: Implementation of the showSizes() debugging modifier
// blog article: https://swiftui-lab.com/layout-protocol-part-2
import SwiftUI
struct MeasureExample: View {
var body: some View {
VStack {
@utkukutlu
utkukutlu / AndroidNavigationComponentDialogFragment
Last active November 11, 2023 13:51
android navigation component add fragment instead of replace
Android Navigation Component Dialog Fragment
@lattner
lattner / TaskConcurrencyManifesto.md
Last active November 18, 2024 17:28
Swift Concurrency Manifesto
sealed class Optional<out T: Any> {
abstract val isPresent: Boolean
}
object None : Optional<Nothing>() {
override val isPresent: Boolean = false
}
data class Some<T: Any>(val value: T) : Optional<T>() {
override val isPresent: Boolean = true
}
fun <T: Any> T?.asOptional(): Optional<T> = this?.let(::Some) ?: None
//
// TSAN_OPTIONS.h
// PSPDFKit
//
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
// Example code licensed under MIT. Enjoy!
//
#if __has_feature(thread_sanitizer)
@jaredsburrows
jaredsburrows / RxBus1.java
Last active March 16, 2023 10:44
RxBus for RxJava 1 and RxJava 2
import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;
/**
* @author <a href="mailto:[email protected]">Jared Burrows</a>
*/
public final class RxBus {
private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create());
@chrislonge
chrislonge / AttributedHTMLFont.swift
Created August 4, 2016 14:33
Attributed HTML With Custom Font Parsing (Playground)
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))
containerView.backgroundColor = UIColor.whiteColor()
XCPlaygroundPage.currentPage.liveView = containerView
var aboutTextView = UITextView(frame: CGRect(x: 12.0, y: 20.0, width: containerView.frame.size.width - 12.0, height: 200.0))
aboutTextView.textAlignment = .Left
@baileysh9
baileysh9 / Parsing_productids.swift
Last active February 17, 2017 17:05
Parsing Product Ids from Receipt in Swift
func getProductIdFromReceipt(_ data:Data) -> String? //Swift 2: func getProductIdFromReceipt(data:NSData) -> String?
{
//Swift 2: var p = UnsafePointer<UInt8>(data.bytes)
//Swift 3
var p : UnsafePointer? = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
let dataLength = data.length
var type:Int32 = 0
var tag:Int32 = 0
@baileysh9
baileysh9 / Parsing_Receipt.swift
Last active February 9, 2017 16:44
Parsing Receipt in Swift
//Swift 2
//let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).memory.contents)
//var ptr = UnsafePointer<UInt8>(octets.memory.data)
//let end = ptr.advancedBy(Int(octets.memory.length))
//Swift 3
let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).pointee.contents)
var ptr = UnsafePointer<UInt8>(octets?.pointee.data)
let end = ptr?.advanced(by: Int((octets?.pointee.length)!))
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)