Skip to content

Instantly share code, notes, and snippets.

Christian Melchior cmelchior

View GitHub Profile
cmelchior / AndroidManifest.xml
Last active Dec 25, 2015
Adding support for ".res-auto" in ContentProvider authorities in AndroidManifest.xml. This replaces ".res-auto" with the current package name, making it possible to install multiple build variants on the same devices without getting [INSTALL_FAILED_CONFLICTING_PROVIDER]
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
android:versionName="@string/client_info" >
<!-- ... -->
cmelchior /
Created Feb 20, 2014
Bash script for pulling APK's from Non-rooted android devices
if test $# -lt 1 ; then
echo "Usage: <GooglePlayPackageName>"
exit 1
APK_PATH=`adb shell pm list packages -f -3 | grep $PACKAGE | cut -d'=' -f 1 | cut -c9-`
echo "Pulling $APK_PATH from device"
echo `adb pull ${APK_PATH} ./${PACKAGE}.apk`
cmelchior / material_design_colors.xml
Last active Aug 29, 2015
Material design colors reference sheet, credit: Marcel Ulbrich
View material_design_colors.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Name this file “colors.xml” -->
<!-- Then place it in your project's “res/values/” folder. -->
<!-- Created by Marcel Ulbrich -->
<!-- -->
<!-- Updated 2014-12-09 to reflect Google's latest changes -->
<color name="red_050">#FFEBEE</color> <!-- Use with black text -->
<color name="red_100">#FFCDD2</color> <!-- Use with black text -->
cmelchior /
Created Apr 9, 2015
Realm, GSON and primitive JSON arrays
// Make a custom Gson instance, with a custom TypeAdapter for each wrapper object.
// In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer>
Type token = new TypeToken<RealmList<RealmInt>>(){}.getType();
Gson gson = new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
cmelchior /
Last active Jan 13, 2019
Serialize Realm objects to JSON using GSON
// GSON can parse the data.
// Deserialization:
// Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects.
// To work around this, use the ExclusionStrategy below or downgrade to 1.7.1
// See more here:
// Serialization:
// <Type>RealmProxy objects are created by the Realm annotation processor. They are used to control
// access to the actual data instead of storing them in fields and it is therefore them we need to register a
cmelchior /
Last active Dec 1, 2018
Using Parceler 1.0.3 with Realm
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
public Bar itemFromParcel(Parcel parcel) {
cmelchior /
Created May 3, 2016
Example of using Realm.waitForChange()/Realm.stopWaitForChange()
// Create a background thread
RealmThread t = new RealmThread(realmConfig, new RealmRunnable() {
public void run(Realm realm) {
do {
// Do some work once, and every time the Realm changes
} while (realm.waitForChange())
cmelchior /
Created May 4, 2016
Helper class for writing Lint Checks for Android
* Copyright 2016 Realm Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
cmelchior / github_issue_rankings.rb
Last active Mar 23, 2018
Small ruby script that will rank all Github issues in a repo according to which is the most popular
View github_issue_rankings.rb
#!/usr/bin/ruby -w
# This script will analyze a Github repo and try to rank all open issues with regard to popularity.
# WARNING: This script will run quite a few HTTP requests against Github to do this analysis. At least 1 pr. issue.
# The current limit on Github is 5000 requests pr. hour:
# Usage: ./ruby github-issue-rankings.rb <github_user/repo> <github_api_access_token>
# Example: ruby github_issue_rankings.rb realm/realm-java $GITHUB_ISSUE_RANKINGS_ACCESS_TOKEN
# The algorithm for ranking issues are the following:
cmelchior /
Created Mar 17, 2017
Load new Realm file from assets when a migration is required
public Realm loadAssetFileOnMigration() {
// TODO Don't re-create this every time
RealmConfiguration config = new RealmConfiguration.Builder()
.schemaVersion(2) // Bumping the schema because new app
Realm realm;
try {
realm = Realm.getInstance(config);
You can’t perform that action at this time.