Skip to content

Instantly share code, notes, and snippets.

@DenTelezhkin
DenTelezhkin / main.m
Last active December 26, 2015 23:19
Running XCTests without creating any of application controllers.
static bool isRunningTests()
{
NSDictionary* environment = [[NSProcessInfo processInfo] environment];
NSString* injectBundle = environment[@"XCInjectBundle"];
return [[injectBundle pathExtension] isEqualToString:@"xctest"];
}
int main(int argc, char *argv[])
{
@autoreleasepool
@DenTelezhkin
DenTelezhkin / README.md
Last active July 11, 2016 09:19
CI Rakefile for iOS applications.Prerequisites: xcpretty, shenzhen, cocoapods, testflight, XCTest.Put this Rakefile into directory with your .xcodeproj and run rake. Remove build tasks you don't need in your setup.

Usage

Install dependencies and run tests

rake 

Dependencies, tests, archive in Release configuration and upload to TestFlight

rake testflight 
@DenTelezhkin
DenTelezhkin / NetworkingTest.m
Created March 25, 2014 15:59
Testing networking with OHHTTPStubs and Expecta
@interface BitcoinLoaderSpecs : XCTestCase
@property (nonatomic, strong) RateModel * rate;
@end
@implementation BitcoinLoaderSpecs
- (void)setUp
{
[super setUp];
@DenTelezhkin
DenTelezhkin / gist:beab675d853fcd2fd464
Created July 22, 2014 15:02
Multipart-form PUT request for image upload. NSURLSession, iOS 7
+(void)uploadUserPhoto:(UIImage *)image
success:(void (^)(void))success
failure:(FailureBlock)failure
{
GTSessionManager * manager = [GTSessionManager manager];
NSString* tmpFilename = [NSString stringWithFormat:@"%f", [NSDate timeIntervalSinceReferenceDate]];
NSURL* tmpFileUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:tmpFilename]];
NSString * query = [NSString stringWithFormat:@"%@user?auth_token=%@",[manager.baseURL absoluteString],[[UserManager shared] authToken]];
@DenTelezhkin
DenTelezhkin / README.md
Last active December 8, 2016 10:08
Rakefile for iTunesConnect upload and testing, iOS

What's this stuff about?

This is a build script for installing dependencies, running tests, and uploading your iOS application builds to Apple's iTunesConnect & Testflight.

Used technologies

  • CocoaPods
  • XCTest
  • Ruby gems: xcpretty, deliver, shenzhen
  • Apple's iTunesConnect&Testflight
@DenTelezhkin
DenTelezhkin / LoadableFromXibView.swift
Last active July 4, 2020 17:47
DEPRECATED. Please use https://github.com/MLSDev/LoadableViews. Create reusable views in XIBs and easily load them in another XIB, storyboard, or programmatically.
import Foundation
import UIKit
protocol NibDefinable {
var nibName: String { get }
}
extension NibDefinable {
var nibName : String {
return String(self.dynamicType)
@DenTelezhkin
DenTelezhkin / prepare_icons.sh
Created September 30, 2016 07:56
Slice iOS app icons from 1024x1024 PNG file, originally taken from https://gist.github.com/jessedc/837916#file-ios-icon-png-bash-script. Updated for Xcode 8 - September 2016.
#!/bin/bash
f=$(pwd)
sips --resampleWidth 512 "${f}/${1}" --out "${f}/iTunesArtwork"
sips --resampleWidth 1024 "${f}/${1}" --out "${f}/iTunesArtwork@2x"
sips --resampleWidth 20 "${f}/${1}" --out "${f}/Icon-20.png"
sips --resampleWidth 40 "${f}/${1}" --out "${f}/Icon-20@2x.png"
sips --resampleWidth 60 "${f}/${1}" --out "${f}/Icon-20@3x.png"
@DenTelezhkin
DenTelezhkin / MeasureAppStartupTime.swift
Last active May 21, 2024 13:40
Measure iOS app startup time, in seconds, from the time user tapped an icon on the home screen (using time, when app process was created). Swift 4.
// Returns number of seconds passed between time when process was created and function was called
func measureAppStartUpTime() -> Double {
var kinfo = kinfo_proc()
var size = MemoryLayout<kinfo_proc>.stride
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)
let start_time = kinfo.kp_proc.p_starttime
var time : timeval = timeval(tv_sec: 0, tv_usec: 0)
gettimeofday(&time, nil)
let currentTimeMilliseconds = Double(Int64(time.tv_sec) * 1000) + Double(time.tv_usec) / 1000.0
@DenTelezhkin
DenTelezhkin / Fastfile
Created March 27, 2019 10:33
Fastfile example for MLSDev blog article.
before_all do
cocoapods
scan
end
# Increment build number to current date
lane :set_build_number do
increment_build_number(
build_number: Time.new.strftime("%Y.%m.%d.%H%M")
)
@DenTelezhkin
DenTelezhkin / UIView+extensions.swift
Created March 27, 2019 10:34
IBInspectable example for MLSDev blog articles
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get { return layer.cornerRadius }
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {