Skip to content

Instantly share code, notes, and snippets.

View davidwong's full-sized avatar

David Wong davidwong

View GitHub Profile
public class MessagePagingSource extends RxPagingSource<Integer, Message> {
private MessageRepository messageRepository;
// the initial load size for the first page may be different from the requested size
private int initialLoadSize;
public MessagePagingSource(MessageRepository messageRepository) {
this.messageRepository = messageRepository;
}
@davidwong
davidwong / ErrorLogger-release.java
Created March 21, 2019 08:31
Example code for blog post: Crashlytics and Android: Clean Way to Use Custom Crash Reports?
import com.crashlytics.android.Crashlytics;
public class ErrorLogger extends LoggerWrapper {
public ErrorLogger(Class clazz) {
super(clazz);
}
public ErrorLogger(String className) {
super(className);
@davidwong
davidwong / ErrorReport.java
Last active March 21, 2019 10:02
Example code for blog post: Crashlytics and Android: Clean Way to Use Custom Crash Reports?
/**
* Attempt at generic non-fatal error report, modelled on Crashlytics error reporting methods.
*/
public class ErrorReport {
private String id; // could be user ID, for instance
private final Map<String, String> stateString;
private final Map<String, Boolean> stateBool;
private final Map<String, Integer> stateInt;
private final Map<String, Double> stateDouble;
@davidwong
davidwong / 01_RecyclerViewIdlingResourceTest.java
Created February 3, 2018 23:17
RecyclerView update Idling Resource example code
@RunWith(AndroidJUnit4.class)
public class RecyclerViewIdlingResourceTest {
@Rule
public ActivityRule<MainActivity> activityRule = new ActivityRule<MainActivity>(MainActivity.class);
// number of items in the original list
int allItemsCount = ...;
// number of items after the list has been filtered
@davidwong
davidwong / AndroidMockStaticMethod.java
Last active November 24, 2017 11:31
Example code for blog post: Mocking Static Methods in Android: Let's Wrap it up.
// Example 1 - Test that fails
public class ClassUnderTest {
public String methodUnderTest(String str)
{
if (PhoneNumberUtils.isGlobalPhoneNumber(str))
{
return "yes";
}
@davidwong
davidwong / Dockerfile for JRebel and Tomcat
Created May 27, 2015 10:39
Dockerfile for adding JRebel to a Tomcat image
FROM tomcat:8-jre8
MAINTAINER "David Wong"
RUN mkdir /jrebel
ADD jrebel.jar /jrebel/
ENV CATALINA_OPTS="-javaagent:/jrebel/jrebel.jar -Drebel.remoting_plugin=true"
@davidwong
davidwong / fig.yml
Created January 30, 2015 12:14
Fig YAML for backing up a Docker data volume container for Jenkins
# Backup a data volume container for Jenkins
backup:
image: busybox
command: tar cvf /backup/jenkins-backup.tar /var/jenkins_home
volumes:
- .:/backup
@davidwong
davidwong / Dockerfile for Jenkins data container
Last active August 29, 2015 14:14
Dockerfile for creating a data volume container for Jenkins
# Create a data volume container for Jenkins config and data
FROM jenkins
VOLUME /var/jenkins_home
# run a do-nothing command
CMD ["true"]