Skip to content

Instantly share code, notes, and snippets.

View ricardopereira's full-sized avatar
🏠
Working from home

Ricardo Pereira ricardopereira

🏠
Working from home
View GitHub Profile
@ricardopereira
ricardopereira / SwiftGen-script
Last active August 7, 2016 02:10
Generate Localisable strings
swiftgen strings ${SRCROOT}/<APP>/Base.lproj/Localizable.strings --output ${SRCROOT}/<APP>/LocalizableStrings.swift
@ricardopereira
ricardopereira / pre-commit.sh
Last active January 16, 2017 11:30
iOS pre-commit sample
#!/usr/bin/env bash
set -eu
if git diff-index -p -M --cached HEAD -- '*.xib' '*.storyboard' | grep '^+' | egrep 'misplaced="YES"' >/dev/null 2>&1
then
echo "COMMIT REJECTED because it contains misplaced views; please correct them before committing."
exit 1
fi
if git diff-index -p -M --cached HEAD -- '*.swift' | grep '^+' | egrep 'TEST' >/dev/null 2>&1
@ricardopereira
ricardopereira / xcode-git-bootstrap
Created August 7, 2016 01:50
"Bootstrap script that will allow you to have git hook inside your repository and make it easy for the whole team to be in sync." http://merowing.info/2016/08/setting-up-pre-commit-hook-for-ios/
#!/usr/bin/env bash
# Usage: scripts/bootstrap
set -eu
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR/.."
@ricardopereira
ricardopereira / Objc-Blocks-cheatsheet.m
Last active December 30, 2016 09:11 — forked from twobitlabs/gist:4226365
Blocks cheat sheet
// http://cocoawithlove.com/2009/10/ugly-side-of-blocks-explicit.html has a nice breakdown of the syntax--it helps to think of the ^ as similar to a pointer dereference symbol *
// block typedef:
typedef void(^Block)();
typedef void(^ConditionalBlock)(BOOL);
typedef NSString*(^BlockThatReturnsString)();
typedef NSString*(^ConditionalBlockThatReturnsString)(BOOL);
// block property with typedef:
@ricardopereira
ricardopereira / SpinlockTestTests.swift
Created October 4, 2016 10:20 — forked from steipete/SpinlockTestTests.swift
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
Test Suite 'All tests' started at 2016-11-23 13:16:03.092
Test Suite 'Quick.framework' started at 2016-11-23 13:16:03.093
Test Suite 'Quick.framework' passed at 2016-11-23 13:16:03.093.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
Test Suite 'AblySpec.xctest' started at 2016-11-23 13:16:03.094
Test Suite 'RealtimeClientConnection' started at 2016-11-23 13:16:03.095
Test Case '-[AblySpec.RealtimeClientConnection Connection__connection_failures_once_CONNECTED__System_s_response_to_a_resume_request__should_resume_the_connection_after_an_auth_renewal_and_detach_all_channels_if_the_connectionId_changes]' started.
2016-11-23 13:16:04.097 xctest[32837:4092858] DEBUG: (ARTRest.m:57) RS:0x7f955c623000 0x7f955c617b50 alloc HTTP
2016-11-23 13:16:04.098 xctest[32837:4092858] DEBUG: (ARTAuth.m:78) RS:0x7f955c623000 validating ARTClientOptions: key=_tmp_U7qorQ.Jl-lRg:3XINc2IggVonxFd9 token=_tmp_U7qorQ.DpFF_XDx2ZDmtlrAdFrPgOvnn-9k3W10UiJam2XZytbRKSVDhdCs4YT5EnNkEZz0pykArPnjAfXf0EYxG51dv8SxY7fg
@ricardopereira
ricardopereira / NSURLSession-invalidate.swift
Created December 7, 2016 17:07
The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you do not invalidate the session, your app leaks memory until it exits.
import UIKit
class ModalViewController: UIViewController, NSURLSessionDelegate {
var session: NSURLSession!
override func viewDidLoad() {
super.viewDidLoad()
session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(), delegate: self, delegateQueue: nil)
@ricardopereira
ricardopereira / Animated-rootViewController-transition.m
Last active December 30, 2016 09:04 — forked from gimenete/gist:53704124583b5df3b407
Animated rootViewController transition
// put this in your AppDelegate
- (void)changeRootViewController:(UIViewController*)viewController {
if (!self.window.rootViewController) {
self.window.rootViewController = viewController;
return;
}
UIView *snapShot = [self.window snapshotViewAfterScreenUpdates:YES];
[viewController.view addSubview:snapShot];
self.window.rootViewController = viewController;
@interface MyStringProxy : NSProxy
@property (nonatomic) NSString *target;
@end
@implementation MyStringProxy
- (BOOL)respondsToSelector:(SEL)aSelector {
class ViewController: UIViewController {
var image: UIImage!
var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let avatarData = NSData(contentsOfURL: NSURL(string: "https://www.gravatar.com/avatar/7d7c8bd1f797a0e9b474e52c3968cbde?s=48&d=identicon&r=PG")!)
let landscapeData = NSData(contentsOfURL: NSURL(string: "https://upload.wikimedia.org/wikipedia/commons/e/e4/Stourhead_garden.jpg")!)