Skip to content

Instantly share code, notes, and snippets.

View Galeas's full-sized avatar
🇺🇦
#standwithukraine

Evgeniy Branitsky Galeas

🇺🇦
#standwithukraine
View GitHub Profile
@Galeas
Galeas / DispatchOnce.swift
Created October 15, 2020 17:18
Swift 3+ GCD's dispatch_once
extension DispatchQueue {
private static var _onceTracker = [String]()
func once(file: String = #file, function: String = #function, line: Int = #line, _ block:() -> Void) {
let token = file + ":" + function + ":" + String(line)
once(token: token, block)
}
/// Executes a block of code, associated with a unique token, only once. The code is thread safe and will
/// only execute the code once even in the presence of multithreaded calls.
@Galeas
Galeas / joke
Created December 13, 2021 09:37
English: A dog.
Swedish: What?
English: The dog.
English: Two dogs.
Swedish: Okay. We have: En hund, hunden, Två hundar, hundarna.
@Galeas
Galeas / git_cleanup.sh
Created May 26, 2025 16:19
The script checks for remote-less local branches and prunes it
#!/bin/zsh
# Git branch cleanup script - removes local branches whose remotes were deleted
# Usage: ./git_cleanup.sh [path-to-git-repo]
set -e
# Handle path parameter
if [ $# -gt 1 ]; then
echo "Usage: $0 [path-to-git-repo]"
# -----------------------------------------
# Create permanent environment variable
#
# $1 - variable name
# $2 - variable definition
# @requires: '~/.zshrc' or '~/.bashrc'
# -----------------------------------------
function new_env_var {
local detected_shell="$(ps -o comm= -p $$)"
local rcfile=$(echo "${HOME}/.${detected_shell//-/}rc")
@Galeas
Galeas / DiffableDatasource.swift
Last active December 9, 2025 16:49
Generic, boilerplate-reducing base classes for UIKit Diffable Data Sources
import UIKit
public protocol DiffableDatasource: AnyObject {
typealias Snapshot = NSDiffableDataSourceSnapshot<Section, Item>
typealias SnapshotProvider = () -> Snapshot
associatedtype View
associatedtype Datasource
associatedtype Section: Hashable & Sendable
associatedtype Item: Hashable & Sendable