This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Alamofire.request(urlString).responseJSON { response in | |
| guard case let .failure(error) = response.result else { return } | |
| if let error = error as? AFError { | |
| switch error { | |
| case .invalidURL(let url): | |
| print("Invalid URL: \(url) - \(error.localizedDescription)") | |
| case .parameterEncodingFailed(let reason): | |
| print("Parameter encoding failed: \(error.localizedDescription)") | |
| print("Failure Reason: \(reason)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut | |
| //Use the extension method to dequeue an instance of the appropriate `Reusable` | |
| class MyVC: UITableViewDataSource { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| tableView | |
| .registerReusable(FooCell.self) | |
| .registerReusable(BarCell.self) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public extension FileManager { | |
| /// This method calculates the accumulated size of a directory on the volume in bytes. | |
| /// | |
| /// As there's no simple way to get this information from the file system it has to crawl the entire hierarchy, | |
| /// accumulating the overall sum on the way. The resulting value is roughly equivalent with the amount of bytes | |
| /// that would become available on the volume if the directory would be deleted. | |
| /// | |
| /// - note: There are a couple of oddities that are not taken into account (like symbolic links, meta data of | |
| /// directories, hard links, ...). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // in a UITableViewController (or any other view controller with a UITableView) | |
| - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator | |
| { | |
| UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 0)]; | |
| header.translatesAutoresizingMaskIntoConstraints = NO; | |
| // [add subviews and their constraints to header] | |
| NSLayoutConstraint *headerWidthConstraint = [NSLayoutConstraint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CSS Color Names | |
| // Compiled by @bobspace. | |
| // | |
| // A javascript array containing all of the color names listed in the CSS Spec. | |
| // The full list can be found here: http://www.w3schools.com/cssref/css_colornames.asp | |
| // Use it as you please, 'cuz you can't, like, own a color, man. | |
| var CSS_COLOR_NAMES = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rotate(srcBase64, degrees, callback) { | |
| const canvas = document.createElement('canvas'); | |
| const ctx = canvas.getContext('2d'); | |
| const image = new Image(); | |
| image.onload = function () { | |
| canvas.width = degrees % 180 === 0 ? image.width : image.height; | |
| canvas.height = degrees % 180 === 0 ? image.height : image.width; | |
| ctx.translate(canvas.width / 2, canvas.height / 2); |