Skip to content

Instantly share code, notes, and snippets.

View Wooder's full-sized avatar

Jochen Holzer Wooder

  • Karlsruhe, Germany
View GitHub Profile
extension TimeInterval {
func asHoursMinutesSeconds () -> (Int, Int, Int) {
let interval = Int(self)
return ( interval / 3600, interval % 3600 / 60, (interval % 3600) % 60)
}
/// Creates a string with hours, minutes, seconds,
/// divided by the given separator.
import UIKit
extension UIApplication {
static var applicationName: String {
let mainBundle = NSBundle.mainBundle()
let key = String(kCFBundleNameKey)
let value = mainBundle.objectForInfoDictionaryKey(key) as? String
return value ?? ""
}
@Wooder
Wooder / load_gravatar_image.sh
Created February 21, 2017 10:04
Loads a gravatar image by email address. e.G.: ./load_gravatar_image.sh test@email.com
MD5_HASH=`md5 -s "$1" | awk -F"=" '{print $2}' | xargs`
wget -O $1.jpg https://www.gravatar.com/avatar/$MD5_HASH
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l
@Wooder
Wooder / cocoapods-installation-update-commands
Created April 19, 2017 12:07
some helpful commands for cocoapods installation
#avoid problems with standard installation directory
sudo gem update cocoapods -n /usr/local/bin
#install certain version of cocoapods
sudo gem install cocoapods -v 1.2.0
private func urlEncodeString(_ string: String) -> String {
#if swift(>=3.0)
let allowedCharacterSet = (CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[] ").inverted)
if let escapedString = string.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) {
return escapedString
}
#else
let allowedCharacterSet = (NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[] ").invertedSet)
if let escapedString = string.stringByAddingPercentEncodingWithAllowedCharacters(allowedCharacterSet) {
return escapedString
@Wooder
Wooder / IsDebuggerAttached.swift
Created November 21, 2017 15:32
Swift Code that check if the debugger is attached to your iOS Device (App runs in XCode) while running your app
#if DEV
fileprivate func isDebuggerAttached() -> Bool {
var info = kinfo_proc()
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
return (info.kp_proc.p_flag & P_TRACED) != 0
}
#endif
### which shell is used?
echo $SHELL
echo $0
@Wooder
Wooder / swiftlint_commandsmd
Last active August 29, 2018 12:03
swiftlint command to autocorrect a single file
#autocorrect a single file
SCRIPT_INPUT_FILE_COUNT=1 SCRIPT_INPUT_FILE_0="Class.swift" swiftlint autocorrect --use-script-input-files
#show only swiftlint warnings
swiftlint 2>&1 | grep -i warning
Date in current timezone as string:
let longDateString = Date().description(with: .current)
let shortDateString DateFormatter.localizedString(from: expiryDate, dateStyle: .medium, timeStyle: .short)