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
require("colors"); | |
const express = require("express"); | |
const logger = require("morgan"); | |
const helmet = require("helmet"); | |
const xss = require("xss-clean"); | |
const hpp = require("hpp"); | |
const mongoSanitize = require("express-mongo-sanitize"); | |
const rateLimit = require("express-rate-limit"); | |
const cors = require("cors"); | |
const morgan = require("morgan"); |
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
var axios = require('axios'); | |
var fs = require('fs'); | |
var path = require('path') | |
var util = require('util') | |
let readfile = util.promisify(fs.readFile) | |
async function sendData(url,data) { | |
let params = data | |
let resp = await axios({ |
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
// declaration | |
inline fun inlineFunction(callback: () -> User) { | |
println("before callback") | |
val result = callback() | |
println("after callback") | |
} | |
// Illegal usage of inline-parameter 'callback' in '...'. |
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
// declaration | |
inline fun inlineFunction(callback: () -> Unit) { | |
println("before callback") | |
callback() | |
println("after callback") | |
} | |
// calling function | |
btnPrintMessage.setOnClickListener(){ | |
inlineFunction(){ |
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
btnPrintMessage.setOnClickListener { | |
nonInline { println("Noninline function has been called") } | |
} | |
// in java code | simplified version | |
btnPrintMessage.setOnClickListener(){ | |
@override | |
void onClick(View v){ | |
noninline(new Function { | |
println("Noninline function has been called") |
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
nonInline { | |
println("Noninline function has been called") | |
} | |
// in java code | simplified version | |
nonInline(new Function() { | |
@Override | |
public void invoke() { | |
System.out.println("Noninline function has been called"); | |
} |
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
fun nonInline(callback: () -> Unit) { | |
println("before callback") | |
callback() | |
println("after callback") | |
} | |
// in java code | |
public void nonInline(Function callback) { | |
System.out.println("before callback"); | |
callback.invoke(); |
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 MainActivity : AppCompatActivity() { | |
private val tvUsername: TextView by lazy { findViewById(R.id.tv_username) } | |
private var text: String by Delegates.observable("Initial Value") { property, oldvalue, newValue -> | |
tvUsername.text = newValue | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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 MainActivity: AppCompatActivity { | |
val buttonLogin by id(R.id.btn_login) | |
// other stuff | |
// .. | |
// .. | |
fun AppCompatActivity.id(viewId: Int) = ViewDelegate(viewId) | |
} |
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 ViewDelegate( | |
private val viewId: Int | |
): ReadOnlyProperty<AppCompatActivity, String> { | |
private var result: String? = null | |
override fun getValue(thisRef: AppCompatActivity, property: KProperty<*>): String = | |
result ?: thisRef.findViewById(viewId).also { result = it } | |
} |
NewerOlder