Skip to content

Instantly share code, notes, and snippets.

View milis92's full-sized avatar
🎯
Focusing

Ivan Milisavljevic milis92

🎯
Focusing
View GitHub Profile
@milis92
milis92 / Contravariance.java
Last active March 20, 2023 01:20
Kotlin Generics Blog Content
// Where hierarchy tree looks like Animal->Dog->Husky
public static void main(String[] args) {
List<? super Dog> animals = new ArrayList<Animal>(); //Compatible type
List<? super Dog> dogs = new ArrayList<Dog>(); //Compatible type
List<? super Dog> huskies = new ArrayList<Husky>(); //Incompatible type
contravariance(new ArrayList<Animal>()); //Ok
contravariance(new ArrayList<Dog>()); //OK
contravariance(new ArrayList<Husky>()); //Compiler error
}
//Put this into buildSrc/src/android-applicaiton-convention.gradle.kts
@file:Suppress("UnstableApiUsage")
import com.android.build.api.dsl.ApplicationDefaultConfig
plugins {
id("com.android.application")
id("org.gradle.android.cache-fix")
kotlin("android")
package com.ivan.store
import android.content.SharedPreferences
import androidx.core.content.edit
interface KeyValueStore {
fun write(key: String, value: Any?)
fun <T> read(key: String): T?
task getDeviceIp {
doLast {
new ByteArrayOutputStream().withStream { os ->
exec {
commandLine(android.getAdbExe())
args('shell', 'ip', 'addr', 'show', 'wlan0', ' | grep', '\'inet \'', '| cut -d\' \'', '-f6', '|cut -d/', '-f1')
standardOutput = os
}
ext.deviceIp = os.toString().trim()
}
#!/bin/bash
set -o pipefail -e
usage="
$(basename "$0") [-h] [-e/d -p=\"password\" -f=\"path/to/file\"]
where:
-h --help show this help text
#!/bin/bash
certs=`openssl s_client -servername $1 -host $1 -port 443 -showcerts </dev/null 2>/dev/null | sed -n '/Certificate chain/,/Server certificate/p'`
rest=$certs
while [[ "$rest" =~ '-----BEGIN CERTIFICATE-----' ]]
do
cert="${rest%%-----END CERTIFICATE-----*}-----END CERTIFICATE-----"
rest=${rest#*-----END CERTIFICATE-----}
echo `echo "$cert" | grep 's:' | sed 's/.*s:\(.*\)/\1/'`
echo "$cert" | openssl x509 -pubkey -noout |
openssl rsa -pubin -outform der 2>/dev/null |