Skip to content

Instantly share code, notes, and snippets.

Avatar

Dino Budimilić budidino

View GitHub Profile
View stackoverflow - returnTweet()
// example to help out someone on stackoverflow
// http://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1/16169848?noredirect=1#comment34312649_16169848
// get the array of tweets
$tweets = returnTweet();
// loop all the tweets and display each of them
foreach($tweets as $tweet){
echo "Tweet: " . $tweet["text"] . "<br>";
}
View globals, UIFont and UILabel extensions
// Some of the things I use in my projects
import UIKit
let sharedApp = UIApplication.shared
let noteCenter = NotificationCenter.default
let userDefaults = UserDefaults.standard
func assertOnMain() { assert(Thread.isMainThread) }
func assertOffMain() { assert(!Thread.isMainThread) }
func assertFail() { assert(false) }
@budidino
budidino / compressVideo.swift
Created Jan 24, 2017
compress and optionally mute video in Swift 2
View compressVideo.swift
func compressVideo(inputURL: NSURL, outputURL: NSURL, bitRate: Int, muteSound: Bool, onDone: () -> ()) {
let videoAsset = AVURLAsset(URL: inputURL, options: nil)
let videoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0]
let videoSize = videoTrack.naturalSize
let videoWriterCompressionSettings = [
AVVideoAverageBitRateKey: bitRate
]
let videoWriterSettings:[String : AnyObject] = [
AVVideoCodecKey : AVVideoCodecH264,
@budidino
budidino / gist:e0d4e353bc1e9a58caa67f450dc55f5c
Last active Mar 11, 2017
play video's audio out loud and resume playback after plugging out headphones
View gist:e0d4e353bc1e9a58caa67f450dc55f5c
// SWIFT 2 - http://stackoverflow.com/a/42730969/611879
// setup player
let audioSession = AVAudioSession.sharedInstance()
_ = try? audioSession.setCategory(AVAudioSessionCategoryPlayback, withOptions: .DuckOthers)
_ = try? audioSession.setActive(true)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(audioRouteChanged), name: AVAudioSessionRouteChangeNotification, object: nil)
player.play()
@budidino
budidino / gist:ffefdbd1a8a33607c54d495b6120850e
Created Apr 28, 2017 — forked from acj/TrimVideo.swift
Trim video using AVFoundation in Swift
View gist:ffefdbd1a8a33607c54d495b6120850e
//
// TrimVideo.swift
// VideoLab
//
// Created by Adam Jensen on 3/28/15.
// Copyright (c) 2015 Adam Jensen. All rights reserved.
//
import AVFoundation
import Foundation
@budidino
budidino / isVenueOpenWithFoursquareHours
Last active Apr 28, 2017
handle foursquare hours API - return if venue is open, if it's going to be open or when it closed
View isVenueOpenWithFoursquareHours
-(NSDictionary*)isVenueOpenDictionaryForHours:(NSArray*)hours{
// defaults and inits
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDictionary *lastSegmentYesterday = [[NSDictionary alloc] init];
NSDate *dateNow = [NSDate date];
NSString *venueOpenText = [[NSString alloc] init];
NSString *venueOpen = @"no";
// get components for today
NSDateComponents *compsNow = [gregorian components:NSWeekdayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:dateNow];
@budidino
budidino / countryCodeFlags.swift
Created Sep 16, 2020
Dictionary with country codes and their flags
View countryCodeFlags.swift
var flagDictionary: [String: String] = [
"AD": "🇦🇩", "AE": "🇦🇪", "AF": "🇦🇫", "AG": "🇦🇬", "AI": "🇦🇮", "AL": "🇦🇱", "AM": "🇦🇲", "AO": "🇦🇴", "AQ": "🇦🇶", "AR": "🇦🇷", "AS": "🇦🇸", "AT": "🇦🇹", "AU": "🇦🇺", "AW": "🇦🇼", "AX": "🇦🇽", "AZ": "🇦🇿", "BA": "🇧🇦", "BB": "🇧🇧", "BD": "🇧🇩", "BE": "🇧🇪", "BF": "🇧🇫", "BG": "🇧🇬", "BH": "🇧🇭", "BI": "🇧🇮", "BJ": "🇧🇯", "BL": "🇧🇱", "BM": "🇧🇲", "BN": "🇧🇳", "BO": "🇧🇴", "BQ": "🇧🇶", "BR": "🇧🇷", "BS": "🇧🇸", "BT": "🇧🇹", "BV": "🇧🇻", "BW": "🇧🇼", "BY": "🇧🇾", "BZ": "🇧🇿", "CA": "🇨🇦", "CC": "🇨🇨", "CD": "🇨🇩", "CF": "🇨🇫", "CG": "🇨🇬", "CH": "🇨🇭", "CI": "🇨🇮", "CK": "🇨🇰", "CL": "🇨🇱", "CM": "🇨🇲", "CN": "🇨🇳", "CO": "🇨🇴", "CR": "🇨🇷", "CU": "🇨🇺", "CV": "🇨🇻", "CW": "🇨🇼", "CX": "🇨🇽", "CY": "🇨🇾", "CZ": "🇨🇿", "DE": "🇩🇪", "DJ": "🇩🇯", "DK": "🇩🇰", "DM": "🇩🇲", "DO": "🇩🇴", "DZ": "🇩🇿", "EC": "🇪🇨", "EE": "🇪🇪", "EG": "🇪🇬", "EH": "🇪🇭", "ER": "🇪🇷", "ES": "🇪🇸", "ET": "🇪🇹", "FI": "🇫🇮", "FJ": "🇫🇯", "FK": "🇫🇰", "FM": "🇫🇲", "FO": "🇫🇴", "FR": "🇫🇷", "GA": "🇬🇦", "GB": "🇬🇧", "GD": "🇬🇩", "GE": "🇬🇪", "GF": "🇬🇫", "GG": "🇬🇬", "GH": "🇬🇭
@budidino
budidino / HapticFeedback.swift
Last active Feb 11, 2021
simplified way to call haptic feedback
View HapticFeedback.swift
import Foundation
enum HapticStyle {
case light
case medium
case heavy
case success
case error
case warning
case selection
@budidino
budidino / UIColor.swift
Created Feb 11, 2021
init UIColor using hex string
View UIColor.swift
/*
// convenience method for initializing UIColor with HEX value
UIColor("#ff0000") // with #
UIColor("ff0000") // without #
UIColor("ff0000", alpha: 0.5) // using optional alpha value
*/
extension UIColor {
convenience init(_ hex: String, alpha: CGFloat = 1.0) {
@budidino
budidino / UIView extensions
Last active Feb 20, 2021
Useful UIView extensions for animating views - usually used when UIView is updated or interacted with
View UIView extensions
extension UIView {
func springIn(duration: TimeInterval = 0.5, delay: Double = 0, fromScale: CGFloat = 0.6) {
self.layer.removeAllAnimations()
self.alpha = 1
self.transform = CGAffineTransform(scaleX: fromScale, y: fromScale)
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.5, initialSpringVelocity: 3.0, options: [.curveEaseInOut, .allowUserInteraction], animations: {
self.transform = .identity
})
}