Skip to content

Instantly share code, notes, and snippets.

View CollectiveHealth-gists's full-sized avatar

CollectiveHealth-gists

View GitHub Profile
@CollectiveHealth-gists
CollectiveHealth-gists / rxSwiftTask.swift
Created August 8, 2017 18:50
RxSwift Download Image from Url
URLSession.shared.rx
.response(imageURL)
// subscribe on main thread
.subscribeOn(MainScheduler.sharedInstance)
.subscribe(onNext: { [weak self] data in
// Update Image
self?.imageView.image = UIImage(data: data)
}, onError: {
// Log error
}, onCompleted: {
@CollectiveHealth-gists
CollectiveHealth-gists / task.swift
Created August 8, 2017 18:48
Swift Download Image from Url
// create task to download image from url
let task = session.dataTask(with: imageURL) {(imageData, response, error) in
// check for image data
if let data = imageData {
// update UI on main thread
DispatchQueue.main.async {
self.imageView.image = UIImage(data: data)
// animate image alpha
UIView.animateWithDuration(0.3) {
self.imageView.alpha = 1
@CollectiveHealth-gists
CollectiveHealth-gists / AWS_Lambda_and_Apex_ListUsers-index.js
Created July 10, 2017 23:51
Development and Deployment of AWS Lambda Functions: A function to list users in the infrastructure
var assert = require('assert');
exports.handler = function(event, context) {
// Log the context, it contains details about the function's execution
console.log("Context: %j", context);
// Log the event, it contains data and parameters passed to the function
console.log("Event: %j",event);
try {
// Simple example to show that the assert library was successfully included
@CollectiveHealth-gists
CollectiveHealth-gists / AWS_Lambda_and_Apex_package.json
Created July 10, 2017 23:49
Development and Deployment of AWS Lambda Functions: package.json
{
"name": "my-api",
"version": "1.0.0",
"dependencies": {
"assert": "1.3.0"
},
"devDependencies": {
"browserify": "13.0.0"
}
}
@CollectiveHealth-gists
CollectiveHealth-gists / AWS_Lambda_and_Apex_project.json
Created July 10, 2017 23:48
Development and Deployment of AWS Lambda Functions:
{
"name": "my-api",
"description": "API Lambda Functions",
"role": "arn:aws:iam::123456789023:role/lambda-api",
"runtime": "nodejs",
"handler": "main.handler",
"hooks": {
"build": "npm install && ../../node_modules/.bin/browserify --node -s default --exclude aws-sdk -o main.js index.js",
"clean": "rm -f main.js"
}
@CollectiveHealth-gists
CollectiveHealth-gists / testingiOS_check-element-exists.swift
Created July 10, 2017 23:40
Testing iOS at Collective Health: Checking if an element exists
func assertExists(element: XCUIElement, timeout: NSTimeInterval = 10) {
expectationForPredicate(NSPredicate(format: "exists == 1"),
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(timeout, handler: nil)
}
@CollectiveHealth-gists
CollectiveHealth-gists / testingiOS_ui-test.swift
Created July 10, 2017 23:39
Testing iOS at Collective Health: A UI Test
func launchApp() {
app.launch()
// We have stubbed out the login flow to always succeed,
// so the password doesn't matter
app.secureTextFields["password_text_field"].typeText("nonsense password\n")
app.tabBars.buttons["get care tab button"].tap()
}
func testCurrentLocationPreSelected() {
@CollectiveHealth-gists
CollectiveHealth-gists / testingiOS_network-stub-code.swift
Created July 10, 2017 23:32
Testing iOS at Collective Health: Our network stub code
func setupSearchResults() {
let testBlock: OHHTTPStubsTestBlock
testBlock = { $0.URL?.path == "/api/v1/getcare/*" }
let fixture = OHPathForFile("GetCareResponse.json", self.dynamicType)!
successResponseBlock = { _ in
return OHHTTPStubsResponse(
fileAtPath: fixture,
statusCode: 200,
headers: ["Content-Type":"application/json"]
@CollectiveHealth-gists
CollectiveHealth-gists / testingiOS_handling-launch-argument.swift
Created July 10, 2017 23:31
Testing iOS at Collective Health: Handling the launch argument
// This method is called from
// `application(didFinishLaunchingWithOptions:)`
private func handleLaunchArguments() {
var arguments = NSProcessInfo.processInfo().arguments
// The first argument is the path of the executable
arguments.removeFirst()
for argument in arguments {
switch argument {
case LaunchArguments.NoAnimations:
@CollectiveHealth-gists
CollectiveHealth-gists / testingiOS_keys-launch-arguments.swift
Created July 10, 2017 23:31
Testing iOS at Collective Health: Passing the keys as launch arguments
var app: XCUIApplication!
override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launchArguments = [
LaunchArguments.ResetDefaults,