Skip to content

Instantly share code, notes, and snippets.

View ok3141's full-sized avatar

Oleksii ok3141

View GitHub Profile
@ok3141
ok3141 / Example.java
Last active December 3, 2018 16:40
Android show/hide soft keyboard guaranteed
public void somewhere() {
EditText editText = result.findViewById(R.id.edit_text);
new SoftInputHelper(editText)
.setShowFlags(InputMethodManager.SHOW_FORCED) // NOTE this line can be omitted for most cases
.show();
}
@ok3141
ok3141 / MonospaceSpan.java
Last active March 15, 2023 05:43
MonospaceSpan detects the widest char of given text and draws others with the same width
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.style.ReplacementSpan;
public class MonospaceSpan extends ReplacementSpan {
private boolean ignoreFullText;
public void setIgnoreFullText(boolean ignoreFullText) {
@ok3141
ok3141 / TextDrawable.java
Last active November 22, 2018 14:00
TextDrawable which can be used for drawing iconiс fonts
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
@ok3141
ok3141 / Somewhere.java
Last active November 22, 2018 10:10
Scaling ThreadPoolExecutor. Android. Java
@NonNull
@UiThread
public Executor getThreadPool() {
if (threadPool == null) {
final String threadNamePrefix = getClass().getSimpleName();
int corePoolSize = 0;
int maxPoolSize = Math.max(2, Runtime.getRuntime().availableProcessors() * 2 + 1);
long keepAliveTime = 10;
@ok3141
ok3141 / _.md
Last active April 14, 2026 16:57
Linux/Mac Scripts

General

Generate random password

cat /dev/random | base64 | head -c 24 && echo

Generate debug.keystore for Android

keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000

@ok3141
ok3141 / LoggingInputStream.java
Last active September 18, 2018 08:14
Redirect InputStream to Android Logcat
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public final class LoggingInputStream extends InputStream {
static {
if (!BuildConfig.DEBUG) {
throw new AssertionError();
@ok3141
ok3141 / curl.md
Created August 3, 2018 12:46 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@ok3141
ok3141 / build.gradle
Created August 3, 2018 12:05 — forked from lifuzu/build.gradle
Parse XML file in gradle
//Declaring the inputs and outputs of a task
//build.gradle
task transform {
ext.srcFile = file('mountains.xml')
ext.destDir = new File(buildDir, 'generated')
inputs.file srcFile
outputs.dir destDir
doLast {
println "Transforming source file."
@ok3141
ok3141 / android-vector-drawable-to-svg.xsl
Last active November 24, 2024 15:45
Convert Android Vector Drawable to SVG with XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<svg xmlns="http://www.w3.org/2000/svg">
<xsl:attribute name="width">
<xsl:value-of select="substring-before(vector/@width, 'dp')"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="substring-before(vector/@height, 'dp')"/>
</xsl:attribute>
@ok3141
ok3141 / build.gradle
Created May 9, 2018 12:16 — forked from michail-nikolaev/build.gradle
Gradle - force transitive dependency version for some group
apply plugin: 'java'
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
//specifying a fixed version for all libraries with 'org.gradle' group
if (details.requested.group == 'org.springframework') {
details.useVersion "$springVersion"
}
}