Skip to content

Instantly share code, notes, and snippets.

View gist:f70eddddbcb7c96f6a07
if ((num & (num - 1)) == 0){
// num is 2^N
}
View hex string to integer
NSString *hexString = "01abcd";
UInt64 value = (UInt64)strtoull([hexString UTF8String], NULL, 16);
NSLog(@"value %ld", value);
View gist:1300719
+ (NSString *) uniqueId
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *identifier =(NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return [identifier autorelease];
}
@naotokui
naotokui / gist:1378493
Created Nov 19, 2011
Check if Retina Display is available or not
View gist:1378493
// 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 Nov 27, 2011
Get text contents of UIWebView
View gist:1397437
NSString *contents = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerText"];
@naotokui
naotokui / gist:1581112
Created Jan 9, 2012
Debug NSAutoreleasePool
View gist:1581112
[NSAutoreleasePool showPools]
/* Definition */
extern void _objc_autoreleasePoolPrint();
_objc_autoreleasePoolPrint();
@naotokui
naotokui / gist:1709648
Created Jan 31, 2012
- (UIView *)findFirstResponder
View gist:1709648
- (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 Feb 7, 2012
- (void) presentModalViewControllerInSizeYouWant (for iPad)
View gist:1756346
- (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 Feb 8, 2012
UIView with rounded corners
View gist:1768018
#import <QuartzCore/QuartzCore.h>
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 3.0;
View gist:603aa18fee584232363a
auto start = std::chrono::steady_clock::now();
// some task
auto end = std::chrono::steady_clock::now();
std::cout << "Elapsed time " << double((end-start).count())/double(std::chrono::steady_clock::period::den) << "s" << std::endl;