View Between times.kts
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 org.joda.time.DateTime | |
import org.joda.time.Minutes | |
val now = DateTime.now() | |
val past = now.minusMinutes(3) | |
println(Minutes.minutesBetween(past, now).minutes) | |
println(Minutes.minutesBetween(now, past).minutes) |
View withStrictModeThreadPolicy.kt
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 android.os.StrictMode | |
fun <T> withStrictModeThreadPolicy(threadPolicy: StrictMode.ThreadPolicy, block: () -> T): T { | |
val previousPolicy = StrictMode.getThreadPolicy() | |
StrictMode.setThreadPolicy(threadPolicy) | |
try { | |
return block() | |
} finally { | |
StrictMode.setThreadPolicy(previousPolicy) | |
} |
View AliceAndBobSource
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
// Alice.ts | |
import aws from 'aws-sdk'; | |
export function main(event: any, context: any, callback: Function) { | |
new aws.Lambda().invoke({ | |
FunctionName: process.env.BobFunction!, | |
Payload: JSON.stringify({message: "Hi!. I'm Alice."}) | |
}, (error: Error, data: any) => { | |
const response = JSON.parse(data.Payload); | |
console.log('FromBob', error || response) |
View LambdaAndCloudform
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 cloudform, { Lambda, IAM, Fn } from 'cloudform'; | |
const LambdaExecutionRole = 'LambdaExecutionRole'; | |
cloudform({ | |
Resources: { | |
HelloWorld: new Lambda.Function({ | |
Code: { | |
ZipFile: "exports.wrtiteToConsole = function (event, context, callback){ console.log('Hello'); callback(null); }" | |
}, |
View LambdaExecutionRole
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
[LambdaExecutionRole]: new IAM.Role({ | |
AssumeRolePolicyDocument: { | |
Statement: [{ | |
Effect: "Allow", | |
Principal: { Service: ["lambda.amazonaws.com"] }, Action: ["sts:AssumeRole"] | |
}] | |
}, | |
Path: "/", | |
ManagedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"], Policies: [{ | |
PolicyName: "AllowCallingOtherLambda", |
View AliceAndBob
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 cloudform, { Lambda, IAM, Fn } from 'cloudform'; | |
import { FunctionProperties } from 'cloudform/types/lambda/function'; | |
import { readFileSync } from 'fs'; | |
const LambdaExecutionRole = 'LambdaExecutionRole', Alice = 'Alice', Bob = 'Bob'; | |
function lambdaFunction(functionCode: string, options?: Partial<FunctionProperties>) { | |
return new Lambda.Function({ | |
Code: { ZipFile: functionCode }, | |
Handler: "index.main", | |
Role: Fn.GetAtt(LambdaExecutionRole, "Arn"), |
View TenantTaskCoordinator.kt
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 org.slf4j.LoggerFactory | |
import org.springframework.http.HttpStatus | |
import org.springframework.web.bind.annotation.ResponseStatus | |
import reactor.core.publisher.Flux | |
import reactor.core.publisher.FluxSink | |
import reactor.core.publisher.Mono | |
import reactor.core.publisher.MonoSink | |
import reactor.core.scheduler.Scheduler | |
import java.util.concurrent.Callable |
View RateLimitingMappingHandlerAdapter.kt
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 CommandInvocableHandlerMethod(private val handlerMethod: HandlerMethod, | |
private val requestCommandFactory: RequestCommandFactory, | |
private val configuration: RequestCommandConfiguration) : ServletInvocableHandlerMethod(handlerMethod) { | |
private lateinit var returnValueHandlers: HandlerMethodReturnValueHandlerComposite | |
@Trace(dispatcher = true) | |
override fun invokeForRequest(request: NativeWebRequest?, mavContainer: ModelAndViewContainer?, vararg providedArgs: Any?): Any { | |
// same as super.invokeForRequest(request, mavContainer, *providedArgs) | |
//but with request passed to do invoke | |
val args = this.getMethodArgumentValuesCallable.invoke(request, mavContainer, providedArgs) |
View SecurityContextHolderAwareTaskExecutor.kt
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 org.springframework.core.task.TaskExecutor | |
import org.springframework.security.core.Authentication | |
import org.springframework.security.core.context.SecurityContext | |
import org.springframework.security.core.context.SecurityContextHolder | |
class SecurityContextHolderAwareTaskExecutor(private val realTaskExecutor: TaskExecutor) : TaskExecutor { | |
override fun execute(task: Runnable) { | |
val context = SecurityContextHolder.getContext() | |
if (context != null) { |
View MockitoTests_Constructor.kt
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 org.hamcrest.MatcherAssert | |
import org.hamcrest.Matchers | |
import org.junit.Test | |
import org.mockito.Mockito | |
import javax.inject.Inject | |
import javax.servlet.http.HttpServletRequest | |
interface Database { | |
fun findUser(): User |
NewerOlder