Skip to content

Instantly share code, notes, and snippets.

View natanrolnik's full-sized avatar

Natan Rolnik natanrolnik

View GitHub Profile
@kylestew
kylestew / NSObject+PWObject.c
Created February 24, 2012 00:17
Category - Perform Block After Delay
#import "NSObject+PWObject.h"
@implementation NSObject (PWObject)
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay {
int64_t delta = (int64_t)(1.0e9 * delay);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block);
}
@end
@mayoff
mayoff / drawArc.m
Created April 7, 2013 22:07
Use Core Graphics to draw an arc with a gradient fill, a stroked outline, and a shadow. http://stackoverflow.com/questions/15866179/draw-segments-from-a-circle-or-donut
static UIImage *imageWithSize(CGSize size) {
static CGFloat const kThickness = 20;
static CGFloat const kLineWidth = 1;
static CGFloat const kShadowWidth = 8;
UIGraphicsBeginImageContextWithOptions(size, NO, 0); {
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextAddArc(gc, size.width / 2, size.height / 2,
(size.width - kThickness - kLineWidth) / 2,
-M_PI / 4, -3 * M_PI / 4, YES);
@bomberstudios
bomberstudios / sketch-plugins.md
Last active February 26, 2024 07:02
A list of Sketch plugins hosted at GitHub, in no particular order.
@raven
raven / Breakpoints_v2.xcbkptlist
Last active August 30, 2019 00:53
Symbolic breakpoint for dynamically linking libReveal against UIApplicationMain
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "2"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5]
func partition(v: Int[], left: Int, right: Int) -> Int {
var i = left
for j in (left + 1)..(right + 1) {
if v[j] < v[left] {
i += 1
(v[i], v[j]) = (v[j], v[i])
}
}
@nicklockwood
nicklockwood / Hacking UIView Animation Blocks.md
Last active January 12, 2024 06:15
This article was originally written for objc.io issue 12, but didn't make the cut. It was intended to be read in the context of the other articles, so if you aren't familiar with concepts such as CALayer property animations and the role of actionForKey:, read the articles in that issue first.

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

@irace
irace / gist:927f843cb0f683a7f2c2
Created August 13, 2014 20:03
New iOS 8 APIs don't allow you to use a custom presentation controller for compact devices, in conjunction with a popover on "normal" size class devices
//
// ViewController.m
// PopoverPresentationControllerExample
//
// Created by Bryan Irace on 8/8/14.
// Copyright (c) 2014 Bryan Irace. All rights reserved.
//
#import "CustomCompactPresentationController.h"
#import "ViewController.h"
@jpsim
jpsim / MyTableViewController.m
Created August 19, 2014 22:57
Grouped UITableView using Realm
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2014 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
@alvesjtiago
alvesjtiago / gist:e2c61eb288c9d488a8cc
Last active August 29, 2015 14:18
Remove alpha channel and transparencies from images for AppStore screenshots.
# Run the following code on a folder that contains all your images
for f in *.png; do convert "$f" -background white -alpha remove -flatten -alpha off "$f"; done
//
// SimpleScrollingStack.swift
// A super-simple demo of a scrolling UIStackView in iOS 9
//
// Created by Paul Hudson on 10/06/2015.
// Learn Swift at www.hackingwithswift.com
// @twostraws
//
import UIKit