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 / IntegrationWithSoundSystemTest.java
Created June 1, 2018 18:13
Testing with real instance of SoundSystem, but mocked out DisplaySystem.
public class IntegrationWithSoundSystemTest {
@Test
public void testSoundSystem() {
Injector injector = Guice.createInjector(new ComputerTestModule()
.withInstance(SoundSystem.class, new SoundSystem()));
Computer computer = injector.getInstance(Computer.class);
// We will be satisfied with no exception being thrown
@CollectiveHealth-gists
CollectiveHealth-gists / IntegrationWithDisplaySystemTest.java
Created June 1, 2018 18:12
Testing with real instance of DisplaySystem, but mocked out SoundSystem.
public class IntegrationWithDisplaySystemTest {
@Test
public void testDisplaySystem() {
Injector injector = Guice.createInjector(new ComputerTestModule()
.withInstance(DisplaySystem.class, new DisplaySystem()));
Computer computer = injector.getInstance(Computer.class);
// We are satisfied with no exception being thrown
public class ComputerTestModule extends TestModule {
@Override
protected Collection<ClassInstancePair<?>> getDefaultInstances() {
return Arrays.asList(
createClassMockPair(DisplaySystem.class),
createClassMockPair(SoundSystem.class));
}
}
@CollectiveHealth-gists
CollectiveHealth-gists / ComputerTestUsingTestModule.java
Created June 1, 2018 18:10
ComputerTest implemented using TestModule.
public class ComputerTestUsingTestModule {
@Test
public void testPlayVideo() {
Injector injector = Guice.createInjector(new TestModule()
.withMockedClasses(SoundSystem.class, DisplaySystem.class));
Computer computer = injector.getInstance(Computer.class);
SoundSystem soundSystem = injector.getInstance(SoundSystem.class);
DisplaySystem displaySystem = injector.getInstance(DisplaySystem.class);
@CollectiveHealth-gists
CollectiveHealth-gists / ComputerTestUsingSetter.java
Created June 1, 2018 18:09
ComputerTest implemented using setters.
public class ComputerTestUsingSetter {
@Test
public void testPlayVideo() {
Computer computer = new Computer();
MotherBoard motherBoard = new MotherBoard();
SoundCard soundCard = new SoundCard();
VideoCard videoCard = new VideoCard();
SoundSystem soundSystem = Mockito.mock(SoundSystem.class);
DisplaySystem displaySystem = Mockito.mock(DisplaySystem.class);
@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,
@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 / 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 / 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 / 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