Skip to content

Instantly share code, notes, and snippets.

View timtsj's full-sized avatar

WrittenWord timtsj

View GitHub Profile
@timtsj
timtsj / RoundBarChartRender.kt
Created October 5, 2020 04:19
mpandroidchart stacked bar chart radius
package com.exmaple
import android.graphics.*
import com.github.mikephil.charting.animation.ChartAnimator
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
import com.github.mikephil.charting.renderer.BarChartRenderer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler
@timtsj
timtsj / NetworkUtils.kt
Created May 11, 2020 06:22
Android utility class for checking device's network connectivity and speed.
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.net.NetworkInfo
import android.os.Build
import android.telephony.TelephonyManager
object NetworkUtils {
enum class ConnectivityMode {
@timtsj
timtsj / LogTimberKotlin.xml
Created March 19, 2020 06:05
LogTimberKotlin.xml template
<templateSet group="LogTimberKotlin">
<template name="timm" value="timber.log.Timber.d($FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="timd" value="timber.log.Timber.d(&quot;$METHOD_NAME$: $content$&quot;)" description="Timber.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClas
@timtsj
timtsj / AndroidLogKotlin.xml
Created March 19, 2020 06:05
AndroidLogKotlin template
<templateSet group="AndroidLogKotlin">
<template name="logm" value="android.util.Log.d(&quot;$NAME$&quot;, $FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logd" value="android.util.Log.d(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(
@timtsj
timtsj / IINValidator.java
Last active November 23, 2020 04:09
Simple KZ IIN validator
public boolean isValidIIN(String iin) {
if (TextUtils.isEmpty(iin)) return false;
String date = iin.substring(0, 6);
String gender = iin.substring(6, 7);
return iin.matches("\\d{12}") && isValidBirthday(date) && gender.matches("[1-6]") && isValidControl(iin);
}
private boolean isValidBirthday(String date) {
if (TextUtils.isEmpty(date) || !date.matches("\\d{2}[01]\\d[0-3]\\d")) return false;
@timtsj
timtsj / CourtCounter
Last active November 15, 2018 17:56
CourtCounter in JavaRush
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
@timtsj
timtsj / gist:c57d0d659db5eac3aec5405de98431c8
Last active September 22, 2017 03:29 — forked from jsidhu/gist:766e4e85193f89c94640495959eb5620
Curl post to zabbix api (api_jsonrpc.php)
curl -i -X POST -H 'Content-Type: application/json-rpc' -d '{"jsonrpc":"2.0","method":"hostgroup.get", "params":{"output":["groupid", "name"]},"id":3,"auth":"2fc44689924341bc5b589d303cab8f1a"}' http://IP/zabbix/api_jsonrpc.php