Skip to content

Instantly share code, notes, and snippets.

View toineheuvelmans's full-sized avatar

Toine Heuvelmans toineheuvelmans

View GitHub Profile
@toineheuvelmans
toineheuvelmans / git-safeguard.sh
Created June 25, 2020 08:10
Check local repo changes before proceeding with other commands
#!/bin/bash
# Exits with error if there are uncommitted changes.
# This can be used as follows:
# $ ./git-safeguard.sh && <other commands>
# to only execute the other commands if there are no changes.
if [[ $(git status -s) ]]; then
echo "There are uncommitted changes:"
git status -s
exit 1
fi
@toineheuvelmans
toineheuvelmans / pure_swift_optional_protocol_func.swift
Last active February 13, 2017 13:29
Optional protocol functions in Swift (without @objc).
protocol MyFancyProtocol {
func requiredFunction() -> String
func optionalFunction() -> String
}
extension MyFancyProtocol {
func optionalFunction() -> String {
return "Default implementation of optionalFunction"
}
func nonProtocolFunction() -> String {
// (Swift 3)
// Given a number of functions that all have the signature () -> T?
// I want to try each of them, until I have a result (i.e. a non-optional).
// For instance:
let f1: () -> Int? = { _ in nil }
let f2: () -> Int? = { _ in nil }
let f3: () -> Int? = { _ in 2 }
let f4: () -> Int? = { _ in 3 }
// You could of course do the following:
#!/usr/bin/env ruby
# Toine Heuvelmans, November 2016
# A small script that helps you removing Xcode-related data.
# This can potentially save many Gigabytes.
# Just run `ruby xcode_cleanup.rb`.
require 'fileutils'
require 'date'
require 'rubygems'