Skip to content

Instantly share code, notes, and snippets.

View jacksonfdam's full-sized avatar
💻
Coding...

Jackson F. de A. Mafra jacksonfdam

💻
Coding...
View GitHub Profile
# define ALog(format, ...) NSLog((@"%s [L%d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
# ifdef DEBUG
# define DLog(format, ...) ALog(format, ##__VA_ARGS__);
# else
# define DLog(...)
# endif
@jacksonfdam
jacksonfdam / createDocumentSubdir.m
Created May 28, 2012 17:20 — forked from slashingweapon/createDocumentSubdir.m
Useful Objective-C Snippets
// Create a path to a directory, and make sure it exists.
// The iOS documentation will tell you that URLs are preferred, but there is no createDirectory method for
// URLs. So we have to use string paths instead.
// Create a sub-directory in the application's Documents directory. Return the path on success, or nil on failure.
- (void)createDocumentSubdirectory:(NSString*)dirName {
NSString *retval = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dirPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:dirName];
NSFileManager *fm = [[NSFileManager alloc] init];
@jacksonfdam
jacksonfdam / autoscoped.h
Created May 28, 2012 17:21 — forked from mkhl/autoscoped.h
Objective-C macros
// GCC Attribute for autoscoped Obj-C objects
// Source: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/13/232287
#define autoscoped __attribute__((cleanup(releaseObject)))
static inline void releaseObject(id *object)
{
[*object release];
}
- (void)test
{
int foo = 1;
void (^block)() = ^() {
NSLog(@"%d at %p", foo, &foo); //=> 1 at 0xbfffd65c / エンクロージャの変数fooは参照できる.
// 以下は 'Variable is not assignable' コンパイルエラー
// foo = 2;
};
block();
NSLog(@"%d at %p", foo, &foo); //=> 1 at 0xbfffd6ac / block内のfooとはアドレスが違う.
@jacksonfdam
jacksonfdam / mobile-meta-links.html
Created May 28, 2012 17:23
iOS Web App Configuration
@jacksonfdam
jacksonfdam / hideaddrbar.js
Created May 28, 2012 17:23 — forked from scottjehl/hideaddrbar.js
Normalized hide address bar for iOS & Android
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
@jacksonfdam
jacksonfdam / SwipeView.h
Created July 2, 2012 05:21 — forked from siannopollo/SwipeView.h
A UIVIew class to detect swipes, and forward the message on to a delegate which can react to the swipe
#import <UIKit/UIKit.h>
@protocol SwipeViewDelegate;
@interface SwipeView : UIView {
id <SwipeViewDelegate> swipeDelegate;
int touchBeganX, touchBeganY;
int touchMovedX, touchMovedY;
}
@jacksonfdam
jacksonfdam / gist:3099676
Created July 12, 2012 17:58
Sublime Text2 - PHP Getter and Setter Snippet
<snippet>
<content><![CDATA[public function get${1/(.*)/\u$1/}()
{
return \$this->${1:$SELECTION};
}
public function set${1/(.*)/\u$1/}(\$$1)
{
\$this->$1 = \$$1;
return \$this;