Skip to content

Instantly share code, notes, and snippets.

@venator85
venator85 / MaterialColorsPreview.kt
Last active October 17, 2024 17:28
A Composable function designed to showcase all the colors of a Material theme, in both light and dark modes.
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
@venator85
venator85 / DelTagHandler.java
Created January 15, 2020 11:02
A Html.fromHtml() TagHandler to support <del> on Android <= 6
import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.StrikethroughSpan;
import org.xml.sax.XMLReader;
public class DelTagHandler implements Html.TagHandler {
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
@venator85
venator85 / coroutines_sample.kt
Created November 12, 2019 16:55
Coroutine Samples
// implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
// for lifecycleScope: implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-rc02'
class MyFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val request = Request.Builder().get()
.url("https://icanhazip.com")
.build()
@venator85
venator85 / itemclick_recyclerview.kt
Created August 25, 2018 08:13
RecyclerView with item click support
package eu.alessiobianchi
import android.support.v7.widget.RecyclerView
import android.view.View
interface ItemClickListener<T> {
fun onClick(view: View, position: Int, item: T)
}
abstract class ClickableAdapter<T, V: ClickableViewHolder<T>>(
@venator85
venator85 / build.gradle
Created January 12, 2018 09:56
Gradle task to print APK signing certificate information (e.g. SHA1 hash)
android.applicationVariants.all { variant ->
tasks.create(name: "signatureHash${variant.name.capitalize()}", type: Exec) {
group "util"
commandLine 'keytool', '-exportcert', '-list', '-v',
'-alias', variant.signingConfig.keyAlias,
'-keypass', variant.signingConfig.keyPassword,
'-keystore', variant.signingConfig.storeFile,
'-storepass', variant.signingConfig.storePassword
doFirst {
println ":: Signing config for variant ${variant.name} is: ${variant.signingConfig.name}\n"
@venator85
venator85 / constraint_layout_gridlayout.xml
Last active March 16, 2017 22:53
Trying to replicate GridLayout behavior with ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
@venator85
venator85 / asuswrt-route53.sh
Created January 26, 2017 22:05
Custom AsusWRT DDNS script for AWS Route53
#!/bin/sh
# note: when debugging on PC/MAC, this script must be run with bash
# Custom AsusWRT DDNS script for AWS Route53 - v1.0
# Author: Alessio Bianchi <[email protected]>
# Credits: http://czak.pl/2015/09/15/s3-rest-api-with-curl.html
ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXXXX"
SECRET_ACCESS_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# These keys can be associated to a IAM user with the following policy:
@venator85
venator85 / fold.sh
Created January 26, 2017 10:51
fold (hard wrap) in pure bash
fold() {
data="$1"
width="$2"
length=$(echo -n "$data" | wc -c)
while [ $length -gt $width ]
do
echo ${data:0:$width}
data=${data:$width}
length=$(echo -n "$data" | wc -c)
done
@venator85
venator85 / CertificateValidation.java
Created October 24, 2016 13:50
Manually verify a certificate (chain) against a root
public static void validateCertificate(X509Certificate toVerify, X509Certificate root) throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
CertPath cp = cf.generateCertPath(Collections.singletonList(toVerify));
TrustAnchor trustAnchor = new TrustAnchor(root, null);
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
PKIXParameters pkixParams = new PKIXParameters(Collections.singleton(trustAnchor));
pkixParams.setRevocationEnabled(false);
@venator85
venator85 / ApkCertificate.java
Created October 24, 2016 10:41
Extract the X509Certificate used to sign the app from the APK
package com.example.alessio.testapp;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.zip.ZipEntry;