Skip to content

Instantly share code, notes, and snippets.

@fxm90
fxm90 / CustomNotificationCenterTestCase.swift
Created August 6, 2018 12:57
XCTest - Use custom notification center in test case and assert notification (not) triggered.
class CustomNotificationCenterTestCase: XCTestCase {
var notificationCenter: NotificationCenter!
override func setUp() {
super.setUp()
notificationCenter = NotificationCenter()
}
@fxm90
fxm90 / NotificationTestCase.swift
Last active April 8, 2020 12:58
XCTest - Assert notification (not) triggered.
import XCTest
class NotificationTestCase: XCTestCase {
func testTriggerNotification() {
expectation(forNotification: .fooBar,
object: nil,
handler: nil)
let notificationCenter = NotificationCenter.default
@fxm90
fxm90 / WebViewExampleViewController.swift
Last active June 17, 2023 01:18
Show progress of WKWebView in UIProgressBar that is attached to an UINavigationBar
//
// WebViewExampleViewController.swift
//
// Created by Felix Mau on 06.01.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
import WebKit
@fxm90
fxm90 / swiftlint.sh
Last active September 1, 2019 10:19
Check "SwiftLint" installed via CocoaPods. Add a new "Run Script Phase" with this gist.
SWIFTLINT="${PODS_ROOT}/SwiftLint/swiftlint"
if [ ! -f "$SWIFTLINT" ]; then
echo "warning: SwiftLint not installed!"
exit 1
fi
$SWIFTLINT
@fxm90
fxm90 / NotificationCenter+ObserveOnce.swift
Last active December 5, 2022 15:15
Extension for "NotificationCenter" to observe a notification just once and directly unsubscribe.
//
// NotificationCenter+ObserveOnce.swift
//
// Created by Felix Mau on 18.10.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import UIKit
extension NotificationCenter {
@fxm90
fxm90 / isNumeric.php
Last active April 28, 2018 08:58
Checks whether all given parameters are numeric (Same as php-vanilla "is_numeric" but as variadic function).
// Checks whether all given parameters are numeric.
// Usage: $validCoordinates = isNumeric($_GET['p1Lat'], $_GET['p1Lon']));
function isNumeric() {
$numberOfArguments = func_num_args();
$arguments = func_get_args();
return count(array_filter($arguments, 'is_numeric')) === $numberOfArguments;
}
@fxm90
fxm90 / randomHelpers.php
Created August 31, 2017 07:29
PHP - Random helper functions
// Returns a random float value between "$min" and "$max".
// Usage: $latitude = randomFloat(53.394655, 53.694865)
function randomFloat($min, $max) {
return $min + lcg_value() * abs($max - $min);
}
// Returns a random argument, passed to this function.
// Usage: $fruit = randomArgument('Apple', 'Banana', 'Strawberry');
function randomArgument() {
$numberOfArguments = func_num_args();
@fxm90
fxm90 / isset.swift
Last active April 23, 2017 11:35
Equivalent of php "isset()" in swift 3.0
func isset(_ args: Any?...) -> Bool {
return !args.contains { $0 == nil }
}
@fxm90
fxm90 / Deferred.js
Created February 28, 2017 14:27
Create a angular like deferred object with plain javascript (ES6)
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.reject = reject;
this.resolve = resolve;
});
}
resolve(value) {
this.resolve(value);
@fxm90
fxm90 / UIColor+Initializers.swift
Last active August 11, 2020 08:45
Create UIColor from RGB, RGBA, Hex or Hex-String ("#ffffff")
public extension UIColor {
/// Create color from RGB(A)
///
/// Parameters:
/// - absoluteRed: Red value (between 0 - 255)
/// - green: Green value (between 0 - 255)
/// - blue: Blue value (between 0 - 255)
/// - alpha: Blue value (between 0 - 255)
///