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
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) | |
} |
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
#!/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 |
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
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 { |
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
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) | |
}); | |
}); |
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 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) {} |
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
val cookieManager = CookieManager.getInstance() | |
cookieManager.removeAllCookies { | |
// undesired async completion handler | |
} | |
suspend fun CookieManager.clearCookies(): Boolean = suspendCoroutine { | |
removeAllCookies(it::resume) | |
} |
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
inline fun getCwd(): String? { | |
return ByteArray(1024).usePinned { getcwd(it.addressOf(0), 1024) }?.toKString() | |
} |
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 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) |
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
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) |
NewerOlder