Skip to content

Instantly share code, notes, and snippets.

View yonat's full-sized avatar

Yonat Sharon yonat

View GitHub Profile
@yonat
yonat / Badge.swift
Last active December 22, 2022 09:40
Rounded UILabel and UIButton, Badged UIBarButtonItem
//
// Badge.swift
// Extensions for Rounded UILabel and UIButton, Badged UIBarButtonItem.
//
// Usage:
// let label = UILabel(badgeText: "Rounded Label");
// let button = UIButton(type: .System); button.rounded = true
// let barButton = UIBarButtonItem(badge: "42", title: "How Many Roads", target: self, action: "answer")
//
// Created by Yonat Sharon on 06.04.2015.
@yonat
yonat / MKStoreKitConfigs.plist
Last active August 29, 2015 14:18
Sample MKStoreKitConfigs.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Consumables</key>
<dict>
<key>com.steinlogic.dummyconsumable.pack10</key>
<dict>
<key>ConsumableCount</key>
<integer>10</integer>
@yonat
yonat / Save-iOS-image-name.md
Last active March 16, 2017 10:01
Set Image Name in iOS Camera Roll
@yonat
yonat / FBSDKGraphRequest+Paging.h
Last active April 5, 2016 07:09
Convenience method for Facebook iOS SDK to page through all graph results
//
// 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 / BackgroundTaskWrapper.swift
Last active November 28, 2021 17:44
iOS background task with all the checks and balances
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 / String+substr.swift
Created September 3, 2016 07:03
Perl style substring for Swift String
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 / Binding+Extensions.swift
Last active December 13, 2019 12:01
Random collection of Swift utilities
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(
//
// ContentView.swift
// Stacketude
//
// Created by Yonat Sharon on 06/01/2020.
// Copyright © 2020 Yonat Sharon. All rights reserved.
//
import SwiftUI
@yonat
yonat / zoom-dl.sh
Last active April 25, 2021 05:31
Download zoom recordings
#!/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"
@yonat
yonat / UserDefaultsPropertyWrapper.swift
Created March 5, 2021 09:26
Property wrapper for `UserDefaults.standard` backed value
import Foundation
/// Property wrapper for `UserDefaults.standard` backed value
@propertyWrapper
struct UserDefault<Value: UserDefaultsValue> {
let key: String
let defaultValue: Value
let container: UserDefaults