Skip to content

Instantly share code, notes, and snippets.

@naotokui
naotokui / gist:f70eddddbcb7c96f6a07
Created August 21, 2014 01:34
check if a number is 2^N
if ((num & (num - 1)) == 0){
// num is 2^N
}
NSString *hexString = "01abcd";
UInt64 value = (UInt64)strtoull([hexString UTF8String], NULL, 16);
NSLog(@"value %ld", value);
@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];
}
@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:603aa18fee584232363a
Created October 11, 2015 04:53
time elapsed time in c++
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;