Skip to content

Instantly share code, notes, and snippets.

Avatar

Yonat Sharon yonat

View GitHub Profile
@yonat
yonat / Fastfile
Last active Mar 16, 2022
Change any Xcode build setting in fastlane
View Fastfile
desc "Change a value in xcodeproj file."
desc "Usage: fastlane change_build_value xcodeproj:<file-name> name:<build-setting> from:<old-value> to:<new-value>"
lane :change_build_value do |options|
xcodeproj = options[:xcodeproj]
name = options[:name]
from = options[:from]
to = options[:to]
optional_quotes = '"\\{0,1\\}'
replacement_expression = "s/#{name} = #{optional_quotes}#{from}#{optional_quotes};/#{name} = #{to};/g"
@yonat
yonat / UserDefaultsPropertyWrapper.swift
Created Mar 5, 2021
Property wrapper for `UserDefaults.standard` backed value
View UserDefaultsPropertyWrapper.swift
import Foundation
/// Property wrapper for `UserDefaults.standard` backed value
@propertyWrapper
struct UserDefault<Value: UserDefaultsValue> {
let key: String
let defaultValue: Value
let container: UserDefaults
@yonat
yonat / zoom-dl.sh
Last active Apr 25, 2021
Download zoom recordings
View zoom-dl.sh
#!/bin/sh
# courtesy of https://github.com/ytdl-org/youtube-dl/issues/23573#issuecomment-631115716
url="${1%%\?*}"
jar=$(mktemp)
mp4=$(curl -s -c "$jar" "$url" | grep video/mp4 | grep -o 'https:[^"]*')
file=$(echo "$mp4" | grep -o "[^/? ]*\.mp4")
echo "Downloading $file"
View FilteredList.swift
//
// ContentView.swift
// Stacketude
//
// Created by Yonat Sharon on 06/01/2020.
// Copyright © 2020 Yonat Sharon. All rights reserved.
//
import SwiftUI
@yonat
yonat / Binding+Extensions.swift
Last active Dec 13, 2019
Random collection of Swift utilities
View Binding+Extensions.swift
import SwiftUI
extension Binding {
/// Execute block when value is changed.
///
/// Example:
///
/// Slider(value: $amount.didSet { print($0) }, in: 0...10)
func didSet(execute: @escaping (Value) ->Void) -> Binding {
return Binding(
@yonat
yonat / UISegmentedControl+Vertical.swift
Created Sep 12, 2016
Vertical UISegmentedControl
View UISegmentedControl+Vertical.swift
//
// UISegmentedControl+Vertical.swift
// Make a UISegmentedControl vertical by setting mySegmentedControl.vertical = true
//
// Created by Yonat Sharon on 14/9/14.
// Copyright (c) 2014 Yonat Sharon. All rights reserved.
//
import UIKit
@yonat
yonat / String+substr.swift
Created Sep 3, 2016
Perl style substring for Swift String
View String+substr.swift
extension String {
/**
Perl style substring
- parameter offset: Negative offset starts that far back from the end of the string
- parameter length: Negative length leaves that many characters off the end of the string. Omit to return everything through the end of the string.
*/
func substr(offset: Int, length: Int = 0) -> String {
let start = offset < 0 ? endIndex.advancedBy(offset, limit: startIndex) : startIndex.advancedBy(offset, limit: endIndex)
let end = length > 0 ? start.advancedBy(length, limit: endIndex) : endIndex.advancedBy(length, limit: startIndex)
@yonat
yonat / BackgroundTaskWrapper.swift
Last active Nov 28, 2021
iOS background task with all the checks and balances
View BackgroundTaskWrapper.swift
class BackgroundTaskWrapper {
private var taskID = UIBackgroundTaskIdentifier.invalid
var cancelAction: (() -> Void)?
func begin() {
guard .invalid == taskID else { return }
taskID = UIApplication.shared.beginBackgroundTask { [weak self] in
self?.cancelAction?()
self?.end()
}
@yonat
yonat / FBSDKGraphRequest+Paging.h
Last active Apr 5, 2016
Convenience method for Facebook iOS SDK to page through all graph results
View FBSDKGraphRequest+Paging.h
//
// FBSDKGraphRequest+Paging.h
// Facebook Paging Extension
//
// Created by Yonat Sharon on 04.04.2016.
// Copyright © 2016 Yonat Sharon. All rights reserved.
//
#import <FBSDKCoreKit/FBSDKCoreKit.h>
@yonat
yonat / ask.swift
Created Apr 28, 2015
ask() - Show an OK/Cancel modal box that works in both iOS 7 and iOS 8
View ask.swift
/// Show an OK/Cancel modal box that works in both iOS 7 and iOS 8
func ask(title: String, #message: String, #completion: (answer: Bool) -> Void) {
if nil != objc_getClass("UIAlertController".UTF8String) { // use UIAlertController
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action) -> Void in
completion(answer: false)
})
let okayAction = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
completion(answer: true)
})