Skip to content

Instantly share code, notes, and snippets.

View tartakovsky's full-sized avatar

Eugene Tartakovsky tartakovsky

View GitHub Profile
04bbc49892c7ffcb5ce52788628a409715238c448bb931ee17db634197db04cd8c5dc03d3718c87dcf244708e4a5e994d5e34356e64433d9bc16c2bc62be13b426;GoodGuyMat
@tartakovsky
tartakovsky / iterm2-solarized.md
Created July 5, 2017 23:34 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@tartakovsky
tartakovsky / UIView+Mask.swift
Created October 7, 2016 12:15
UIView+Mask.swift
// Mask UIView with rect/path
// inverse = false: part inside rect is kept, everything outside is clipped
// inverse = true: part inside rect is cut out, everything else is kept
//
// Usage:
//
// // - Cuts rectangle inside view, leaving 20pt borders around
// let rect = CGRect(x: 20, y: 20, width: bounds.size.width - 20*2, height: bounds.size.height - 20*2)
// targetView.mask(withRect: rect, inverse: true)
//
@tartakovsky
tartakovsky / validation.swift
Last active February 5, 2016 21:32
Reactive form validation
let emailStream = emailTextField.bnd_text
let passwordStream = passwordTextField.bnd_text
let emailErrorStream = emailStream.map { self.validateEmail($0) }
let passwordErrorStream = passwordStream.map { self.validatePassword($0) }
let errorStream = combineLatest(emailErrorStream, passwordErrorStream).map {
[$0, $1].flatMap{ $0 }.filter{ $0 != nil }.first
}
let formValidStream = errorStream.map{ $0==nil }
@tartakovsky
tartakovsky / #Guide: DefaultStringConvertible.swift
Last active December 1, 2015 15:01
Default description property getter for types that conform to CustomStringConvertible
How to use it:
1. Add the file to the project
2. Append CustomStringConvertible or CustomDebugStringConvertible protocol to the type you want to have description
3. Now you can call object.description on any custom Class or Struct you've made
@tartakovsky
tartakovsky / #Guide: Stopwatch Swift
Last active October 3, 2016 16:27
Reusable Stopwatch class implemented in Swift
This is the implementation of Stopwatch class.
Usage:
1. Add the Stopwatch.swift file to the project
2. Create instance and assing the callback function
let stopwatch = Stopwatch()
stopwatch.callback = self.tick
3. Implement the callback function
@tartakovsky
tartakovsky / #Guide: UICollectionView Swift
Last active February 16, 2016 00:33
UICollectionView Swift
What do you need to do to implement working UICollectionView:
1. Add UIViewController to the storyboard.
2. Create YourViewController class, subclass of the UIViewController.
3. Go to the storyboard -> select new View Controller -> Identity Inspector -> set Class to YourViewController.
4. Drag'n'drop UICollectionView to the YourViewController in storyboard.
5. It will contain one UICollectionViewCell. Otherwise, drag'n'drop UICollectionViewCell to the UICollectionView.
5. Go to the storyboard -> select new Cell -> Attributes Inspector -> set Identifier to "YourCell".
6. Go to YourViewController file, create reuseIdentifier constant and set it's vaule to "YourCell".
7. Go to the storyboard -> drag delegate and dataSource connections from UICollectionView to YourViewController
8. Implement UICollectionViewDataSource protocol via Swift extension
@tartakovsky
tartakovsky / #Guide: Fisher-Yates Shuffle Swift
Last active October 31, 2016 00:22
Fisher-Yates Shuffle in Swift.
Source: http://stackoverflow.com/a/24029847/1855792 by Nate Cook
Implementation of Fisher-Yates (fast and uniform) shuffle for any collection type using Swift 2 Protocol Extensions.
The naming and behavior follow Swift 2.0's sort() and sortInPlace() methods.
Code:
See FisherYatesShuffle.swift file
Usage:
[1, 2, 3].shuffle()