Skip to content

Instantly share code, notes, and snippets.

View dennislysenko's full-sized avatar

Dennis Lysenko dennislysenko

View GitHub Profile
@akatkov7
akatkov7 / ApplyAndWith.swift
Created March 26, 2018 18:25
Adds Kotlin-esque apply/with to Swift
import Foundation
protocol ApplyProtocol { }
extension NSObject: ApplyProtocol { }
extension ApplyProtocol {
@discardableResult func apply(closure: (Self) -> Void) -> Self {
closure(self)
return self
@dennislysenko
dennislysenko / SimpleMediaSaver.swift
Last active December 10, 2019 02:54
Simplifies saving media on iOS to an app-specific collection in the Photo Library
//
// SimpleMediaSaver.swift
//
// Created by Dennis Lysenko on 27-09-16.
// Copyright © 2016 Dennis Lysenko. All rights reserved.
// https://gist.github.com/dennislysenko/5388cacb83b754e8983e99bff7fef2d2
//
// This gist is licensed under the terms of the MIT license.
//
brew list -1 | while read line; do brew unlink $line; brew link $line; done
@hlissner
hlissner / replace.sh
Last active September 11, 2023 10:14
Bulk search & replace with ag (the_silver_searcher)
# ag <https://github.com/ggreer/the_silver_searcher>
# usage: ag-replace.sh [search] [replace]
# caveats: will choke if either arguments contain a forward slash
# notes: will back up changed files to *.bak files
ag -0 -l $1 | xargs -0 perl -pi.bak -e "s/$1/$2/g"
# or if you prefer sed's regex syntax:
ag -0 -l $1 | xargs -0 sed -ri.bak -e "s/$1/$2/g"
@s4y
s4y / showAlert.swift
Last active March 15, 2016 07:40
A function for showing alerts and action sheets, written for iOS 7 and 8
import UIKit
// Notes:
// - You must explicitly weak link to UIKit to support iOS 7
// - Action sheets on iOS 7 only show a title
func showAlert(viewController: UIViewController, style: UIAlertControllerStyle = .Alert, title: String? = nil, message: String? = nil, sourceView: UIView? = nil, completion: (() -> ())? = nil, buttons: (UIAlertActionStyle, String, (() -> ())?)...) {
if (NSClassFromString("UIAlertController") != nil) {
// iOS 8+