Skip to content

Instantly share code, notes, and snippets.

View maximbilan's full-sized avatar
🧑‍🚒
Working...

Maksym Bilan maximbilan

🧑‍🚒
Working...
View GitHub Profile
@maximbilan
maximbilan / pascals-triangle.swift
Created April 17, 2022 08:57
Pascal's Triangle (Swift)
import Foundation
class Solution {
func generate(_ numRows: Int) -> [[Int]] {
var result = [[Int]]()
for i in 0..<numRows {
var array = Array(repeating: 1, count: i + 1)
if i > 1 {
let previousArray = result[i-1]
public extension UIView {
class func fromNib<T: UIView>() -> T {
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
@maximbilan
maximbilan / SwiftyAccountKit.swift
Created August 12, 2017 08:13
SwiftyAccountKit - Facebook AccountKit Swift Wrapper
//
// SwiftyAccountKit.swift
// SwiftyAccountKit
//
// Created by Maxim on 7/13/17.
// Copyright © 2017 Maxim Bilan. All rights reserved.
//
import AccountKit
@maximbilan
maximbilan / Trim.swift
Created February 10, 2017 20:36
Swift 3 Trimming of special characters
extension String {
func trim(_ string: String) -> String {
var set = Set<Character>()
for c in string.characters {
set.insert(Character(String(c)))
}
return trim(set)
}
@maximbilan
maximbilan / AmazonS3Uploader.swift
Created February 10, 2017 20:27
Swift 3 Upload file to Amazon S3 with pre-signed link
func upload(data: Data, urlString: String, mimeType: String, completion: @escaping (Bool, Error?) -> Void) {
let requestURL = URL(string: urlString)!
let client = AFHTTPSessionManager(baseURL: requestURL)
var request = URLRequest(url: requestURL)
request.httpMethod = "PUT"
request.httpBody = data
request.setValue(mimeType, forHTTPHeaderField: "Content-Type")
request.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
request.setValue("public-read", forHTTPHeaderField: "x-amz-acl")
let task = client?.dataTask(with: request, completionHandler: { (response, responseObject, error) in
extension Date {
struct Formatter {
static let iso8601: DateFormatter = {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale.current
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
@maximbilan
maximbilan / UITextViewPlaceholder.swift
Created July 24, 2016 06:53
UITextView Placeholder Example
import UIKit
class ViewController: UIViewController {
let placeholder = "Placeholder"
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
@maximbilan
maximbilan / InstagramWallPost.swift
Created July 24, 2016 06:11
iOS Instagram Wall Post
let image = UIImage(named: "example")
let instagramURL = NSURL(string: "instagram://app")
if UIApplication.sharedApplication().canOpenURL(instagramURL!) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let saveImagePath = (documentsPath as NSString).stringByAppendingPathComponent("Image.igo")
let imageData = UIImagePNGRepresentation(image!)
do {
try imageData?.writeToFile(saveImagePath, options: NSDataWritingOptions(rawValue: 0))
} catch {
print("Instagram sharing error")
@maximbilan
maximbilan / NSLayoutConstraintMultiplierExtension.swift
Created July 21, 2016 12:51
NSLayoutConstraint Multiplier Extension
extension NSLayoutConstraint {
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(
item: firstItem,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
attribute: secondAttribute,
@maximbilan
maximbilan / ConnectionCheck.swift
Created July 16, 2016 09:21
Swift Quick Internet Availability Check
import SystemConfiguration
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in()
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))