Skip to content

Instantly share code, notes, and snippets.

View chiahsien's full-sized avatar

Nelson chiahsien

View GitHub Profile
@MaximKeegan
MaximKeegan / xcode_ramdisk.sh
Created April 12, 2012 03:28
Create a RAM disk for using with XCode
#!/bin/sh
# Create a RAM disk with same perms as mountpoint
# Script based on http://itux.idev.pro/2012/04/iservice-speed-up-your-xcode-%D0%BD%D0%B5%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D1%8B%D0%B5-%D1%81%D0%BF%D0%BE%D1%81%D0%BE%D0%B1%D1%8B/ with some additions
# Usage: sudo ./xcode_ramdisk.sh start
USERNAME=$(logname)
TMP_DIR="/private/tmp"
RUN_DIR="/var/run"
SYS_CACHES_DIR="/Library/Caches"
@steipete
steipete / UIKitLegacyDetector.m
Last active March 12, 2024 13:57
A simple way to detect at runtime if we're running in UIKit legacy mode or the new "flat" variant. Written for our PDF iOS SDK (http://pspdfkit.com), where the precompiled binary needs to detect at runtime in what variant it's running. Want more stuff like that? Follow me on Twitter: http://twitter.com/steipete
// Taken from http://PSPDFKit.com. This snippet is under public domain.
#define UIKitVersionNumber_iOS_7_0 0xB57
BOOL PSPDFIsUIKitFlatMode(void) {
static BOOL isUIKitFlatMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// We get the modern UIKit if system is running >= iOS 7 and we were linked with >= SDK 7.
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
isUIKitFlatMode = (NSVersionOfLinkTimeLibrary("UIKit") >> 16) >= UIKitVersionNumber_iOS_7_0;
}
@fdstevex
fdstevex / gist:6741638
Created September 28, 2013 12:34
Method to retrieve a list of downloadable fonts on iOS 7. This method may block for a while (it can involve a network call) so don't call on main thread. The return is a dictionary that maps font families to arrays of font names in that family.
+ (NSDictionary *)downloadableFonts
{
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)@{(id)kCTFontDownloadableAttribute : (id)kCFBooleanTrue});
CFArrayRef matchedDescs = CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL);
NSArray *array = (__bridge NSArray *)matchedDescs;
NSMutableDictionary *families = [NSMutableDictionary dictionary];
for (UIFontDescriptor *fontDescriptor in array) {
NSString *familyName = fontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute];
@steipete
steipete / PSPDFTextView.m
Created November 28, 2013 11:15
Works around the issue where UITextView doesn't scroll to the new line until there's a character in there. Super horrible workaround.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
// Horrible HACK for bug in UITextView where it won't scroll to the new line after pressing enter in the text view.
// I feel dirty for having to write this. Buggy at least within iOS 7.0 - 7.1b1.
if (PSPDFIsUIKitFlatMode() && [text isEqualToString:@"\n"] && range.location == textView.text.length) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^{
CGPoint contentOffset = textView.contentOffset;
CGFloat fontSize = textView.font.pointSize;
if (textView.contentSize.height - fontSize > textView.bounds.size.height) {
contentOffset.y += fontSize + 2.f; // add spacing