Skip to content

Instantly share code, notes, and snippets.

@tapi
tapi / KVO.js
Created February 24, 2012 01:36
Quick and dirty Javascript KVO
/* Extends the Class Object Written by Resig. http://ejohn.org/blog/simple-javascript-inheritance/ */
Class.prototype.addObserver = function(/** String */ key, /** Object */ observer, /** Function */ method)
{
if (key !== null && key !== undefined &&
observer !== null && observer !== undefined &&
method !== null && method !== undefined)
{
eval("this._" + key + " = this." + key);
this.__defineGetter__(key, function()
@tapi
tapi / NSObject+SMDictionaryMapper.h
Created April 25, 2012 11:37
Dictionary <--> Object Mapper for Objective-C
//
// NSObject+SMDictionaryMapping.h
// SoundTrack
//
// Created by Paddy O'Brien on 12-04-24.
// Copyright (c) 2012 Paddy O'Brien. All rights reserved.
//
#import <Foundation/Foundation.h>
@tapi
tapi / .gitignore
Last active December 15, 2015 20:49 — forked from adamgit/.gitignore
Adds the AppCode .idea folder
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@tapi
tapi / genModels.sh
Created July 31, 2013 22:04
An Xcode build phase script to automatically run mogenerator on your xcdatamodel if it has changed
# Xcode sets up its own PATH variable so we want to ensure that it includes /usr/local/bin
PATH=$PATH:/usr/local/bin
# Check that mogenerator is available
command -v mogenerator >/dev/null 2>&1 || { echo >&2 "You need mogenerator but it's not installed. To install using homebrew use 'brew install mogenerator'. Aborting."; exit 1; }
# Change the working dir to where our models are
cd "${SRCROOT}"/Models
# Only run mogenerator if the access time for ResultsCache.xcdatamodeld is newer than our lock file
@tapi
tapi / genModels.sh
Created July 31, 2013 22:05
An Xcode build phase script to automatically run mogenerator on your xcdatamodel if it has changed
# Xcode sets up its own PATH variable so we want to ensure that it includes /usr/local/bin
PATH=$PATH:/usr/local/bin
# Check that mogenerator is available
command -v mogenerator >/dev/null 2>&1 || { echo >&2 "You need mogenerator but it's not installed. To install using homebrew use 'brew install mogenerator'. Aborting."; exit 1; }
# Change the working dir to where our models are
cd "${SRCROOT}"/Models
# Only run mogenerator if the access time for ResultsCache.xcdatamodeld is newer than our lock file
@tapi
tapi / pageViewGestures.m
Created August 14, 2013 15:07
A little had to get at the gesture recognizers of a UIPageviewControllers paging view
- (void)didMoveToParentViewController:(UIViewController *)parent
{
[super didMoveToParentViewController:parent];
if ([parent isKindOfClass:[UIPageViewController class]]) {
UIScrollView *scrollView;
for (UIView *view in parent.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)view;
}
@tapi
tapi / gist:9236422
Created February 26, 2014 19:17
This is the funkiest assignment syntax I have ever seen used in Objective-C
_imageView = ({
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.scrollView addSubview:imageView];
imageView;
});
### Keybase proof
I hereby claim:
* I am tapi on github.
* I am tapi (https://keybase.io/tapi) on keybase.
* I have a public key whose fingerprint is B8A2 FE8D A75F 3FD8 9114 77D5 E7E6 6A04 5D6C 1382
To claim this, I am signing this object:
@tapi
tapi / BookExample.swift
Created June 4, 2014 05:41
Generic types broken into separate lines
func anyCommonElements <T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> (lhs: T, rhs: U) -> Bool {
for lhsItem in lhs {
for rhsItem in rhs {
if lhsItem == rhsItem {
return true
}
}
}
return false
}
@tapi
tapi / GroupBy.swift
Created February 6, 2015 14:24
A generic groupby function that should work similarily to ruby's
/**
Group all items in a collection according to the value returned by a block.
:param: collection The collection whose items you want to group.
:param: groupBlock A block that returns a key for that value to be grouped by.
:returns: Returns a dictionary whose keys are the values returned by the groupBlock.
*/
func groupBy<V, K : protocol<Hashable, Equatable>, C : _ExtensibleCollectionType where C.Generator.Element == V>(collection: C, groupBlock: (V) -> K) -> [K: [V]] {
typealias ValueGroup = [V]