Skip to content

Instantly share code, notes, and snippets.

View mherod's full-sized avatar
🏳️‍🌈

Matthew Herod mherod

🏳️‍🌈
View GitHub Profile
import { test, expect } from "@playwright/test";
const { getCookie } = require("@mherod/get-cookie");
test.beforeAll(async ({ browser }) => {
const browserContexts = browser.contexts();
const domain = "myunidays.com";
const cookie = await getCookie({
name: "auth",
domain: domain
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
inline class PropertyAlias<T>(val delegate: KMutableProperty0<T>) : ReadWriteProperty<Any?, T> {
override operator fun getValue(thisRef: Any?, property: KProperty<*>): T = delegate.get()
override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) = delegate.set(value)
}
@mherod
mherod / twennyminutewifi.sh
Last active May 3, 2022 05:12
stopping at a hotel which only gives you 20 minutes of free wifi. run this for unlimited wifi
#!/bin/bash
# link airport into path if not found
which airport || sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport
while true ; do
CURRENT_SSID=`airport -I | grep "\\s\\+SSID:\\s" | awk '{print $2}'`
echo "Currently connected to $CURRENT_SSID"
# set wifi interface mac address, computed random blob using openssl and then sed formats into shape, add colon per 2 char, trim trailing colon
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy
import kotlin.properties.Delegates
inline fun <reified T : Any> lazyProxyLazy(noinline delegate: () -> T): Lazy<T> {
return lazy { proxyLazy(delegate) }
}
inline fun <reified T : Any> proxyLazy(noinline delegate: () -> T): T {
const { exec } = require("child_process");
async function command(command) {
const promise = new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) reject(error)
if (stderr) reject(stderr)
if (stdout) resolve(stdout)
});
});
@mherod
mherod / coroutineSample.kt
Created October 1, 2021 00:42 — forked from nosix/coroutineSample.kt
Promise and async/await sample in Kotlin/JS
fun main(args: Array<String>) {
launch {
loadAllFiles()
}
}
fun launch(block: suspend () -> Unit) {
block.startCoroutine(object : Continuation<Unit> {
override val context: CoroutineContext get() = EmptyCoroutineContext
override fun resume(value: Unit) {}
val cookieManager = CookieManager.getInstance()
cookieManager.removeAllCookies {
// undesired async completion handler
}
suspend fun CookieManager.clearCookies(): Boolean = suspendCoroutine {
removeAllCookies(it::resume)
}
@mherod
mherod / PosixCwd.kt
Created January 4, 2021 11:34
Get current working directory in Kotlin/Native
inline fun getCwd(): String? {
return ByteArray(1024).usePinned { getcwd(it.addressOf(0), 1024) }?.toKString()
}
@mherod
mherod / PosixExec.kt
Created January 4, 2021 11:32
Execute program and read output using Kotlin/Native
fun exec(command: String): String {
val returnBuffer = StringBuilder()
val file = popen(command, "r")
try {
memScoped {
val readBufferLength = 128
val buffer = allocArray<ByteVar>(readBufferLength)
var line = fgets(buffer, readBufferLength, file)?.toKString()
while (line != null) {
returnBuffer.append(line)
@mherod
mherod / DaggerComponentSearch.kt
Created October 24, 2020 16:02
Complement to a Dagger reflect setup
import java.util.Locale
import kotlin.reflect.KClass
@Deprecated(
message = "This shouldn't be used in production.",
level = DeprecationLevel.WARNING
)
inline fun <reified T : Any> findComponent(): T {
val kClass: KClass<T> = T::class
val name = checkNotNull(kClass.qualifiedName)