Skip to content

Instantly share code, notes, and snippets.

View harryhan24's full-sized avatar

harry han harryhan24

View GitHub Profile
@harryhan24
harryhan24 / printData
Last active June 1, 2018 16:39
medium용
fun print(body: (Int, Int) -> Int) {
println(body(5, 5))
}
print({a,b-> a})
public final void print(@NotNull Function2 body) {
Intrinsics.checkParameterIsNotNull(body, "body");
Object result = body.invoke(1,2); //result 값은 1
System.out.println(result);
}
private fun printResult(body: (Int, Int) -> Int) {
println(body(10, 5))
}
fun sum(a: Int, b: Int) = a + b
fun subtract(a: Int, b: Int) = a - b
printResult(::sum) //result = 15
printResult(::minus) //result 5
@harryhan24
harryhan24 / STSTesting.scala
Created June 2, 2018 18:36
Using STS with MFA and longer lived session credentials
import com.amazonaws.auth.profile.internal.{BasicProfile, ProfileStaticCredentialsProvider}
import com.amazonaws.auth.profile.{ProfileCredentialsProvider, ProfilesConfigFile}
import com.amazonaws.auth.{AWSCredentials, AWSCredentialsProvider, AWSStaticCredentialsProvider, BasicSessionCredentials, DefaultAWSCredentialsProviderChain}
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.securitytoken.model.{AssumeRoleRequest, GetSessionTokenRequest}
import com.amazonaws.services.securitytoken.{AWSSecurityTokenServiceClient, AWSSecurityTokenServiceClientBuilder}
import scala.collection.JavaConversions._
object STSTesting {
@harryhan24
harryhan24 / sns-to-slack.js
Created June 7, 2018 14:40 — forked from benyanke/sns-to-slack.js
AWS Lambda function for forwarding SNS notifications to Slack
// Added by Ben Yanke
// from https://gist.github.com/benyanke/862e446e5a816551928d8acc2d98b752
console.log('Loading function');
const https = require('https');
const url = require('url');
// SETUP
// urlToUse = in this environment variable, place the name of another environment variable which contains the key.
// This allows easy dev/prod switching.
@harryhan24
harryhan24 / build.gradle
Created June 28, 2018 14:38 — forked from davebren/build.gradle
gradle flavors and resources example
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 23
@harryhan24
harryhan24 / Extensions.kt
Created July 2, 2018 15:44 — forked from albertogiunta/Extensions.kt
Extension functions (Kotlin) & build.gradle files for Android projects
/**
* ANY
*/
fun Any.toJson(): String = GsonInitializer.toJson(this)
/**
* VIEW
*/
fun View.toggleVisibility(setAsVisible: Boolean) = if (setAsVisible) this.visible() else this.gone()
@harryhan24
harryhan24 / serverless.yml
Created July 21, 2018 02:58 — forked from DavidWells/serverless.yml
DynamoDB custom index serverless.yml example
service: service-name
provider:
name: aws
runtime: nodejs6.10
functions:
myfunc:
handler: handler.myfunc
class AnkoViewHolder<out V : AnkoComponent<ViewGroup>>(val parent: ViewGroup, val createUI: () -> V) {
class ViewHolder<out V : AnkoComponent<ViewGroup>>(val view: View, val ui: V) : RecyclerView.ViewHolder(view)
val ankoContext by lazy { AnkoContext.createReusable(parent.context, parent) }
val viewHolder by lazy {
val ui = createUI()
val view = ui.createView(ankoContext)
view.setupTapEffectForBG(true) // default for every item in application
// TODO some items may be disabled...
ViewHolder(view, ui)