Skip to content

Instantly share code, notes, and snippets.

def algo(env)
data_raw = open('http://spreadsheets.google.com/tq?key=0AsTunpthKrMxdEp5R1loYjBBcVhNQWVEc1BUZmZ1QUE&pub=1')
data = data_raw.read
data = data.split('(')[1].split(")")[0]
data = data.gsub("'", '"')
data = data.gsub(/([a-z]+):/, '"\1":')
result = JSON.parse(data)
require "open-uri"
require "json"
class RuteoApp
def batman(env)
[200, {"Content-Type" => "text/plain"}, "El Guason"]
end
func centerMapWithCoords(coordsArr:[CLLocationCoordinate2D]){
var zoomRect:MKMapRect = MKMapRectNull;
for coord:CLLocationCoordinate2D in coordsArr {
var annotationPoint: MKMapPoint = MKMapPointForCoordinate(coord)
var pointRect:MKMapRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0)
zoomRect = MKMapRectUnion(zoomRect, pointRect)
}
mapView.setVisibleMapRect(zoomRect, edgePadding:UIEdgeInsetsMake(150, 30, 30, 30), animated:false)
func setupBackButton(){
var count: Int? = navigationController?.viewControllers.count
if count > 0 && navigationItem.leftBarButtonItem == nil{
if !(navigationController?.viewControllers.first === self) {
self.navigationItem.leftBarButtonItem = HSAppearance.barButtonWithTitle("BACK", image:UIImage(named:"ArrowLeft"), target: self, action: "HSBackAction:")
}
}
}
@Busta117
Busta117 / gist:f7e7e81d9c2098505359
Created June 13, 2015 21:22
address from cords
class func getAddressFromCoords(coords:CLLocationCoordinate2D, complete:(location:Location?, error:NSError?)->()){
var url = "http://maps.googleapis.com/maps/api/geocode/json"
var str = String(format: "%f",coords.latitude) + "," + String(format:"%f",coords.longitude)
var params = ["latlng":str, "sensor":true]
AFHTTPRequestOperationManager().GET(url, parameters: params, success: { (operation:AFHTTPRequestOperation!, response:AnyObject!) -> Void in
let json:JSON = JSON(response)
var loc = Location(dictionary: json)
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
@Busta117
Busta117 / ArrayTransform
Created October 2, 2016 22:06
transform array from objectMapper parsing to Realm List
//transform array from objectMapper parsing to Realm List
public class ArrayTransform<T:RealmSwift.Object where T:Mappable> : TransformType {
public typealias Object = List<T>
public typealias JSON = Array<Any>
public init(){
}
public func transformFromJSON(_ value: Any?) -> List<T>? {
let result = List<T>()
@Busta117
Busta117 / BaristaISO8601DateTransform
Created October 3, 2016 18:56
objectmapper ISO8601 date transform
import ObjectMapper
import RealmSwift
open class BaristaISO8601DateTransform: TransformType {
public typealias Object = Date
public typealias JSON = String
let dateFormatter: DateFormatter = DateFormatter()
@Busta117
Busta117 / Image
Last active October 3, 2016 19:16
extension UIImage tint color swift 3
public extension UIView {
/**
Convert current view to image
:returns: return the image
*/
public func convertToImage() -> UIImage {
UIGraphicsBeginImageContext(self.bounds.size);
self.layer.render(in: UIGraphicsGetCurrentContext()!)
let viewImage = UIGraphicsGetImageFromCurrentImageContext()
@Busta117
Busta117 / DateFormatterISO8601Regex
Created October 24, 2016 05:49
return the right dateString and dateFormat of a ISO8601 to use it in DateFormatter, validated by regular expression, so, you don't need to fight again with those formats
func formatFrom(_ value:String) -> (dateString:String?, dateFormat:String?) {
var regexString = "\\A(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2})" // Mandatory - YYYY-MM-DDTHH:mm
regexString = regexString + ":?(\\d{2})?" // Optional - :ss
regexString = regexString + "[.]?(\\d{1,6})?" // Optional - .nnnnnn
regexString = regexString + "([+-])?(\\d{2})?:?(\\d{2})?|Z" // Optional -[+-]hh:mm or Z
regexString = regexString + "\\z"
let regex: NSRegularExpression?
var matchesResult: [NSTextCheckingResult]?