Aggressively removing DS_Store files in git repos

DS_Store files in git repositories is a minor problem for a lot of people. Global .gitignore files are a great solution to not commiting DS_Store files but it won’t actively remove them from your project directories. This is my shortcut for git status: function s() { find . -name '*.DS_Store' -type f -delete #find and delete DS_Store files git status -s -b #s - simple output, b - include branch name }

September 18, 2013 · 1 min · Paul

Animal Match Games for iOS

I built a simple iOS match game for my kids that addresses a few common shortcomings of existing kids apps and then themed it when they wanted more animals. Differences that I felt were important: There’s nothing to distract from the gameplay. I don’t do promotions, ads, in app purchases or even more inocuous things like a start button or settings page. If the app is open, it’s ready to play. No sounds. My kids love to play with the vibration toggle on my phone and being able to give them something to play with that definitely won’t make noise has been very helpful at times. All 3 are universal apps so it’s not necessary to buy it again on the iPad. The Apps Animal Match View in App Store ...

September 9, 2013 · 1 min · Paul

Disabling the save shortcut for browsers

The save hotkey in Chrome needs to be changed for all the same reasons I disabled the Print hotkey. I hit it by accident a few times a week thinking some other application is active and then I have to wait for it to load to get out of it. It’s only a few seconds but it’s an easily fixed annoyance. The Fix Changing the Save hotkey for Chrome is pretty simple and it’ll work similarly for other browsers. Open System Preferences > Keyboard > Keyboard Shortcuts > Application Shortcuts. Add custom shortcuts for: ...

August 26, 2013 · 1 min · Paul

Sharing a single NSDateFormatter instance

Formatting dates in cellForRowAtIndexPath or another method that gets called very often will make an app noticeably slower if an NSDateFormatter needs to be initialized on every call. Storing the NSDateFormatter in a property or making it static are both fine options but if it’s around anyway it might as well be used by the rest of the app. NSDateFormatter Instance Category //NSDateFormatter Category + (NSDateFormatter *)instance { static dispatch_once_t onceMark; static NSDateFormatter *formatter = nil; dispatch_once(&onceMark, ^{ formatter = [[NSDateFormatter alloc] init]; }); return formatter; } //Usage NSDateFormatter *dateformatter = [NSDateFormatter instance]; Drawbacks If there are multiple date formats in use the date format needs to be set before each use. Not a major drawback but it can get annoying. ...

August 15, 2013 · 1 min · Paul

Retina alterative to CGRectIntegral

CGRectIntegral is a function for rounding all the values of a CGRect at once, typically used for snapping frames to pixels. For a good example of how this helps prevent image blurring and other related rendering issues see this stackoverflow answer. On retina screens CGRectIntegral still rounds to the nearest point (1.0) rather than the nearest pixel (0.5) which isn’t ideal. My solution to this is implemented as a UIView category which matches my use case for CGRectIntegral 100% of the time. Your mileage may vary. ...

August 14, 2013 · 1 min · Paul

Mac constantly switching to a new finder window when the space key is pressed

If whenever you press the space key your mac shifts focus to a finder window you should be able to fix it by hard booting Finder. Open terminal and run: killall Finder

August 13, 2013 · 1 min · Paul

Unarchiving 7z files on OS X

Brew is always saving the day. # Install p7zip brew install p7zip # extract 7z x file.7z

August 12, 2013 · 1 min · Paul

Quick Browser Detection One Liners

// You can expand this out in any line below // but it makes things much more readable var ua = navigator.userAgent.toString().toLowerCase(); //Browsers var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/ var IE7 = (document.all && !window.opera && window.XMLHttpRequest && ua.indexOf('trident/4.0') == -1) ? true : false; var IE8 = (ua.indexOf('trident/4.0') != -1); var IE9 = ua.indexOf("trident/5")>-1; var IE10 = ua.indexOf("trident/6")>-1; var SAFARI = (ua.indexOf("safari") != -1) && (ua.indexOf("chrome") == -1); var FIREFOX = (ua.indexOf("firefox") != -1); var CHROME = (ua.indexOf("chrome") != -1); //Platforms var MAC = (ua.indexOf("mac")!=-1) ? true: false; var WINDOWS = (navigator.appVersion.indexOf("Win")!=-1) ? true : false; var LINUX = (navigator.appVersion.indexOf("Linux")!=-1) ? true : false; var UNIX = (navigator.appVersion.indexOf("X11")!=-1) ? true : false; var IOS = ((ua.indexOf("iphone")!=-1) || (ua.indexOf("ipod")!=-1) || (ua.indexOf("ipad")!=-1)) ? true : false; var ANDROID = ua.indexOf("android")!=-1) ? true: false; var BLACKBERRY = (ua.indexOf("blackberry")!=-1) ? true: false; //mobile browsers var OPERA_MINI = (ua.indexOf("opera mini")!=-1) ? true: false;

August 9, 2013 · 1 min · Paul

Vertical space in bootstrap

I use Bootstrap for most personal projects lately but one thing that consistently gets me is the lack of vertical spacing classes. Quick fix I added these classes to my bootstrap stylesheet .voffset { margin-top: 2px; } .voffset1 { margin-top: 5px; } .voffset2 { margin-top: 10px; } .voffset3 { margin-top: 15px; } .voffset4 { margin-top: 30px; } .voffset5 { margin-top: 40px; } .voffset6 { margin-top: 60px; } .voffset7 { margin-top: 80px; } .voffset8 { margin-top: 100px; } .voffset9 { margin-top: 150px; } Example Vertically offset text

August 8, 2013 · 1 min · Paul

Checking if a UITableViewCell is fully visible

Sometime you need to know if a UITableViewCell is completely visible and for those times there’s this handy UITableViewCell category. //Place in UITableViewCell Category - (BOOL) isCompletelyVisible { // For parents category see pdenya.com/g/uiview_parents UITableView *tableview = (UITableView *)[self parents:[UITableView class]]; CGRect rect = [tableview rectForRowAtIndexPath:[tableview indexPathForCell:self]]; rect = [tableview convertRect:rect toView:tableview.superview]; BOOL completelyVisible = CGRectContainsRect(tableview.frame, rect); return completelyVisible; } I’d like to mention that you can skip this check entirely if your goal is to make sure a cell is completely visible. With UITableViewScrollPositionNone scrollToRowAtIndexPath:atScrollPosition:animated: doesn’t scroll at all if the cell is totally visible and in other cases it scrolls as little as possible which is usually the ideal behavior. ...

August 7, 2013 · 1 min · Paul