Skip to content

Instantly share code, notes, and snippets.

@berikv
berikv / uninstall_xcode.sh
Created April 21, 2022 14:11
Uninstall XCode.app, its caches, CommandLineTools and installation records
#!/bin/sh
set -x
sudo rm -rf /Library/Developer/CommandLineTools/
sudo rm -rf /Applications/Xcode.app
rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Application\ Support/Xcode
rm -rf ~/Library/Developer/
@berikv
berikv / ViewPrint.swift
Created January 13, 2022 16:19
Allow views to print values in ViewBuilders
import SwiftUI
/**
* An @ViewBuilder will only allow statements that result in a View.
* `print(value)` does not result in a view and is not allowed in a @ViewBuilder such as `var body: some View`.
* This view extension allows you print inside a @ViewBuilder.
*
* Usage:
* ```
* struct MyView: View {
* var body: some View {
@berikv
berikv / coverage.sh
Last active November 23, 2021 17:20
Coverage generator for Swift Package based projects
#! sh
# Install:
# - Place this file next to the Package.swift in your project
# - Open a terminal and cd to the project directory
# - Run: brew install lcov
# - Run: chmod +x coverage.sh
#
# Usage:
# Run: ./coverage.sh
@berikv
berikv / Retry.swift
Created November 19, 2021 14:53
retry() code block in Swift
/// Retry a block of code until it succeeds, maximum n times
///
/// Usage:
/// ```
/// var failTimes = 3
/// try retry(5) {
/// if failTimes > 0 {
/// failTimes -= 1
/// throw MyError()
/// }
@berikv
berikv / SwiftUIBindings.swift
Created November 10, 2021 13:50
SwiftUI Bindings playground
// Drop this code in an xcode playground for iOS
// Open the canvas to see the view rendered
// Cmd+Enter to Run
import PlaygroundSupport
import SwiftUI
// Wrap your application state in observable objects
// Adhering to ObservableObject is needed for @ObservedObject, @StateObject and @EnvironmentObject
final class Clock: ObservableObject {
@berikv
berikv / metatype.swift
Created October 16, 2021 10:23
Static member cannot be used on protocol metatype
protocol P {}
struct S: P {}
extension P {
static var a: P { S() }
}
let v = P.a
// error: static member 'a' cannot be used on protocol metatype 'P.Protocol'
// let v = P.a
@berikv
berikv / MySQL_5-7_macOS.md
Last active April 21, 2021 12:44 — forked from robhrt7/MySQL_5-7_macOS.md
Install MySQL 5.7 on macOS using Homebrew

This is a fork of original gist https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e, with slight changes on pointing to 5.7 version branch, instead of 8 (latest default of MySQL in Hombrew).

Install MySQL 5.7 on macOS

This procedure explains how to install MySQL using Homebrew on macOS (Sierra 10.12 and up)

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.
@berikv
berikv / raspberry_headless_setup.md
Created July 25, 2019 08:01
Raspberry pi ssh headless setup
@berikv
berikv / install_relative_commit
Created July 12, 2019 10:10
Installs HEAD^ as the default relative commit for arc
#!/bin/bash
#
# See: https://medium.com/@kurtisnusbaum/stacked-diffs-keeping-phabricator-diffs-small-d9964f4dcfa6
REPOSITORY_DIR=~/Work
for dir in "$REPOSITORY_DIR"/*/.git/arc/
do
echo "HEAD^" > "$dir/default-relative-commit"
done
@berikv
berikv / tictactoe.swift
Last active November 11, 2022 16:16
A TicTacToe game written with SwiftUI, works in Xcode 11.0 beta Playground
import PlaygroundSupport
import SwiftUI
// MARK: - Game
extension TicTacToe.Board {
var hasNonEmptyCells: Bool {
self.flatMap { $0 }
.contains(where: { $0 != .empty })
}