This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dk.ilios.jervis.ui | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: https://code.google.com/p/google-gson/issues/detail?id=440 | |
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { | |
@Override | |
public boolean shouldSkipField(FieldAttributes f) { | |
return f.getDeclaringClass().equals(RealmObject.class); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: https://developer.github.com/v3/rate_limit/ | |
# | |
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BAD: Store a global managed object | |
MyApp.GLOBAL_OBJECT = realm.objects(Person::class).first() | |
// BETTER: Copy data out into an unmanaged object | |
val person = realm.objects(Person::class).first() | |
MyApp.GLOBAL_OBJECT = Person(person.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A write can now happen between two queries | |
val results1: RealmResults<Person> = realm.objects(Person::class) | |
val results2: RealmResults<Person> = realm.objects(Person::class) | |
// Resulting in subsequent queries not returning the same result | |
results1.version() != results2.version() | |
results1.size != results2.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val jane = getJane() | |
CoroutineScope(Dispatchers.Main).launch { | |
// Run mapping/transform logic in the background | |
val flow: Flow<String> = jane.observe() | |
.filter { it.name.startsWith("Jane") } | |
.flowOn(Dispatchers.Unconfined) | |
// Before collecting on the UI thread | |
flow.collect { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val jane = getJane() | |
CoroutineScope(Dispatchers.Main).launch { | |
// Updates are observed using Kotlin Flow | |
val flow: Flow<Person> = jane.observe() | |
flow.collect { | |
// Listen to changes to the object | |
println(it.name) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CoroutineScope(Dispatchers.Main).launch { | |
// Create initial object | |
val jane = realm.write { | |
copyToRealm(Person("Jane")) | |
} | |
realm.write { | |
// Find latest version and update it | |
// Note, this always involves a null-check | |
// as another thread might have deleted the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CoroutineScope(Dispatchers.Main).launch { | |
// Write automatically happens on a background dispatcher | |
val jane = realm.write { | |
val unmanaged = Person("Jane") | |
// Add unmanaged objects | |
copyToRealm(unmanaged) | |
} | |
// Objects returned from writes are automatically frozen |
NewerOlder