Skip to content

Instantly share code, notes, and snippets.

View ralfebert's full-sized avatar

Ralf Ebert ralfebert

View GitHub Profile
@ralfebert
ralfebert / xcode_set_development_language_de.rb
Last active May 16, 2023 07:07
Ruby script that uses cocoapods Xcodeproj to set development_region / known_regions of an Xcode project to German
#!/usr/bin/env ruby
require 'fileutils'
require 'xcodeproj'
unless ARGV.count == 2
puts "Usage: xcode_set_development_region.rb [project] [region]"
exit(1)
end
@ralfebert
ralfebert / generate_storyboard_constants.rb
Last active May 29, 2019 21:31
Generate Swift constants for Xcode storyboards containing cell reuse identifiers, segue identifiers and storyboard identifier. More information: https://www.ralfebert.de/storyboard-constants/
#!/usr/bin/env ruby
require 'nokogiri'
def show_usage(msg = nil)
puts "#{msg}\n\n" if msg
puts "Usage:\n\t#{$PROGRAM_NAME} [storyboard_file]"
exit(0)
end
@ralfebert
ralfebert / CompareImages.swift
Last active June 28, 2023 03:11 — forked from SheffieldKevin/compareimages.swift
A couple of swift functions for comparing two CGImage using CIImage in OS X
import CoreGraphics
import CoreImage
func imageMetadataString(image: CGImage) -> String {
return "\(image.width)x\(image.height) bitsPerComponent:\(image.bitsPerComponent) bytesPerRow:\(image.bytesPerRow) bitsPerPixel:\(image.bitsPerPixel)"
}
/**
@brief Returns the maximum difference of pixel values in the image.
@discussion Assumes doImagesHaveSameMeta has already returned true on
@ralfebert
ralfebert / slice.py
Last active April 12, 2021 08:29
Export images from Sketch to xcasset (by @ryangomba)
#!/usr/bin/env python
import os
import sys
import subprocess
import shutil
import json
import re
import time
from distutils.spawn import find_executable
@ralfebert
ralfebert / ArrayWith.swift
Last active April 6, 2020 09:23
List of random numbers with a given sum
func arrayWith(count: Int, sum : Int) -> [Int] {
assert(count >= 1)
var result = [sum]
while result.count < count {
let randomIndex = result.indices.randomElement()!
let v = Int.random(in: 0...result[randomIndex])
result[randomIndex] -= v
result.append(v)
}
return result
@ralfebert
ralfebert / create
Last active December 11, 2020 13:13
Create and open a file from the shell using simple templates
#!/usr/bin/env ruby
# Create and open a file from the shell using simple templates
# https://gist.github.com/ralfebert/cdc30dbc9d2c2356d8f9b6b7c1492888/edit
require 'date'
require 'shellwords'
require 'ostruct'
require 'optionparser'
import SwiftUI
class DemoModel : ObservableObject {
enum State {
case value(Date)
}
@Published var counter = 0
@Published var state = State.value(Date())

Components

See also

import CoreHaptics
import SwiftUI
enum FeedbackType {
case selection, success, error
}
class Haptics {
@AppStorage("HaptikFeedbackEnabled") var haptikFeedbackEnabled = true
extension Comparable {
mutating func clamp(_ limits: ClosedRange<Self>) {
self = min(max(self, limits.lowerBound), limits.upperBound)
}
mutating func clamp(_ limits: PartialRangeFrom<Self>) {
self = max(self, limits.lowerBound)
}
mutating func clamp(_ limits: PartialRangeThrough<Self>) {
self = min(self, limits.upperBound)
}