Skip to content

Instantly share code, notes, and snippets.

View artem-sherbachuk's full-sized avatar
🏠
Working from home

Artem Sherbachuk artem-sherbachuk

🏠
Working from home
View GitHub Profile
// MARK: - Adding a header to a single request
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
]
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers)
.responseJSON { response in
debugPrint(response)
@artem-sherbachuk
artem-sherbachuk / xcodebuild_profiling_func_swift.sh
Created November 15, 2016 18:55
Profiling compilation time of most expensivest func in swift
# Clean and build, capturing only lines containing `X.Yms` where X > 0, sorting from largest to smallest
# http://irace.me/swift-profiling
xcodebuild -workspace App.xcworkspace -scheme App clean build | grep [1-9].[0-9]ms | sort -nr > culprits.txt
@artem-sherbachuk
artem-sherbachuk / FadingInOutAVPlayer.swift
Created January 19, 2017 09:43
Fading audio in and out AVPlayer
let player = AVPlayer()
func playFileAtURL(url: NSURL) {
let asset = AVAsset.assetWithURL(url) as AVAsset
let duration = asset.duration
let durationInSeconds = CMTimeGetSeconds(duration)
let item = AVPlayerItem(asset: asset)
let params = AVMutableAudioMixInputParameters(track: asset.tracks.first! as AVAssetTrack)
@artem-sherbachuk
artem-sherbachuk / MeasureCode.swift
Created January 19, 2017 10:49
measure code execution time with block.
func measure(title: String, block: (() -> ()) -> ()) {
let startTime = CFAbsoluteTimeGetCurrent()
block {
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
println("\(title):: Time: \(timeElapsed)")
}
}