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 / 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 / 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_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 / 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 / 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 / typeaheadFiltering.swift
Created August 8, 2017 18:51
Get Care MKLocalSearchCompletion
func filterSearchLocation(completer: MKLocalSearchCompleter)
throws -> Observable<[MKLocalSearchCompletion]> {
// Filter results by titles that contain "United States" keywors
let filteredResults = completer
.results
.filter { $0.title.contains("United States") }
// Throw Location not found error
guard filteredResults.isEmpty else { throw "Location not found"}
// convert an filtered results into an Observable
@CollectiveHealth-gists
CollectiveHealth-gists / MKLocalSearchCompleter.swift
Created August 8, 2017 18:52
MKLocalSearchCompleter Initialize
// Initialize MKLocalSearchCompleter
let requestCompleter = MKLocalSearchCompleter()
// OnDidCompleteRequestProxy
requestCompleter.rx_completerDidUpdateResults
.flatMap(filterSearchLocation) // filter search locations
.subscribe(onNext: { [weak self] (results) in
// Method to handle search completer success
self?.updateLocations(results)
}, onError: { [weak self] error in
@CollectiveHealth-gists
CollectiveHealth-gists / lambda_config.ini
Last active September 7, 2017 18:20
Stock configuration file used with serverless endpoint
[creds]
user = consumer-account
passwd = auth_token_password
[endpoints]
prod_domain = https://prod.endpoint-mgmt.tld/web/api/v1.6
dev_domain = https://dev.endpoint-mgmt.tld/web/api/v1.6
[slack_dev]
webhook = https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXX
@CollectiveHealth-gists
CollectiveHealth-gists / endpoint_ops.py
Created September 7, 2017 18:23
Example Lambda runbook
#!/usr/bin/env python
""" Example Lambda function for Security ChatOPs"""
__author__ = 'Jacolon Walker'
__email__ = '[email protected]'
from urlparse import parse_qs
from ConfigParser import SafeConfigParser
import logging
from sentinel_core import AUTH, count_agents, fetch_agent_logs, login, threats_summary, blacklist_hash
import requests
@CollectiveHealth-gists
CollectiveHealth-gists / proxied_lambda_request
Created September 7, 2017 18:25
Example Lambda proxied request data
{
u 'body': u 'token=SLASH_CMD_TOKEN&team_id=T1PASUPJL&team_domain=my_slack_domain&channel_id=C3GQWN08L&channel_name=integration_dev&user_id=U3GMSMREW&user_name=jdev&command=%2Fs1&text=health&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FXXXXXXXXX%2FXXXXXXXXXXXX%2FXXXXXXXXXXXXXXX', u 'resource': u '/slack/cmds/s1', u 'requestContext': {
u 'resourceId': u '7y5pmu',
u 'apiId': u 'REDACTED',
u 'resourcePath': u '/slack/cmds/s1',
u 'httpMethod': u 'POST',
u 'requestId': u '08b60825-d7ad-11e6-8e0c-2d47855f377e',
u 'accountId': u 'REDACTED',
u 'identity': {
u 'apiKey': REDACTED,