Skip to content

Instantly share code, notes, and snippets.

@shkschneider
shkschneider / Log
Last active November 21, 2021 03:51
Android Log helper (automatic class, method and line) replacing android.util.Log
package me.shkschneider.skeleton.helper;
import android.text.TextUtils;
import android.util.Log;
/**
* Improved android.util.Log.
*
* Logs class and method automatically:
* [MyApplication onCreate():34] Hello, world!
@shkschneider
shkschneider / Android.pro
Last active May 1, 2018 13:00
ProGuard: obfuscate private fields with Android bug 78377
# <https://code.google.com/p/android/issues/detail?id=78377#c188>
# <https://stackoverflow.com/questions/30526173>
-keepattributes **
-keep class !android.support.v7.internal.view.menu.**, ** {
!private <fields>;
protected <fields>;
public <fields>;
<methods>;
}
#-dontpreverify
@shkschneider
shkschneider / Gson.getJsonElement
Last active August 29, 2015 14:22
GsonParsor.getJsonElement(JsonObject, String)
// Uses GSON library
// getJsonElement(jsonObject, "{errors}{email}[reasons:0]")
// Retrieves the first JsonElement of the JsonArray "reasons" of the JsonObject "email" of the JsonObject "errors"... in one line ;)
public static JsonElement getJsonElement(@NonNull final JsonObject jsonObject, final String string) {
// matches all
if (TextUtils.isEmpty(string)) {
return jsonObject;
}
// bad formats
@shkschneider
shkschneider / Code39Extended.java
Last active April 28, 2016 14:19
Code39Extended
public class Code39Extended {
protected Code39Extended() {
// Empty
}
private static final Character NULL = '\0';
// <https://en.wikipedia.org/wiki/Code_39#Full_ASCII_Code_39>
private static final HashMap<String, HashMap<String, Character>> EXTENDED = new HashMap<String, HashMap<String, Character>>() {
@shkschneider
shkschneider / brainwallet.py
Created September 18, 2017 08:43
Bitcoin brainwallet (mainnet)
#!/usr/bin/env python
#
# <https://github.com/arzzen/python-simple-brainwallet>
# <https://github.com/jgilmour/brainwallet-check>
# <https://bitcointalk.org/index.php?topic=84238.0>
# JeromeS
# ShkSchneider <https://github.com/shkschneider>
import base58
import binascii
class MainViewModel : ViewModel() {
private lateinit var users: MutableLiveData<List<User>>
fun getUsers(): LiveData<List<User>> {
if (!::users.isInitialized) {
users = MutableLiveData()
// TODO loading of the data (hopefully using coroutines)
users.postValue(arrayListOf(
User(login = "user.name1"),
private val viewModel by lazy {
ViewModelProviders.of(this).get(MainViewModel::class.java)
}
// inside onCreate()
viewModel.getUsers().observe(this, Observer {
display(it)
})
object DataManager {
fun dummy(context: Context) {
val db = MyDatabase.get(context)
db.users().insert(User(login = "user.name"))
db.projects().insert(Project(name = "project.name"))
db.notifications().insert(Notification(msg = "created"))
}
}
@Database(entities = [
User::class,
Project::class,
Notification::class
], version = 1, exportSchema = false)
abstract class MyDatabase : RoomDatabase() {
abstract fun users(): Users
abstract fun projects(): Projects
abstract fun notifications(): Notifications
companion object {
@UiThread
fun getUsers(context: Context): LiveData<List<User>> {
if (!::users.isInitialized) {
users = MutableLiveData()
users.postValue(MyDatabase.get(context).users().getAll())
GlobalScope.launch(Dispatchers.Main) {
val usersFromDb: List<User> = async(Dispatchers.IO) {
return@async MyDatabase.get(context).users().getAll()
}.await()
users.value = usersFromDb