Skip to content

Instantly share code, notes, and snippets.

@naotokui
naotokui / gist:1300719
Created October 20, 2011 08:53
UUID String
+ (NSString *) uniqueId
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *identifier =(NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return [identifier autorelease];
}
CMItemCount numSamplesInBuffer = CMSampleBufferGetNumSamples(buffer);
AudioBufferList audioBufferList;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
buffer,
NULL,
&audioBufferList,
sizeof(audioBufferList),
NULL,
@naotokui
naotokui / gist:1378493
Created November 19, 2011 05:39
Check if Retina Display is available or not
// Check if Retina Display is available or not
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00){
hasRetina = YES;
}
@naotokui
naotokui / gist:1397437
Created November 27, 2011 11:19
Get text contents of UIWebView
NSString *contents = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerText"];
@naotokui
naotokui / gist:1581112
Created January 9, 2012 04:28
Debug NSAutoreleasePool
[NSAutoreleasePool showPools]
/* Definition */
extern void _objc_autoreleasePoolPrint();
_objc_autoreleasePoolPrint();
@naotokui
naotokui / gist:1709648
Created January 31, 2012 09:42
- (UIView *)findFirstResponder
- (UIView *) findFirstResonder:(UIView*)root
{
if ([root isFirstResponder]) {
return root;
}
for (UIView *subView in root.subviews) {
UIView *firstResponder = [self findFirstResonder:subView];
if (firstResponder != nil) {
return firstResponder;
@naotokui
naotokui / gist:1756346
Created February 7, 2012 01:08
- (void) presentModalViewControllerInSizeYouWant (for iPad)
- (void) presentModalViewControllerInSizeYouWant
{
float width = <width you wnat>;
float height = <height you wnat>;
UIViewController *viewCtl = [[UIViewController alloc] initWithNibName: @"UIViewController" bundle: nil];
viewCtl.modalPresentationStyle = UIModalPresentationFormSheet; // set presentation style
[self presentModalViewController:viewCtl animated: YES]; // show!
@naotokui
naotokui / gist:1768018
Created February 8, 2012 10:34
UIView with rounded corners
#import <QuartzCore/QuartzCore.h>
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 3.0;
@naotokui
naotokui / gist:3985027
Created October 31, 2012 05:36
Detect Network Type on iOS ... from the status bar
// http://stackoverflow.com/questions/8400340/determining-3g-vs-edge
- (NSNumber *) dataNetworkTypeFromStatusBar {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSNumber *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
@naotokui
naotokui / gist:4063901
Created November 13, 2012 04:18
UIView RoundedCorner Category
#import <QuartzCore/QuartzCore.h>
@implementation UIView (UIView_RoundCorner)
- (void) setCornersRoundedWithRadius: (float) cornerRadius
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(cornerRadius, cornerRadius)];