Skip to content

Instantly share code, notes, and snippets.

Avatar

Markus Deutsch moopat

View GitHub Profile
@moopat
moopat / BatteryOptimizationUtil.java
Last active Aug 29, 2021
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.
View BatteryOptimizationUtil.java
/*
* 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 Jan 21, 2016
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"
View GenymotionMessageTest.java
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 Aug 29, 2015
Basic Validator for the Austrian Social Security Number.
View SocialSecurityValidator.java
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 Aug 29, 2015
Read basic information from a passport's machine-readable zone.
View PassportReader.java
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 Aug 29, 2015
Show the number of occurrences of every letter in a text entered by the user histogram-style.
View LetterHistrogram.java
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 Aug 29, 2015
Search for a String in another String and highlight occurrences by printing them in uppercase while all other characters are printed in lowercase.
View SearchInString.java
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 Aug 29, 2015
An example of how to create the Caesar Cipher of a text.
View CaesarCipher.java
package at.swe01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CaesarCipher {
public static void main(String[] args) {