Skip to content

Instantly share code, notes, and snippets.

View AmitaiB's full-sized avatar

Amitai Blickstein AmitaiB

View GitHub Profile
@AmitaiB
AmitaiB / .gitignore
Last active August 29, 2015 14:25 — forked from octocat/.gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
-(void)geocodeMe {
CLGeocoder *geocoder = [CLGeocoder new];
[geocoder geocodeAddressString:@"" completionHandler:^(NSArray *placemarks, NSError *error) {
/**
* deprecated sample error message
*/
if (error)
{
// [self.latitudeTextField setText:@"Not found"];
// [self.longitudeTextField setText:@"Not found"];
@AmitaiB
AmitaiB / UIImage+FromURL.m
Last active August 29, 2015 14:28
shortens getting a UIImage from the string of a URL
#import <UIKit/UIKit.h>
@interface UIImage (FromURL)
+(UIImage*)imageWithContentsOfURLString:(NSString*)URLString;
@end
//*************************************
@AmitaiB
AmitaiB / OptionalLiteralType.swift
Created September 28, 2016 17:52
Provides failable initializers for X-Literals, e.g., `String(suspectedString) // returns a String optional`, just like `String(5) // returns a String, "5"`
/*
Instead of, say:
if let definitelyAString = perhapsAString as? String { // yadda... }
We now have:
String(perhapsAString) // returns a String? (an optional)
*/
protocol OptionalLiteralType {
@AmitaiB
AmitaiB / UITableViewCellStyle+PlainEnglishNames.swift
Created November 28, 2016 19:12
Replaces the opaque styles 'value1' and 'value2' with 'rightDetail' and 'leftDetail' respectively.
//
// UITableViewCellExtensions.swift
// HealthBucks
//
// Created by Amitai Blickstein on 11/28/16.
// Copyright © 2016 Amitai Blickstein, LLC. All rights reserved.
//
import UIKit
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
@AmitaiB
AmitaiB / snake_cased.swift
Last active March 30, 2018 03:39
Turns CamelCase and lamaCase strings into snakecase aka underscorecase (Swift 3.0)
// Swift 3.0
// snake_cased
import Foundation
extension String {
mutating func snake_cased() {
self = self.snake_case()
}
func snake_case() -> String {
// Not mine, forgot to whom to give the credit. :(
import Foundation
/// Allows `collection.safe.whatever`. Mimics usage of AVFoundation's `collection.lazy.whatever`
public struct SafeCollection<Base : Collection> {
private var _base: Base
public init(_ base: Base) {
_base = base
@AmitaiB
AmitaiB / ConvertibleNumberType.swift
Created February 13, 2019 21:00
Drop-in, extendable Swift extension that allows for easy, clean number interoperability
/**
* Give Int, CGFloats, and Floats a `doubleValue` property, like `NSNumber`.`doubleValue`
Original By Erica Sadun, (Swift Cookbook recipe 5-1), found here: https://gist.github.com/erica/2f6a38c844573c778b0f
Subsequent mutilations by Amitai Blickstein
*/
//: Numbers that convert to other types
public protocol ConvertibleNumberType: DoubleRepresentable, NumberInitAble {}
@AmitaiB
AmitaiB / SwiftXOR.swift
Created November 17, 2016 04:41
Swift 3 Logical XOR Operator
precedencegroup BooleanPrecedence { associativity: left }
infix operator ^^ : BooleanPrecedence
/**
Swift Logical XOR operator
```
true ^^ true // false
true ^^ false // true
false ^^ true // true
false ^^ false // false
```