Skip to content

Instantly share code, notes, and snippets.

@zacwest
zacwest / ios-font-sizes.swift
Last active May 6, 2024 13:04
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@bignerdranch
bignerdranch / BNRTimeBlock.h
Created March 9, 2012 13:51
Timing Utility Post 20120308
CGFloat BNRTimeBlock (void (^block)(void));
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
@doole
doole / wine32_macos.org
Last active April 4, 2024 21:16
Use win32 binaries on macOS 10.15/11.0

macOS wine 32/64-bit Setup

Run 32-bit apps on macOS Catalina (10.15) and Big Sur (11.0).

Installation

Dependencies

First install homebrew brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@krishnabhargav
krishnabhargav / kotlin-sealedclass-serialization.kt
Last active March 21, 2024 14:41
Using GSON to support serialization and deserialization of Kotlin Sealed Classes.
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import kotlin.jvm.internal.Reflection
import kotlin.reflect.KClass
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.allocArrayOf
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.usePinned
import platform.Foundation.NSData
import platform.Foundation.create
import platform.posix.memcpy
public fun ByteArray.toData(): NSData = memScoped {
NSData.create(bytes = allocArrayOf(this@toData),
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@Orangenhain
Orangenhain / import_minimizer.rb
Created November 28, 2013 12:45
Script that takes a ObjC .m file and tries to find unused (or duplicate) import statements by commenting out each #import line in turn and seeing if the project still compiles. You will have to change BUILD_DIR & BUILD_CMD.
#!/usr/bin/env ruby -w
class String
def starts_with?(prefix)
prefix.respond_to?(:to_str) && self[0, prefix.length] == prefix
end
end
HEADER_REGEX = /^#import\s+["<](.*)[">]/
@Sloy
Sloy / MockParcel.java
Created February 26, 2015 12:50
MockParcel for testing Parcelables implementations with the new Android's Unit testing support (http://tools.android.com/tech-docs/unit-testing-support). Only String and Long read/write implemented here. Add mock methods for other types.
import android.os.Parcel;
import java.util.ArrayList;
import java.util.List;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doAnswer;