Skip to content

Instantly share code, notes, and snippets.

Felix M. fxm90

Block or report user

Report or block fxm90

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fxm90
fxm90 / Array+PlusAssignment.swift
Last active Aug 17, 2017
Append one value of same type to array.
View Array+PlusAssignment.swift
func += <T>(left: inout [T], right: T) {
left.append(right)
}
@fxm90
fxm90 / Dictionary+PlusAssignment.swift
Last active Aug 19, 2017
Combine two dictionaries of same type with custom operator.
View Dictionary+PlusAssignment.swift
func += <Key, Value> (left: inout [Key: Value], right: [Key: Value]) {
for (key, value) in right {
left.updateValue(value, forKey: key)
}
}
@fxm90
fxm90 / UIColor+Initializers.swift
Last active Mar 28, 2018
Create UIColor from RGB, RGBA, Hex or Hex-String ("#ffffff")
View UIColor+Initializers.swift
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)
///
@fxm90
fxm90 / GradientLoadingBar+HandlePromises.swift
Last active Dec 27, 2017
Use GradientLoadingBar with PromiseKit.
View GradientLoadingBar+HandlePromises.swift
import PromiseKit
import GradientLoadingBar
extension GradientLoadingBar {
func handle(promise: Promise<Void>) -> Promise<Void> {
return handle(promiseList: [promise])
}
func handle(promiseList: [Promise<Void>]) -> Promise<Void> {
@fxm90
fxm90 / Deferred.js
Created Feb 28, 2017
Create a angular like deferred object with plain javascript (ES6)
View Deferred.js
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.reject = reject;
this.resolve = resolve;
});
}
resolve(value) {
this.resolve(value);
@fxm90
fxm90 / isset.swift
Last active Apr 23, 2017
Equivalent of php "isset()" in swift 3.0
View isset.swift
func isset(_ args: Any?...) -> Bool {
return !args.contains { $0 == nil }
}
@fxm90
fxm90 / randomHelpers.php
Created Aug 31, 2017
PHP - Random helper functions
View randomHelpers.php
// 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 / isNumeric.php
Last active Apr 28, 2018
Checks whether all given parameters are numeric (Same as php-vanilla "is_numeric" but as variadic function).
View isNumeric.php
// 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 / NotificationCenter+ObserveOnce.swift
Last active Dec 27, 2017
Extension for "NotificationCenter" to observe a notification just once and directly unsubscribe.
View NotificationCenter+ObserveOnce.swift
extension NotificationCenter {
/// Adds an observer to the given notification center, which fires just once.
///
/// Note:
/// - Same parameters as "addObserver", but with default properties
/// See http://apple.co/2zZIYJB for details.
///
/// Parameters:
/// - name: The name of the notification for which to register the observer
@fxm90
fxm90 / swiftlint.sh
Created Sep 30, 2017
Check "SwiftLint" installed via CocoaPods. Add a new "Run Script Phase" with this gist.
View swiftlint.sh
if [ -f "${PODS_ROOT}/SwiftLint/swiftlint" ]; then
${PODS_ROOT}/SwiftLint/swiftlint
else
echo "warning: SwiftLint not installed!"
fi
You can’t perform that action at this time.