Skip to content

Instantly share code, notes, and snippets.

View srstanic's full-sized avatar

Srđan Stanić srstanic

View GitHub Profile
@srstanic
srstanic / NakedTabBarController.swift
Last active July 26, 2021 10:51
A UITabBarController with the invisible tabbar.
class NakedTabBarContorller: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.isHidden = true
}
}
@srstanic
srstanic / ModelState.swift
Last active June 22, 2020 11:26
ModelState and ModelStateUpdateNotifier
import Foundation
protocol ModelStateDelegate: class {
func onModelStateOutdated()
}
class ModelState {
weak var delegate: ModelStateDelegate?
init(updateNotification: Foundation.Notification.Name, itemId: String? = nil, outdated: Bool = true) {
import Foundation
typealias VoidVoid = () -> ()
protocol Repeating {
func startRepeating(withIntervalInSeconds: TimeInterval)
func stopRepeating()
@srstanic
srstanic / TableViewModel.swift
Last active June 22, 2020 11:38
Generic implementation of UITableViewDataSource & UITableViewDelegate
import UIKit
extension UITableViewCell {
class var reuseIdentifier: String {
return "tableViewCell"
}
}
extension Collection {
/// Returns the element at the specified index if it is within bounds, otherwise nil.
@srstanic
srstanic / UIScrollView+scrollForDistance.swift
Created December 6, 2017 17:40
Animated scroll to left or right for distance
extension UIScrollView {
func scrollToLeft(for distance: CGFloat, withAnimationDuration animationDuration: TimeInterval = 0.3) {
var newOffset = self.contentOffset.x - distance
if newOffset < 0 {
newOffset = 0
}
UIView.animate(withDuration: animationDuration) {
self.contentOffset.x = newOffset
}
@srstanic
srstanic / UIView+ShowHide.swift
Last active November 22, 2017 10:53
Showing and hiding UIView
extension UIView {
func show(animated: Bool) {
self.isHidden = false
if animated {
UIView.animate(
withDuration: animationDuration,
animations: {
self.alpha = 1
}
import UIKit
class KeyboardAvoider {
init(for scrollView: UIScrollView) {
self.scrollView = scrollView
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(
self,
@srstanic
srstanic / load-gif-in-background.js
Created March 24, 2017 19:23
Load gif in background
var gifs = {
'imageElementId': 'http://example.com/myimage.gif'
}
function getUpdateImageSrcFunc(imageId) {
return function() {
document.getElementById(imageId).src = this.src;
}
}
for (var imageId in gifs) {
var gifSrc = gifs[imageId]
@srstanic
srstanic / RoundedBorderButton.swift
Last active March 30, 2017 21:02
RoundedBorderButton.swift
import UIKit
@IBDesignable
class RoundedBorderButton: UIButton {
@IBInspectable dynamic var cornerRadius: CGFloat = 20.0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = true
}
#!/bin/bash
IFS='.' read -a filename_parts <<< "$1"
name=${filename_parts[0]}
ext=${filename_parts[1]}
sips -Z 66 $1 --out $name"-66."$ext
sips -Z 44 $1 --out $name"-44."$ext