Skip to content

Instantly share code, notes, and snippets.

View illescasDaniel's full-sized avatar
💻
Learning something new

Daniel Illescas Romero illescasDaniel

💻
Learning something new
View GitHub Profile
package loginapp.app
import loginapp.views.LoginScreen
import tornadofx.App
class LoginApp : App(LoginScreen::class)
//
// UIAlertController+Action.swift
//
import UIKit
/**
Extension to `UIAlertController` to allow direct adding of `UIAlertAction` instances
*/
extension UIAlertController {
@DaveWoodCom
DaveWoodCom / String+Email.swift
Last active February 28, 2021 16:45
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
extension String {
func isValidEmail() -> Bool {
guard !self.lowercaseString.hasPrefix("mailto:") else { return false }
guard let emailDetector = try? NSDataDetector(types: NSTextCheckingType.Link.rawValue) else { return false }
let matches = emailDetector.matchesInString(self, options: NSMatchingOptions.Anchored, range: NSRange(location: 0, length: self.characters.count))
guard matches.count == 1 else { return false }
return matches[0].URL?.scheme == "mailto"
}
}
@ppamorim
ppamorim / ImageInsets.swift
Created November 5, 2015 16:30
Add padding/margin at a image!
import UIKit
extension UIImage {
func imageWithInsets(insetDimen: CGFloat) -> UIImage {
return imageWithInset(UIEdgeInsets(top: insetDimen, left: insetDimen, bottom: insetDimen, right: insetDimen))
}
func imageWithInset(insets: UIEdgeInsets) -> UIImage {
UIGraphicsBeginImageContextWithOptions(
CGSizeMake(self.size.width + insets.left + insets.right,
@taketwo
taketwo / has_method_def.h
Created September 14, 2015 20:50
A c++11 metafunction to check if a class has a method
// Create a metafunction "has_xxx_method" that can be used
// to check if a class has a method called "xxx". Note the
// limitation: only existence of parameterless methods can
// be checked this way.
// Credits: http://stackoverflow.com/a/21827727/1525865
#define HAS_METHOD_DEF(xxx) \
template<typename T> \
constexpr auto has_ ## xxx ## _method(int) \
-> decltype(std::declval<T>(). xxx (), bool()) \
{ return true; } \
@benvium
benvium / MyTabBar.m
Created March 5, 2015 11:22
UITabBarController slide animation. Slide left and right when tabs are selected. Based on code from StackOverflow (linked in code)
- (BOOL) tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
// http://stackoverflow.com/questions/5161730/iphone-how-to-switch-tabs-with-an-animation
NSUInteger controllerIndex = [self.viewControllers indexOfObject:viewController];
if (controllerIndex == tabBarController.selectedIndex) {
return NO;
}
@sekati
sekati / xcode-build-bump.sh
Created July 24, 2012 20:44
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)