Skip to content

Instantly share code, notes, and snippets.


PRADA Hsiung bearprada

  • Facebook
  • London, UK
Block or report user

Report or block bearprada

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Scope (large -> small) : Repository > Store > Factory > Others

Class Name Read Write Comment
store Y Y Provide cache machanism. imply signlton pattern
repository Y Y the same as store, but repository have more features rather than the read/write data, e.g, update/delete data, provide metadata to archive some business goal, e,g. latest update time, sorting the items based on some rules.
source Y N get the results when calling it
provider Y N provide the real implementation, we use it when we try to inject the dependencies(eliminate it)
factory Y N imply Factory pattern, reduce the complexity of creating objects
bearprada / TestDelayAndFlatMap.kt
Created Jan 2, 2019
Test Delay with FlatMap operator
View TestDelayAndFlatMap.kt
fun `test delay`() {
.flatMap { nums ->
val obs = mutableListOf<Observable<Int>>()
for (i in nums) {
obs.add(Observable.just(i).delay(i.toLong(), TimeUnit.MILLISECONDS))
.subscribe { println("$it") }
bearprada / Test.kt
Last active Jan 2, 2019
TakeUntil and TakeLast Behavior
View Test.kt
fun unsubsribeFirst() {
val input = PublishSubject.create<Int>()
val lifetime = CompletableSubject.create()
.subscribeUntil(lifetime) { println("$it") }
View InmobiGDPRConsentSample.kt
fun showGDPRConsentDialog() {
// Launch GDPR concent dialog
fun clickAgreeButton() {
fun clickDisagreeButton() {
public class GenericApp {
private DataSource<FacebookItem> mFbSource = new FacebookDataSource();
private DataSource<InstagramItem> mIgSource = new InstagramDataSource();
public DataSource<? extends Item> getDataSource(int section) {
switch (section) {
case 0:
return mIgSource;
case 1:
private Task<WeatherResult> queryWeather() {
final TaskCompletionSource<WeatherResult> task = new TaskCompletionSource<>();
.setResultCallback(new ResultCallback<WeatherResult>() {
public void onResult(@NonNull WeatherResult weatherResult) {
if (!weatherResult.getStatus().isSuccess()) {
task.setError(new IllegalStateException("Could not get weather."));
Giffle.GiffleBuilder builder = new Giffle.GiffleBuilder()
.size(320, 480) // otuput image size 320x480
.delay(100) // 100 ms
.file(File.createTempFile("PicCollage", "gif"));
final Giffle encoder =;
List<Bitmap> bitmaps = getOutputBitmaps(); // please impelemnt this block by youself
int[] colors = getTrainingPixels(bitmaps, pw, ph, totalFrame, frameMs); // this part is tricky
encoder.GenPalette(colors.length, colors);
for (Bitmap bm : bitmaps) {
* Background database for lookups of fittest color to represent.
private static List<Pair<Integer, String>> sBackgrounds = new ArrayList<>();
static {
// Color Tickets: ------------A-R-G-B-
sBackgrounds.add(new Pair<>(0xFF040404, "background_01.png"));
sBackgrounds.add(new Pair<>(0xFF040404, "background_02.png"));
sBackgrounds.add(new Pair<>(0xFFF2F2F2, "background_03.png"));
RxView.clicks(v.findViewById( -> "Event_Click_Detail_New_Image")
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Comment"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Map"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Report"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Share"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Like"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Share"))
.mergeWith(RxView.clicks(v.findViewById( -> "Event_Click_Detail_Story"))
.subscribe(s -> FlurryAgent.logEvent(s, false));
bearprada / sample_gson_deserializer
Created Jun 14, 2015
the sample code to use JsonDeserializer to handle the nest/complicate JSON format
View sample_gson_deserializer
* Example :
* input : {server: { result : { data: { a:1, b:2 }} }}
public class MyDeserializer implements JsonDeserializer<MyClass> {
public MyClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonElement j = json.getAsJsonObject().get("server").getAsJsonObject().get("result").getAsJsonObject().get("data");
MyClass clz = new MyClass();
You can’t perform that action at this time.