Skip to content

Instantly share code, notes, and snippets.

View eternalstorms's full-sized avatar
Yoink, ScreenFloat, Transloader, Glimpses, flickery, SiriMote

Matthias Gansrigler eternalstorms

Yoink, ScreenFloat, Transloader, Glimpses, flickery, SiriMote
View GitHub Profile
@eternalstorms
eternalstorms / PrettyDate.m
Created August 29, 2012 14:25
return a well-formatted string from an NSDate, presentable to the user
- (NSString *)stringForDate:(NSDate *)date
withLocale:(NSLocale *)locale
timeZone:(NSTimeZone *)timeZone
dateFormat:(NSString *)dateFormat
dateStyle:(NSDateFormatterStyle)style
{
if (dateFormat == nil)
dateFormat = @"yyyy-MM-dd HH:mm:ss Z";
if (locale == nil)
locale = [NSLocale currentLocale];
@eternalstorms
eternalstorms / Mac App Store Promo Code Link.txt
Created September 4, 2012 16:25
Mac App Store Links (Refund, Promo Code Redemption)
@eternalstorms
eternalstorms / DateString.m
Created September 5, 2012 10:50
String from an NSDate in the form of "2 months ago"
- (NSString *)relativeDateStringFromDate:(NSDate *)date
{
NSDate *now = [NSDate date];
if ([now laterDate:date] == date)
return nil; //dates in the future are not supported
NSInteger years = [now yearsSinceDate:date];
NSInteger months = [now monthsSinceDate:date];
NSInteger weeks = [now weeksSinceDate:date];
NSInteger days = [now daysSinceDate:date];
NSInteger hours = [now hoursSinceDate:date];
@eternalstorms
eternalstorms / activity monitor memory usage stackoverflow.txt
Created September 10, 2012 16:34
Activity Monitor memory usage is inaccurate
Monitoring your memory usage with Activity Monitor is pretty unreliable. First, which memory field are you watching (Virtual Private Memory, Real Private Memory, Real Shared Memory, or Real Memory)?
Second, when your code makes an allocation request, that typically goes, directly or indirectly, to the malloc routines. The malloc routines try to satisfy your request from the memory that it already has. If it can't then it requests more from the system. When you free memory, it goes back to malloc. Malloc does not necessarily return it to the system. It may keep it to more quickly satisfy future requests. So, you may not see your process's memory usage go down, at least not all the way, even if your program is releasing everything it allocated.
The proper way to check that your program is managing memory correctly is to use Instruments with the Leaks and Allocations tools.
(source: http://stackoverflow.com/questions/10218314/cocoa-memory-issue-memory-doesnt-get-reclaimed-when-objects-are-removed-from-a )
@eternalstorms
eternalstorms / iCloud.txt
Created September 20, 2012 09:52
iCloud file sync step by step
1) Turn on iCloud in your entitlements. In Xcode, you can find 'em in your target, under the Summary tab, at the bottom. Turn on 'Enable Entitlements' and press + on the iCloud Containers list.
2) You get a folder. Stuff in it gets synchronized around. This is the easy part. You can use the -[NSFileManager URLForUbiquityContainerIdentifier:] call to find out where the container is.
Extra notes: The identifier is whatever name Xcode added to the list in step 1. Make sure you call this at least once, because calling this turns on all the iCloud stuff in Foundation. If iCloud is turned off, this will return nil.
3) This folder is organized like a home folder. Yep, this means this one can have a Documents folder, a Library, whatever. You have to create those folders if you want to use them.
4) Looking at the folder directly is not useful. (Some of the files may not have sync'd yet, so they're not yet in the folder.) Use NSMetadataQuery. This will give you all files, including those not downloaded yet.
To searc
@eternalstorms
eternalstorms / Example.m
Created September 24, 2012 11:35
Pass a block as a void pointer in ARC
- (void)delete
{
void (^myBlock)() = ^{/*some block action*/};
NSBeginCriticalAlertSheet(NSLocalizedString(@"ReallyDeleteWarning", nil),
NSLocalizedString(@"Delete", nil),
NSLocalizedString(@"Cancel", nil), nil, self.window, self, nil,
@selector(deleteAlertWindow:didDismissWithCode:context:),
(__bridge_retained void *)([myBlock copy]),
NSLocalizedString(@"ReallyDeleteWarningMsg", nil));
@eternalstorms
eternalstorms / links.txt
Created October 20, 2012 16:39
Mac/iOS App Store Links and Direct Download Links for Demos
@eternalstorms
eternalstorms / gist:3995963
Created November 1, 2012 19:42
URLs for sending users to rate your App on the (Mac/iOS) App Store
Mac App Store:
macappstore://itunes.apple.com/app/idMACAPPSTOREAPPID
iOS App Store:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=IOSAPPSTOREAPPID
@eternalstorms
eternalstorms / gist:4098116
Created November 17, 2012 17:47
Hide the Full Screen button of an NSWindow that is OS X Lion+ full screen capable
- (void)hideFullscreenButtonOfWindow:(NSWindow *)aWindow
{
NSButton *fsButton = [aWindow standardWindowButton:NSWindowFullScreenButton];
[fsButton setHidden:YES];
fsButton.alphaValue = 0.0;
[fsButton setEnabled:NO];
fsButton.image = nil;
fsButton.alternateImage = nil;
}
@eternalstorms
eternalstorms / NSSharingServicePicker+ESSSharingServicePickerMenu.h
Created November 22, 2012 18:50
A category on NSSharingServicePicker to create a menu that can be used as a sharing submenu or main menu
//
// NSSharingServicePicker+ESSSharingServicePickerMenu.h
//
// Created by Matthias Gansrigler on 22.11.12.
// Copyright (c) 2012 Eternal Storms Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSSharingServicePicker (ESSSharingServicePickerMenu)