Skip to content

Instantly share code, notes, and snippets.

View felix-schwarz's full-sized avatar

Felix Schwarz felix-schwarz

View GitHub Profile
@choefele
choefele / extension
Last active August 29, 2015 14:15
How to know at run-time whether your code runs inside an iOS extension
NSDictionary *extensionInfo = [NSBundle.mainBundle objectForInfoDictionaryKey:@"NSExtension"];
NSString *extensionPointIdentifier = extensionInfo[@"NSExtensionPointIdentifier"];
if ([extensionPointIdentifier isEqualToString:@"com.apple.watchkit"]) {
NSLog(@"WatchKit extension");
} else if ([extensionPointIdentifier isEqualToString:@"com.apple.widget-extension"]) {
NSLog(@"Widget extension");
} else if (extensionPointIdentifier == nil) {
NSLog(@"iOS app");
} else {
NSLog(@"Unknown extension type");
@catlan
catlan / gist:3946586
Created October 24, 2012 15:02
Little Snitch and his Friends
if ([[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.metakine.handsoff"])
{
NSAlert *alert = [NSAlert alertWithMessageText:@"Letter Opener found \"Hands Off!\" application"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"Make sure connections to www.creativeinaustria.com are allowed in \"Hands Off!\""];
[alert setIcon:[NSImage imageNamed:OMiCIcon]];
[alert runModal];
}
@markmunz
markmunz / NSAppleEventDescriptor+targetApplicationBundleID.m
Last active April 21, 2016 12:12
Avoiding the AESendMessage bug from 10.8.2 and, apparently, 10.9.0
+ (NSAppleEventDescriptor*)mm_appleEventWithEventClass:(AEEventClass)eventClass
eventID:(AEEventID)eventID
targetApplicationBundleID:(NSString*)bundleID
{
//NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithDescriptorType:typeApplicationBundleID
// data:[bundleID dataUsingEncoding:NSUTF8StringEncoding]];
NSAppleEventDescriptor *target = [self mm_targetDescriptorForBundleID:bundleID];
return [NSAppleEventDescriptor appleEventWithEventClass:eventClass
eventID:eventID
#import <Cocoa/Cocoa.h>
// NSTextField has alignmentRectInsets = {.left=.right=3, .top=.bottom=0}, so
// when autolayout aligns NSTextField to its container's side margin (e.g. to x=0),
// the actual x position is -3, and the label gets clipped.
//
// ATUnclippedTextField compensates for that by overriding drawRect to extend
// the clipping rect by alignmentRectInsets.
//
@orta
orta / gist:8c7b274c98a77cb39b6371d062d64556
Last active November 1, 2016 21:02
dyld launch times
total time: 6.2 seconds (100.0%)
total images loaded: 347
total segments mapped: 1278, into 78370 pages with 7272 pages pre-fetched
total images loading time: 2.2 seconds (36.4%)
total dtrace DOF registration time: 0.29 milliseconds (0.0%)
total rebase fixups: 2,318,756
total rebase fixups time: 158.44 milliseconds (2.5%)
total binding fixups: 284,875
total binding fixups time: 113.78 milliseconds (1.8%)
total weak binding fixups time: 2.00 milliseconds (0.0%)
@steipete
steipete / openssl-build.sh
Last active August 16, 2017 12:31 — forked from felix-schwarz/openssl-build.sh
Updated script that builds OpenSSL for OS X, iOS and tvOS. Bitcode enabled for iOS, tvOS. Updated to build for tvOS, use the latest SDKs, skip installing man pages (to save time), download the OpenSSL source over HTTPS, patch OpenSSL for tvOS to not use fork(). Currently requires Xcode7.1GM or later (for the tvOS SDK).
#!/bin/bash
# This script downloads and builds the iOS, tvOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# https://gist.github.com/foozmeat/5154962
# Peter Steinberger, PSPDFKit GmbH, @steipete.
# Felix Schwarz, IOSPIRIT GmbH, @felix_schwarz.
@stopher
stopher / ByteRangeRequestsController.java
Last active December 7, 2017 16:40
Byte range requests in Play 2 Java Controllers. Eg. for serving MP4 video files to iPhone etc.
public class ByteRangeRequestsController extends Controller {
// 206 Partial content Byte range requests
private static Result stream(long start, long length, File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
fis.skip(start);
response().setContentType(MimeTypes.forExtension("mp4").get());
response().setHeader(CONTENT_LENGTH, ((length - start) +1l)+"");
response().setHeader(CONTENT_RANGE, String.format("bytes %d-%d/%d", start, length,file.length()));
@steipete
steipete / CallOncePerRunloopHelper.m
Last active February 2, 2018 07:32
To work around rdar://19810773, I need a helper that can filter multiple calls to the same method during the same runloop. This is my first attempt on it.
/// Performs `block` immediately and ignores subsequent calls during the same runloop.
#define pspdf_ensureCalledOnlyOncePerRunloop(block) do { \
static const char __onceKey; _pspdf_ensureCalledOnlyOncePerRunloop(self, &__onceKey, block); } while(0)
extern void _pspdf_ensureCalledOnlyOncePerRunloop(id self, const void *key, dispatch_block_t block);
void _pspdf_ensureCalledOnlyOncePerRunloop(id self, const void *key, dispatch_block_t block) {
NSCParameterAssert(block);
NSCParameterAssert(self);
PSPDFAssertOnMainThread(); // run loop needs the main thread.
@wkoszek
wkoszek / click.oscript
Created January 19, 2018 22:22
Clicking "Allow" button in System Preferences via Screen Sharing
# This is clicking "Allow" in System Preferences "Security & Privacy" screen
# when you're on Screen Sharing. Otherwise it doesn't work.
# To fix:
# - Put "Security & Privacy" window in the top left screen
# - open a Terminal on a side
# - save click.oscript
# - Run: osascript click.oscript
#
# The mouse click you send should hit "Allow" button. You may need to move the window a little bit.
# Script originally from: https://discussions.apple.com/thread/3708948
@catlan
catlan / Document.m
Last active August 7, 2019 21:31
Pages.app like moveToURL:completionHandler: impl. NSIsRelatedItemType key in Info.plist is required
- (void)moveToURL:(NSURL *)url completionHandler:(void (^ __nullable)(NSError * __nullable))completionHandler
{
NSError *error = nil;
NSURL *adjustedURL = nil;
if (![[url pathExtension] isEqualToString:@"testextension"]) {
adjustedURL = [url URLByAppendingPathExtension:@"testextension"];
}