Skip to content

Instantly share code, notes, and snippets.

Piotr Mionskowski miensol

Block or report user

Report or block miensol

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
miensol / withStrictModeThreadPolicy.kt
Last active May 6, 2019
Override android strict mode policy when in android tests to allow calling network on main thread.Useful when you want to access mock web server address and you don't care about the threading.
View withStrictModeThreadPolicy.kt
import android.os.StrictMode
fun <T> withStrictModeThreadPolicy(threadPolicy: StrictMode.ThreadPolicy, block: () -> T): T {
val previousPolicy = StrictMode.getThreadPolicy()
try {
return block()
} finally {
View AliceAndBobSource
// 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
import cloudform, { Lambda, IAM, Fn } from 'cloudform';
const LambdaExecutionRole = 'LambdaExecutionRole';
Resources: {
HelloWorld: new Lambda.Function({
Code: {
ZipFile: "exports.wrtiteToConsole = function (event, context, callback){ console.log('Hello'); callback(null); }"
View LambdaExecutionRole
[LambdaExecutionRole]: new IAM.Role({
AssumeRolePolicyDocument: {
Statement: [{
Effect: "Allow",
Principal: { Service: [""] }, Action: ["sts:AssumeRole"]
Path: "/",
ManagedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"], Policies: [{
PolicyName: "AllowCallingOtherLambda",
View AliceAndBob
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
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
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
import org.springframework.core.task.TaskExecutor
class SecurityContextHolderAwareTaskExecutor(private val realTaskExecutor: TaskExecutor) : TaskExecutor {
override fun execute(task: Runnable) {
val context = SecurityContextHolder.getContext()
if (context != null) {
View MockitoTests_Constructor.kt
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
View MockitoTests.kt
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.Before
import org.junit.Test
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import javax.inject.Inject
import javax.servlet.http.HttpServletRequest
You can’t perform that action at this time.