Skip to content

Instantly share code, notes, and snippets.

View siberianisaev's full-sized avatar

Andrey Isaev siberianisaev

View GitHub Profile
@siberianisaev
siberianisaev / gist:495a7c062c03e45abf75503c6bb3e07d
Created November 13, 2020 15:33
Count of lines in project (include UI)
find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift -o -iname \*.storyboard -o -iname \*.xib \) -print0 | xargs -0 wc -l
@siberianisaev
siberianisaev / NativeWebView.swift
Created April 22, 2020 13:41 — forked from maxcampolo/NativeWebView.swift
WKWebView setup to make a web page adopt native behavior.
import WebKit
class NativeWebViewController: UIViewController {
let viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);"
let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';"
let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';"
override func viewDidLoad() {
// 1 - Make user scripts for injection
@siberianisaev
siberianisaev / html-table.swift
Last active January 14, 2016 08:21
Replace HTML table with spaces and new lines
extension UIFont {
func sizeOfString(string: NSString, constrainedToWidth width: Double) -> CGSize {
return string.boundingRectWithSize(CGSize(width: width, height: DBL_MAX), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: self], context: nil).size
}
}
extension String {
@siberianisaev
siberianisaev / NSString+Email.swift
Created December 22, 2014 12:15
Email address validation (swift version)
import Foundation
extension NSString {
/**
http://stackoverflow.com/questions/800123/what-are-best-practices-for-validating-email-addresses-in-objective-c-for-ios-2
RFC 2822 http://tools.ietf.org/html/rfc2822
*/
func isEmail() -> Bool {
let sRegex = "(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
@siberianisaev
siberianisaev / UINavigationBar+Height.swift
Last active October 30, 2019 07:57
Change height of UINavigationBar
import Foundation
private var AssociatedObjectHandle: UInt8 = 0
extension UINavigationBar {
var height: CGFloat {
get {
if let h = objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat {
@siberianisaev
siberianisaev / ExceptionHandler.h
Last active August 29, 2015 14:01
Exception Handler
#import <Foundation/Foundation.h>
@interface ExceptionHandler : NSObject
+ (void)startHandleExceptions;
@end
#import <Foundation/Foundation.h>
@interface NSString (URLEncoding)
- (NSString *)urlEncodedString;
- (NSString *)stringByDecodingURLFormat;
@end
@siberianisaev
siberianisaev / singleton
Created February 13, 2014 06:50
Singleton snippet for Xcode 5
+ (<#Class name#> *)<#Singleton method#>
{
static <#Class name#> *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[<#Class name#> alloc] init];
});
return sharedInstance;
}