Skip to content

Instantly share code, notes, and snippets.

View StanislavK's full-sized avatar
🚜
Working

StanislavK StanislavK

🚜
Working
View GitHub Profile
@StanislavK
StanislavK / TestFile.java
Created February 10, 2011 13:31
This is a test.
package com.dropbox.android.sample;
import android.os.AsyncTask;
import android.util.Log;
import com.dropbox.client.DropboxAPI;
public class LoginAsyncTask extends AsyncTask<Void, Void, Integer> {
private static final String TAG = "LoginAsyncTask";
//String extension that checks for an empty (after trimming whitespace) or nil string:
//
// Usage: var isEmpty = String.isNilOrEmpty(myString)
//
// Credit to: Kevin McNeish
// http://iosappsfornonprogrammers.com/forum/index.php?topic=1836.0
extension String {
public static func isNilOrEmpty(string: String?) -> Bool {
extension Double {
var second: NSTimeInterval { return self }
var seconds: NSTimeInterval { return self }
var minute: NSTimeInterval { return self * 60 }
var minutes: NSTimeInterval { return self * 60 }
var hour: NSTimeInterval { return self * 3600 }
var hours: NSTimeInterval { return self * 3600 }
}
extension Array {
func combine(separator: String) -> String{
var str : String = ""
for (idx, item) in enumerate(self) {
str += "\(item)"
if idx < self.count-1 {
str += separator
}
}
return str
func log(message: String) {
let thread = Thread.current.isMainThread ? "Main" : "Background"
print("\(thread) thread: \(message)")
}
import Foundation
extension String {
var isValidEmail: Bool {
let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPredicate = NSPredicate(format:"SELF MATCHES %@", emailFormat)
return emailPredicate.evaluate(with: self)
}
}
import Foundation
import UIKit
class Alert {
class func showBasic(title: String, message: String, vc: UIViewController) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
vc.present(alert, animated: true)
}
import Foundation
class TaskManager {
static let shared = TaskManager()
let session = URLSession(configuration: .default)
typealias completionHandler = (Data?, URLResponse?, Error?) -> Void
var tasks = [URL: [completionHandler]]()
class CustomTextFieldWithPadding: UITextField {
let padding: CGFloat = 16
private var paddingEdgeInsets: UIEdgeInsets {
return UIEdgeInsetsMake(0, padding, 0, padding)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
import UIKit
import SystemConfiguration.CaptiveNetwork
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("SSID: \(currentID(for: kCNNetworkInfoKeySSID))\nBSSID: \(currentID(for: kCNNetworkInfoKeyBSSID))")
}