Skip to content

Instantly share code, notes, and snippets.

// Similar to defer in Swift
#define pspdf_defer_block_name_with_prefix(prefix, suffix) prefix ## suffix
#define pspdf_defer_block_name(suffix) pspdf_defer_block_name_with_prefix(pspdf_defer_, suffix)
#define pspdf_defer __strong void(^pspdf_defer_block_name(__LINE__))(void) __attribute__((cleanup(pspdf_defer_cleanup_block), unused)) = ^
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
static void pspdf_defer_cleanup_block(__strong void(^*block)(void)) {
(*block)();
}
#pragma clang diagnostic pop
@ricardopereira
ricardopereira / AsyncBlockOperation.swift
Last active May 24, 2017 16:50 — forked from tomkowz/AsyncBlockOperation.swift
Asynchronous NSBlockOperation
import Foundation
class AsyncBlockOperation: NSOperation {
typealias Block = (completion: () -> Void) -> Void
private lazy var executingAccessQueue = dispatch_queue_create("eu.ricardopereira.AsyncBlockOperation.executing", DISPATCH_QUEUE_CONCURRENT)
private var _executing = false
private lazy var finishedAccessQueue = dispatch_queue_create("eu.ricardopereira.AsyncBlockOperation.finished", DISPATCH_QUEUE_CONCURRENT)
private var _finished = false
@ricardopereira
ricardopereira / iOS-EN-Localizable.strings
Created April 20, 2017 16:11
iOS en.lproj/Localizable.strings
/* Login button text */
"login-button" = "Log in";
/* Logout button text */
"logout-button" = "Log out";
/* Back button text */
"back-button" = "Back";
/* No data label */
//
// FloatingPoint+Scale.swift
// Swiftilities
//
// Created by Zev Eisenberg on 4/15/16.
// Copyright © 2016 Raizlabs. All rights reserved.
//
public extension FloatingPoint {
/// Re-maps a number from one range to another.
//
// SquishButton
// Released under the MIT license.
// http://github.com/BalestraPatrick/SquishButton
//
// Created by Patrick Balestra on 04/08/2017.
// Copyright (c) 2017 Patrick Balestra. All rights reserved.
//
import UIKit
extension UIButton {
// This method sets an image and title for a UIButton and
// repositions the titlePosition with respect to the button image.
// Add additionalSpacing between the button image & title as required
// For titlePosition, the function only respects UIViewContentModeTop, UIViewContentModeBottom, UIViewContentModeLeft and UIViewContentModeRight
// All other titlePositions are ignored
@objc func set(image anImage: UIImage?, title: NSString!, titlePosition: UIViewContentMode, additionalSpacing: CGFloat, state: UIControlState){
self.imageView?.contentMode = .Center
#import "NSMutableArray+QueueAdditions.h"
@implementation NSMutableArray (QueueAdditions)
// Add to the tail of the queue
- (void)enqueue:(id)object {
[self addObject:object];
}
// Grab the next item in the queue, if there is one
@ricardopereira
ricardopereira / .vimrc
Last active February 21, 2017 16:07 — forked from bendc/.vimrc
Vim config (`vim +PluginInstall +qall`)
set nocompatible
set encoding=utf-8 nobomb
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Vundle
Plugin 'VundleVim/Vundle.vim'
class NotificationToken {
let token: NSObjectProtocol
let center: NSNotificationCenter
init(token: NSObjectProtocol, center: NSNotificationCenter) {
self.token = token
self.center = center
}
@ricardopereira
ricardopereira / UITableView_tableHeaderView+AutoLayout.m
Last active February 17, 2017 08:59
Variable-height UITableView tableHeaderView with autolayout
// in a UITableViewController (or any other view controller with a UITableView)
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 0)];
header.translatesAutoresizingMaskIntoConstraints = NO;
// [add subviews and their constraints to header]
NSLayoutConstraint *headerWidthConstraint = [NSLayoutConstraint