Skip to content

Instantly share code, notes, and snippets.

View srstanic's full-sized avatar

Srđan Stanić srstanic

View GitHub Profile
extension Array where Element: Equatable {
func distinctUntilChanged() -> Self {
var resultArray = Self()
for element in self {
if resultArray.last != element {
resultArray.append(element)
}
}
return resultArray
}
extension Optional where Wrapped == String {
var isEmptyOrNil: Bool {
return self?.isEmpty != false
}
var isNotEmptyNorNil: Bool {
return !isEmptyOrNil
}
}
@srstanic
srstanic / firebase-bd.sh
Created October 22, 2020 10:56
Firebase build and deploy jekyll site to production
JEKYLL_ENV=production bundle exec jekyll build
firebase deploy
#!/bin/sh
echo $1 | python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()));"
import UIKit
extension UIViewController {
/// Creates an instance of `ViewControllerType` defined in a storyboard.
///
/// The setup for this method to work is the following:
/// 1. The storyboard needs to have a single view controller of the type `ViewControllerType`
/// 2. This view controller needs to be set as the initial view controller
/// 3. The name of the view controller needs to match the name of the storyboard and end with "ViewController".
/// e.g. Some.storyboard and SomeViewController
typealias AlertActionStyle = UIAlertAction.Style
extension UIAlertController {
static func create(
style: UIAlertController.Style,
title: String?,
message: String?,
actions: [AlertAction] = [],
onDismiss: VoidHandler? = nil
) -> UIAlertController {
extension FileManager {
func isDirectory(at url: URL) -> Bool {
var isDirectory: ObjCBool = false
guard FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory) else {
return false
}
return isDirectory.boolValue
}
}
/// Inspired by
/// http://blog.benjamin-encz.de/post/main-queue-vs-main-thread/
/// and https://stackoverflow.com/a/60348601
/// Associates a predefined key/value pair with the main queue and later uses the presence of it
/// to determine whether the current queue is the main queue.
extension DispatchQueue {
private static let mainQueueCheckKey: DispatchSpecificKey<String> = {
let mainQueueCheckKey = DispatchSpecificKey<String>()
DispatchQueue.main.setSpecific(key: mainQueueCheckKey, value: mainQueueCheckValue)
return mainQueueCheckKey
extension UIView {
static func withoutConstraints() -> Self {
let instance = self.init()
instance.translatesAutoresizingMaskIntoConstraints = false
return instance
}
func addSubviews(_ views: UIView...) {
for view in views {
addSubview(view)
@srstanic
srstanic / .zshrc
Created March 15, 2022 10:19
.zshrc
autoload -U colors && colors
## rbenv
eval "$(rbenv init - zsh)"
## git
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn
zstyle ':vcs_info:git*' formats "%r/%S%{$fg[grey]%} %{$fg[blue]%}%b%{$reset_color%} (%a) %m%u%c%{$reset_color%} "
precmd() {