Scala with Futures:
import java.util.UUID
import scala.concurrent.Future
trait User {
def isAdmin: Boolean
def id: UUID
// unwrap TRs if they got wrapped in a tbody by the parser | |
{ | |
let trsCountInResponseText = 0; | |
let trsCountInResponseFragment = 0; | |
if (responseText.indexOf('<tr') !== -1) { | |
var regExp = new RegExp('<tr', 'gim'); | |
trsCountInResponseText = (responseText.match(regExp) || []).length; | |
for (const elt of responseElts) { | |
if (elt.tagName === 'TR') { |
/** | |
* Principles: | |
* 1. Performance | |
* 2. Simplicity and debuggability. | |
* | |
* It's not trying to be: | |
* 1. Flexible. | |
* | |
* This results into the following: | |
* 1. Explicit attributes only |
```js | |
htmx.onLoad(function (content) { | |
const attr = 'lr-post'; | |
const httpMethod = 'POST'; | |
const controlElts = content.querySelectorAll(`[${attr}]`); | |
for (const controlElt of controlElts) { | |
const link = controlElt.getAttribute && controlElt.getAttribute(attr); | |
if (link === undefined) { | |
continue | |
} |
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0}, | |
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":42755,"ts":0}, | |
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87047,"tid":259,"ts":0}, | |
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":259,"ts":0}, | |
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":259,"ts":0}, | |
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87047,"tid":30979,"ts":0}, | |
{"args":{"name":"ThreadPoolBackgroundWorker"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":25091,"ts":0}, | |
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":37379,"ts":0}, | |
{"args":{"name":"Chrome_ChildIOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":1 |
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0}, | |
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87047,"tid":259,"ts":0}, | |
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":42755,"ts":0}, | |
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":259,"ts":0}, | |
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87047,"tid":30979,"ts":0}, | |
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":259,"ts":0}, | |
{"args":{"name":"ThreadPoolBackgroundWorker"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":25091,"ts":0}, | |
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87058,"tid":37379,"ts":0}, | |
{"args":{"name":"Chrome_ChildIOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":87078,"tid":1 |
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0}, | |
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26442,"tid":22019,"ts":0}, | |
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26404,"tid":259,"ts":0}, | |
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26442,"tid":259,"ts":0}, | |
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26404,"tid":35075,"ts":0}, | |
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26413,"tid":26115,"ts":0}, | |
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26413,"tid":259,"ts":0}, | |
{"args":{"name":"Chrome_ChildIOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26442,"tid":19715,"ts":0}, | |
{"args":{"name":"ThreadPoolBackgroundWorker"},"cat":"__metadata","name":"thread_name","ph":"M","pid":26413,"tid":4 |
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0}, | |
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67620,"tid":259,"ts":0}, | |
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":97368,"tid":22787,"ts":0}, | |
{"args":{"name":"ThreadPoolServiceThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67629,"tid":24323,"ts":0}, | |
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67620,"tid":28931,"ts":0}, | |
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67629,"tid":27907,"ts":0}, | |
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":97368,"tid":259,"ts":0}, | |
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67629,"tid":259,"ts":0}, | |
{"args":{"name":"ThreadPoolBackgroundWorker"},"cat":"__metadata","name":"thread_name","ph":"M","pid":67629,"tid |
/** | |
* Lookup property in obj[path] | |
* @return found property in a nested object | |
*/ | |
fun findNestedProperty(obj: Any, path: List<String>): NestedPropertyLookup { | |
var instance: Any = obj | |
for (keyIdx in path.indices) { | |
val memberProperties = instance::class.memberProperties | |
val property = memberProperties.find { callable -> | |
callable.name == path[keyIdx] |
Scala with Futures:
import java.util.UUID
import scala.concurrent.Future
trait User {
def isAdmin: Boolean
def id: UUID
object Retrofit2Https { | |
fun createHttpClient(context: Context): OkHttpClient { | |
// Loads "my_certificate.crt" from res/raw/my_certificate.crt | |
val cf: CertificateFactory = CertificateFactory.getInstance("X.509") | |
val caInput: InputStream = BufferedInputStream(context.resources.openRawResource(R.raw.my_certificate)) | |
val ca: X509Certificate = caInput.use { | |
cf.generateCertificate(it) as X509Certificate | |
} | |
// Create a KeyStore with the certificate |