Skip to content

Instantly share code, notes, and snippets.

View moopat's full-sized avatar

Markus Deutsch moopat

View GitHub Profile
@moopat
moopat / BatteryOptimizationUtil.java
Last active January 29, 2024 05:18
Many Android manufacturers cause trouble by implementing battery optimizations that cause apps to behave unexpectedly at runtime. This util class allows you to show a dialog to users having such phones and sends them to the settings screen where they can turn of battery optimizations for your app.
/*
* MIT License
*
* Copyright (c) 2018 Markus Deutsch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@moopat
moopat / GenymotionMessageTest.java
Last active January 21, 2016 06:49
Instead of "This message is longer than 57 characters, it has 107 characters, and is therefore not received completely." the genymotion device the test is run on receives the following message: "This message is longer than 57 characters, it has 107 cha"
package genytest;
import android.support.test.InstrumentationRegistry;
import android.test.InstrumentationTestCase;
import com.genymotion.api.GenymotionManager;
public class GenymotionMessageTest extends InstrumentationTestCase {
private GenymotionManager geny;
@moopat
moopat / SocialSecurityValidator.java
Last active November 9, 2021 11:57
Basic Validator for the Austrian Social Security Number.
package at.swe01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SocialSecurityValidator {
public static void main(String[] args) {
@moopat
moopat / PassportReader.java
Last active August 29, 2015 14:13
Read basic information from a passport's machine-readable zone.
package at.swe01;
public class PassportReader {
// Die beiden maschinenlesbaren Zeilen des Reisepasses.
// Die Prüfziffern sind in diesem Beispiel nicht relevant.
public static String line1 = "P<USAKELSO<<BOB<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
public static String line2 = "L0287498<3USA4010120M160505<<<<<<<<<<<<<<<<5";
public static void main(String[] args){
@moopat
moopat / LetterHistrogram.java
Last active August 29, 2015 14:13
Show the number of occurrences of every letter in a text entered by the user histogram-style.
package at.swe01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class LetterHistrogram {
public static int[] values;
@moopat
moopat / SearchInString.java
Last active August 29, 2015 14:13
Search for a String in another String and highlight occurrences by printing them in uppercase while all other characters are printed in lowercase.
package at.swe01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class SearchInString {
static String text = "Der Österreichische Hausärzteverband kann sich immer noch nicht mit der Elektronischen Gesundheitsakte (Elga) anfreunden.\nFür Hausärztepräsident Christian Euler ist es eine kranke Akte. Konkret bezieht sich die Kritik auf die lange \nBearbeitungszeit der Abmeldungserklärungen und auf die Nichteinhaltung des Zeitplans. Der Hausärzteverband rät den \nPatienten weiterhin, sich von Elga abzumelden, also das Opt-out wahrzunehmen, fordert aber eigentlich ein System, das auf \nFreiwilligkeit basiert.";
@moopat
moopat / CaesarCipher.java
Last active August 29, 2015 14:11
An example of how to create the Caesar Cipher of a text.
package at.swe01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CaesarCipher {
public static void main(String[] args) {