Skip to content

Instantly share code, notes, and snippets.

View Kirow's full-sized avatar

Kirill Serebriakov Kirow

View GitHub Profile
@leovandriel
leovandriel / gist:3923434
Last active October 12, 2015 13:19
An iOS view controller for trying out different UIImage preloading strategies
// ImagePreloadingViewController - An iOS view controller for trying out different
// UIImage preloading strategies. Results for 1 MB png on iPhone 4S:
// - No preload: drawing the image right away (80 ms)
// - Header preload: getting the width (10 ms) and then drawing (100 ms)
// - Data preload: getting the data (110 ms) and then drawing (75 ms)
// - Draw preload: drawing it once (100 ms) and then again (20 ms)
// In short: preload a UIImage by drawing it.
// License: BSD
// Author: Leonard van Driel, 2012
@clowwindy
clowwindy / Makefile
Last active January 4, 2016 03:18
stringByAddingPercentEncodingWithAllowedCharacters Crash
test: main.m
gcc -o main main.m -framework Foundation
@sfider
sfider / LOOProfiling.h
Created July 8, 2012 18:16
Objective-C macro for measuring execution time of block of code.
//
// LOOProfiling.h
//
// Created by Marcin Swiderski on 4/12/12.
// Copyright (c) 2012 Marcin Swiderski. All rights reserved.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
@braking
braking / KeyboardNotification.m
Last active November 14, 2018 18:46
Adjust content insets of a tableview when keyboard opens.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
@jessearmand
jessearmand / mpParse.m
Created November 23, 2010 13:59
A command line tool to parse .mobileprovision file
//
// © 2008 Eugene Solodovnykov
// http://idevblog.info/mobileprovision-files-structure-and-reading/
//
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
@beccadax
beccadax / FDRCollectionViewCell.h
Created July 14, 2013 03:26
Collection view cells and headings which, together, give a nice grid with light gray borders between each element.
//
// FDRCollectionViewCell.h
//
//
// Created by Brent Royal-Gordon on 7/10/13.
//
//
#import <UIKit/UIKit.h>
import UIKit
import PlaygroundSupport
func degree2radian(a:CGFloat)->CGFloat {
let b = CGFloat(Double.pi) * a/180
return b
}
func polygonPointArray(sides:Int,x:CGFloat,y:CGFloat,radius:CGFloat,adjustment:CGFloat=0)->[CGPoint] {
let angle = degree2radian(a: 360/CGFloat(sides))
import UIKit
/// High precedence
precedencegroup HighPrecedence { higherThan: BitwiseShiftPrecedence }
/// Exponentiation operator
infix operator **: HighPrecedence
extension CGFloat {
/// Returns base ^^ exp
@lanephillips
lanephillips / CGRectAspectFit.m
Created October 7, 2013 21:05
Objective-C code to fit a CGRect inside or outside another CGRect while maintaining aspect ratio. The fitted rectangle is centered on the target rectangle.
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget)
{
// first try to match width
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit);
// if we scale the height to make the widths equal, does it still fit?
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) {
return s;
}
// no, match height instead
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit);
@raphaelschaad
raphaelschaad / RSTimingFunction.h
Last active March 21, 2023 08:40
All the cool animation curves from `CAMediaTimingFunction` but not limited to use with CoreAnimation. See what you can do with cubic Bezier curves here: http://netcetera.org/camtf-playground.html To get started just "Download Gist", throw the .h and .m files into your Xcode project and you're good to go!
//
// RSTimingFunction.h
//
// Created by Raphael Schaad on 2013-09-28.
// This is free and unencumbered software released into the public domain.
//
#import <UIKit/UIKit.h>