Skip to content

Instantly share code, notes, and snippets.

View jayesh15111988's full-sized avatar

Jayesh Kawli jayesh15111988

View GitHub Profile
<html>
<body style='margin:0px;padding:0px;'>
<script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>
<script type='text/javascript'>
var ytplayer;
function timeElapsed() {
return Math.floor(ytplayer.getCurrentTime())
}
@jayesh15111988
jayesh15111988 / AccountDownloader.swift
Last active December 16, 2016 21:49
Swift testing with Protocols
import Foundation
import UIKit
protocol DownloadAccountProtocol {
func downloadAccount(with name: String, completion: (Person) -> ())
}
class ServerDownloader: DownloadAccountProtocol {
func downloadAccount(with name: String, completion: (Person) -> ()) {
let personDictionary: [String: String] = [:] // Dictionary JSON downloaded from server
private var searchTimer: Timer?
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if let searchTimer = searchTimer {
searchTimer.invalidate()
}
searchTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(self.reload(timer:)), userInfo: searchText, repeats: false)
}
func reload(timer: Timer) {
@jayesh15111988
jayesh15111988 / swift-error-handling.swift
Created January 23, 2017 00:57
A Sample code to demonstrate Swift error handling
import Foundation
enum PasswordError: Error {
case TooShort
case NoNumber
case CustomMessage(message: String)
}
class PasswordChecker {
// This
public indirect enum BrickDimension {
case Ratio(ratio: CGFloat)
case Fixed(size: CGFloat)
case Fill
case Auto(estimate: BrickDimension)
case Orientation(landscape: BrickDimension, portrait: BrickDimension)
case HorizontalSizeClass(regular: BrickDimension, compact: BrickDimension)
case VerticalSizeClass(regular: BrickDimension, compact: BrickDimension)
@jayesh15111988
jayesh15111988 / SwiftyTableView.swift
Created February 20, 2017 01:16
A tableview with Swifty style
import UIKit
// Reference: https://medium.com/swift-programming/upgrade-your-tableviews-with-loading-state-in-swift-1fdce34ada77#.w4sg0dwhk
class SwiftyTableView: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView: UITableView = UITableView()
let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
var tableState = TableState<String>.Loading {
didSet {
//
// AutolayoutScrollView.swift
// Sample
//
// Created by Jayesh Kawli on 2/23/19.
// Copyright © 2019 Jayesh Kawli. All rights reserved.
//
import UIKit
//
// ScrollViewSupportViewController.swift
// Sample
//
// Created by Jayesh Kawli on 2/23/19.
// Copyright © 2019 Jayesh Kawli. All rights reserved.
//
import UIKit
@jayesh15111988
jayesh15111988 / ImageDownloader.swift
Created April 26, 2020 21:37
A gist for image downloader and caching library written in Swift for iOS applications
import UIKit
// Image downloader utility class. We are going to use the singleton instance to be able to download required images and store them into in-memory cache.
final class ImageDownloader {
static let shared = ImageDownloader()
private var cachedImages: [String: UIImage]
private var imagesDownloadTasks: [String: URLSessionDataTask]
//
// MovieCell.swift
//
import UIKit
final class MovieCell: UITableViewCell {
let posterImageView = UIImageView(frame: .zero)