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
struct GeocodingResult:Codable{ | |
struct Geometry:Codable{ | |
struct Location:Codable{ | |
let lat:Float | |
let lng:Float | |
} | |
let location:Location | |
} | |
let formattedAddress:String | |
let geometry:Geometry |
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
import Foundation | |
let geoResult=""" | |
{ | |
"results": [ | |
{ | |
"formatted_address": "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA", | |
"geometry": { | |
"location": { | |
"lat": 37.4224764, |
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
let inputData = """ | |
{"x":10,"y":10,"moment":"2017-06-08T21:36:37Z"} | |
""".data(using: .utf8)! | |
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .iso8601 | |
let obj=try? decoder.decode(Point.self, from: inputData) | |
if let point=obj{ | |
print(point.x) | |
} |
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
import Foundation | |
struct Point:Codable{ | |
var x:Float | |
var y:Float | |
var moment:Date | |
} | |
let p=Point(x:10,y:10,moment:Date()) | |
let x=JSONEncoder() |
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
extension String{ | |
static func randomEmoji()->String{ | |
let range = [UInt32](0x1F601...0x1F64F) | |
let ascii = range[Int(drand48() * (Double(range.count)))] | |
let emoji = UnicodeScalar(ascii)?.description | |
return emoji! | |
} | |
} |
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
import Foundation | |
var str = """ | |
This is some text that needs to be processed. I do not know how fast this runs? | |
日本, | |
Лорем ипсум долор сит амет, перпетуа урбанитас ин про, проприае цонсететур ид сит | |
""" | |
let tagger=NSLinguisticTagger(tagSchemes: [.lemma, .language, .lexicalClass], options:0 ) | |
tagger.string=str |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import MapKit | |
import PlaygroundSupport | |
class Container:UIView{ | |
let mapView:MKMapView | |
override init(frame: CGRect) { |
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
import Foundation | |
import XCPlayground | |
// Updated for Swift 2.0 | |
let url:NSURL!=NSURL(string: "http://objectgraph.com") | |
NSURLSession.sharedSession().dataTaskWithURL(url) { data, response, error in | |
print(NSString(data: data!, encoding: NSUTF8StringEncoding)) | |
print(error) | |
print(response) | |
}.resume() | |
print("This line is printed first as the network call is not complete") |
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
import Foundation | |
func BlockingGet(url:String)->String?{ | |
let sema=dispatch_semaphore_create(0) | |
let url:NSURL!=NSURL(string:url) | |
var output:String? | |
NSURLSession.sharedSession().dataTaskWithURL(url) { | |
data, response, error in | |
output = NSString(data: data!, encoding: NSUTF8StringEncoding) as String? | |
dispatch_semaphore_signal(sema) |
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
/* | |
As you read the data, use Object.keys() method to extract the column names. Might be useful for binding dropdowns. | |
*/ | |
var columns=null; | |
d3.csv('nutdata.csv').row(function(row){ | |
if(columns==null){ | |
columns=Object.keys(row); | |
columns=columns.slice(2,48); //Optional - to remove columns you dont need | |
} |
NewerOlder