This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
class Solution { | |
public int[] products(int[] nums) { | |
int[] result = new int[nums.length]; | |
if (nums.length > 1) { | |
result[0] = 1; | |
} | |
int productSoFar = nums[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handle = (event, context) => { | |
// Handle the request and return a promise | |
} | |
exports.myHandler = withMiddlewares(handle, [ | |
SentryMiddleware(), | |
DynamoDbInsertOrModifyEventsMiddleware() | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DynamoDbInsertOrModifyEventsMiddleware = () => (event, context, next) => { | |
const filteredRecords = event.Records.filter(isInsertOrModifyEvent) | |
const mutatedEvent = event | |
mutatedEvent.Records = filteredRecords | |
return next(mutatedEvent, context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SentryMiddleware = (event, context, next) => { | |
initializeSentry() | |
return next(event, context) | |
.catch(error => captureExceptionAndReturnPromise(error, {}).then(() => Promise.reject(error))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const withMiddlewares = (handler, middlewares = []) => (event, context, callback) => { | |
const chainMiddlewares = ([firstMiddleware, ...restOfMiddlewares]) => { | |
if (firstMiddleware) { | |
return (e, c) => { | |
try { | |
return firstMiddleware(e, c, chainMiddlewares(restOfMiddlewares)) | |
} catch (error) { | |
return Promise.reject(error) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Scientist::Experiment | |
def self.new(name) | |
MyServiceExperiment.new(name: name) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyServiceExperiment | |
include Scientist::Experiment | |
def enabled? | |
true | |
end | |
def publish(result) | |
statsd_client = Rails.application.config.statsd_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LogrageHttpResponseAppender | |
def append_info_to_payload(payload) | |
super | |
payload[:experiments] = RequestStore.store[:experiments] if RequestStore.store[:experiments] | |
end | |
end | |
class ApplicationController < ActionController::API | |
include LogrageHttpResponseAppender | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExperimentalEngine | |
include Scientist | |
def estimate(p1, p2, p3) | |
science "PriceEstimate" |e| | |
e.context p1: p1, p2: p2, p3: p3 | |
e.use { LocalPricingEngine.new.estimate(p1, p2, p3) } | |
e.try { PricingServiceEngine.new.estimate(p1, p2, p3) } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PricingEngineFactory | |
def self.engine | |
engine_class = Figaro.env.pricing_engine || LocalPricingEngine.name | |
engine_class.safe_constantize.new | |
end | |
end |
NewerOlder