Skip to content

Instantly share code, notes, and snippets.

View banasiak's full-sized avatar

Richard Banasiak banasiak

View GitHub Profile
@banasiak
banasiak / SemanticVersionComparator.kt
Last active May 10, 2022 04:15
A version string comparator that adheres to the SemVer standard (https://semver.org)
class SemanticVersionComparator: Comparator<String> {
private val nonDigits: Regex = Regex("[^\\d.]")
private val onPeriods: Regex = Regex("\\.")
override fun compare(currentVersion: String, otherVersion: String): Int {
// remove everything after the "+" character, sanitize non-digits, then split on the periods
val semVerCurrent: MutableList<String> = currentVersion
.substringBefore("+")
@banasiak
banasiak / 10-monitor.conf
Created March 11, 2018 02:36
Dell XPS 15 4K Monitor Resolutions (Fedora)
Section "Monitor"
Identifier "eDP-1"
Modeline "3840x2160_60.00" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync
Modeline "2560x1440_60.00" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync
Modeline "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
Option "PreferredMode" "2560x1440_60.00"
EndSection
Section "Screen"
Identifier "Screen0"
@banasiak
banasiak / deeplink.sh
Last active March 7, 2018 18:18
Script to send a deep link to an Android app.
@banasiak
banasiak / DefaultUncaughtExceptionHandler.java
Created January 16, 2018 22:38
Absolute last chance to log an exception and it's stack trace to logcat for an Android app.
public class MyApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
if(BuildConfig.DEBUG) {
final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(
(t, e) -> {
Timber.wtf(e);
handler.uncaughtException(t, e);
@banasiak
banasiak / KotlinEchoServer.kt
Created November 23, 2017 17:28
An example echo server written in Kotlin.
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.net.ServerSocket
import kotlin.concurrent.thread
const val SERVER_PORT = 1337
fun main(args: Array<String>) {
@banasiak
banasiak / ReflectiveToString.java
Last active October 5, 2017 17:06
Create a string representation of an object. This will include all fields that are not transient or static. The returned string will be in the form of `full_class_name{fieldName='value'}` This will also include all super types values as well in the string.
/**
* Create a string representation of an object. This will include all fields that are not
* transient or static. The returned string will be in the form of `full_class_name{fieldName='value'}`
* This will also include all super types values as well in the string.
*
* @param object The object to get a string representation from.
* @return String representation of the object.
*/
public static String toString(Object object) {
Class<?> aClass = object.getClass();

Keybase proof

I hereby claim:

  • I am banasiak on github.
  • I am banasiak (https://keybase.io/banasiak) on keybase.
  • I have a public key ASAtGYlAVxLbw5TUVjCfsntUqX9FE5y6u0BeQYjWx8Op0wo

To claim this, I am signing this object:

@banasiak
banasiak / timberm
Last active March 24, 2017 20:25
Android Studio live code template for logging a method name and its arguments using Timber
Timber.d($content$);
content:
groovyScript("def params = _2.collect {it + ' = [%s]'}.join(', '); def params2 = _2.collect {it}.join(', '); return '\"' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\"' + (params2.empty ? '' : ', ' + params2)", methodName(), methodParameters())
Applicable in Java: statement
package com.banasiak.android.example.api.parser;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
@echo off
echo Create Backup copies of the original notepad.exe
copy C:\Windows\notepad.exe C:\Windows\notepad.exe.bak
copy C:\Windows\System32\notepad.exe C:\Windows\System32\notepad.exe.bak
copy C:\Windows\SysWOW64\notepad.exe C:\Windows\SysWOW64\notepad.exe.bak
echo Take Ownership of the files
takeown /F C:\Windows\notepad.exe /A
takeown /F C:\Windows\System32\notepad.exe /A
takeown /F C:\Windows\SysWOW64\notepad.exe /A