Skip to content

Instantly share code, notes, and snippets.

View catalinaturlea's full-sized avatar

Catalina Turlea catalinaturlea

View GitHub Profile
@catalinaturlea
catalinaturlea / LoginTests.swift
Created September 25, 2019 19:20
Tests-version2
// You implememt a Mock which conforms to the same protocol the ViewController is connected to
class UserServiceMock: UserServiceInterface {
var resultToReturn: Bool = false
var errorToReturn: Error?
func login(email: String, password: String, completion: (Bool, Error?)) {
completion(resultToReturn, errorToReturn)
}
}
class ViewController: UIViewController {
var userService: UserServiceInterface = UserService.shared
func login(email: String, password: String, completion: ((Bool) -> Void)) {
// ....
userService.login(email, password, completion: { (success, error) in
if success {
completion(true)
@catalinaturlea
catalinaturlea / LoginTests.swift
Created September 25, 2019 19:09
LoginTests-version1
class LoginTests: XCTestCase {
let viewControllerToTest = ViewController()
func testLogin() {
// Since this is an async call we need to wait for the callback in the test - otherwise we will not run long enought to get the response
let loginExpectation = expectation(description: "should call login")
viewController.login("testEmail", "testPassword", completion: { success in
loginExpectation.fulfill()
@catalinaturlea
catalinaturlea / UserService.swift
Created September 25, 2019 19:04
UserService-version1
class UserService {
static var loginURL = "https://my.app.com/login"
static var shared = UserService()
func login(email: String, password: String, completion: (Bool, Error?)) {
let params = ["email": email, "password": password]
Alamofire.shared.request(loginURL, method: .POST, parameters: params, encoding: .URLEncoding).responseJSON { (response) in
switch respose.status {
@catalinaturlea
catalinaturlea / ViewController.swift
Created September 25, 2019 18:56
ViewController-version1
class ViewController: UIViewController {
// ....
@IBAction func loginButtonPressed() {
login(emailTextField.text ?? "", passwordTextField.text ?? "", completion: { success in
if !success {
showLoginError()
return
}
@catalinaturlea
catalinaturlea / gist:cd1722c2d98dca5f92d57a3a7f0dc9b0
Last active April 17, 2025 18:30
Adding a WKWebView programmatically - together with the constraints
private weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// This is needed when using an iOS target < iOS 11.0 - there was a storyboard bug which does not allow instantiating WKWebView from the Storyboard or Xib file
let webView = WKWebView()
self.webView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(webView)
@catalinaturlea
catalinaturlea / youtrack.py
Last active June 14, 2018 09:38
WebSlides Youtrack Generations
import sys
from youtrack.connection import Connection as YouTrack
#// authentication request with permanent token
#yt = YouTrack('https://instance_name.myjetbrains.com/youtrack/', token='perm:abcdefghijklmn')
#// versus authentication with username and password
yt = YouTrack('https://everskill.myjetbrains.com/youtrack/', login='add_yours_here', password='add_yours_here')
def print_issues(project, issues, type):
@catalinaturlea
catalinaturlea / youtrack-flow.py
Created June 12, 2018 15:04
youtrack-reporting-flow
import sys
from youtrack.connection import Connection as YouTrack
#// authentication request with permanent token
#yt = YouTrack('https://instance_name.myjetbrains.com/youtrack/', token='perm:abcdefghijklmn')
#// versus authentication with username and password
yt = YouTrack('https://everskill.myjetbrains.com/youtrack/', login='username', password='password')
def print_issues(project, issues, type):
@catalinaturlea
catalinaturlea / MyTest.swift
Last active June 30, 2016 14:05
Unnecessary code clean up
class MyTest: NSObject {
private var identifier = "myIdentifier"
var defaultContent: [String]
init(withItem item: String) {
defaultContent = [item]
}
class func fetchInfo(success: (info: [AnyObject: AnyObject]?) -> (), failure: ((error: NSError?) -> ())? ) {
@catalinaturlea
catalinaturlea / MyTest.swift
Last active June 30, 2016 14:06
Unnecessary code
class MyTest: NSObject {
private var identifier: String = "myIdentifier"
var defaultContent: [String]
init(withItem item: String) {
self.defaultContent = [item]
}
class func fetchInfo(success: (info: [AnyObject: AnyObject]) -> (), failure: ((error: NSError?) -> ())? ) {