| import com.google.gson.Gson | |
| import com.google.gson.JsonObject | |
| enum class CurrencySymbol { | |
| EUR, CAD, HKD, ISK, PHP, DKK, HUF, CZK, AUD, RON, SEK, | |
| IDR, INR, BRL, RUB, HRK, JPY, THB, CHF, SGD, PLN, BGN, | |
| TRY, CNY, NOK, NZD, ZAR, USD, MXN, ILS, GBP, KRW, MYR | |
| } | |
| /** |
| import android.view.ViewTreeObserver | |
| import android.webkit.JavascriptInterface | |
| import android.webkit.WebView | |
| import android.webkit.WebViewClient | |
| // Try 1 | |
| private fun getHeightFromDocumentBodyScrollHeight(webView: WebView, setHeight: (Int)->Unit) { | |
| webView.webViewClient = object : WebViewClient() { | |
| override fun onPageFinished(view: WebView?, url: String?) { |
| fun getAppSignature(context: Context) = context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES) | |
| .signatures.mapNotNull { hash(context.packageName, it.toCharsString()) }.firstOrNull() | |
| private fun hash(packageName: String, signature: String) = try { | |
| val messageDigest = MessageDigest.getInstance("SHA-256") | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |
| messageDigest.update("$packageName $signature".toByteArray(StandardCharsets.UTF_8)) | |
| } | |
| var hashSignature = messageDigest.digest() | |
| hashSignature = Arrays.copyOfRange(hashSignature, 0, 9) |
| import com.google.gson.* | |
| fun wikipedia(keyword: String): String { | |
| val url = "https://en.wikipedia.org/w/api.php" + | |
| "?action=query&format=json&prop=extracts" + | |
| "&exsectionformat=plain&exsentences=2&explaintext=1" + | |
| "&titles=$keyword" | |
| val json = java.net.URL(url).readText() | |
| val jsonObject = Gson().fromJson<JsonObject>(json, JsonObject::class.java) | |
| val pages = jsonObject["query"].asJsonObject["pages"].asJsonObject |
| import org.jsoup.Jsoup | |
| fun google(keyword: String): String { | |
| val doc = Jsoup.connect("https://google.com/search?q=$keyword") | |
| .userAgent("Mozilla/5.0").get() | |
| val title = doc.selectFirst("h3.r a")?.text() | |
| val description = doc.selectFirst("span.st")?.text() | |
| return "$title. $description" | |
| } |
| fun getBytesFromStringFileSize(fileSizeString: String): Long? { | |
| fun parseBytes(string: String, unit: String, scale: Double): Long { | |
| val numberString = string.toUpperCase().replace(unit, "") | |
| val number = numberString.toDouble() | |
| return (number * Math.pow(1024.0, scale)).toLong() | |
| } | |
| try { | |
| if (fileSizeString.endsWith("GB", ignoreCase = true)) { | |
| return parseBytes(fileSizeString, "GB", 3.0) | |
| } |
| import com.github.kittinunf.fuel.Fuel | |
| import com.github.kittinunf.fuel.core.HeaderValues | |
| import com.github.kittinunf.fuel.core.Method | |
| import com.github.kittinunf.fuel.core.Parameters | |
| import com.github.kittinunf.fuel.core.Request | |
| import com.github.kittinunf.fuel.core.requests.tryCancel | |
| import com.github.kittinunf.fuel.json.FuelJson | |
| import com.github.kittinunf.fuel.json.responseJson | |
| import com.github.kittinunf.fuel.util.FuelRouting | |
| import java.util.* |
| Verifying that +antonis is my blockchain ID. https://onename.com/antonis |