Skip to content

Instantly share code, notes, and snippets.

@li2
li2 / usbreset.c
Created March 20, 2018 11:51
usbreset -- send a USB port reset to a USB device, compile using: gcc -o usbreset usbreset.c
/**
* usbreset -- send a USB port reset to a USB device
* Compile using: gcc -o usbreset usbreset.c
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
@li2
li2 / ThreeLevelExpandableListView.java
Created March 20, 2018 11:52
[A 3 level expandable list view] #tags: android-list
package net.stf.threelevelexpandablelistview;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
@li2
li2 / c.md
Last active May 6, 2018 11:49
Android Studio Tips #tags: tool

Alt+F1, Enter: to locate the current src file in project tree panel.

@li2
li2 / c.md
Last active May 6, 2018 11:42
Fix git merge conflict #tags: git

Merge conflict Close This pull request has conflicts.

You must resolve the conflicts by manually merging release/R1804 into this branch. After the conflicts are resolved you will be able to merge the pull request.

Step 1: Checkout the source branch and merge in the changes from the target branch. Resolve conflicts.

git checkout branch_name
git pull origin release/R1804
@li2
li2 / utc_time.java
Last active May 6, 2018 11:40
UTC #tags: java
public Date utcDate(String utcTimestamp) {
try {
String format = "yyyy-MM-dd'T'HH:mm:ss.SSS";
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.parse(utcTimestamp);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
@li2
li2 / TelsieDividerItemDecoration.java
Last active July 1, 2018 04:39
RecyclerView divider ItemDecoration recyclerView.addItemDecoration( new TelsieDividerItemDecoration(ContextCompat.getDrawable(getContext(), R.drawable.telsie_divider), 32, 16)); #tags: android-list
public class TelsieDividerItemDecoration extends RecyclerView.ItemDecoration {
private Drawable mDivider;
private int mLeftMargin;
private int mRightMargin;
/**
*
* @param divider
* @param left left margin of the divider, unit DP
@li2
li2 / crash1.sh
Last active June 17, 2018 09:21
Rx Crash #tags: rx
06-01 14:57:31.988 17036-17036/com.telstra.wifidiag.pvt.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.telstra.wifidiag.pvt.debug, PID: 17036
java.lang.IllegalStateException: Activity has been destroyed
at android.support.v4.app.r.a(SourceFile:1864)
at android.support.v4.app.j.a(SourceFile:649)
at android.support.v4.app.j.b(SourceFile:609)
at android.support.v4.app.n.show(SourceFile:143)
at com.telstra.mobile.android.home.dashboard.tabs.home.FeedbackDialog.a(SourceFile:32)
at com.telstra.mobile.android.home.dashboard.tabs.home.k$11.call(SourceFile:410)
at rx.Completable$28.onCompleted(SourceFile:1933)
@li2
li2 / crash.sh
Last active June 17, 2018 09:21
Caused by: rx.exceptions.MissingBackpressureException #tags: rx
06-15 16:36:18.882 12542-12542/com.telstra.wifidiag.mock.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.telstra.wifidiag.mock.debug, PID: 12542
rx.exceptions.OnErrorNotImplementedException
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
at rx.internal.operators.OperatorZip$Zip$InnerSubscriber.onError(OperatorZip.java:313)
at rx.internal.operators.OperatorZip$Zip$InnerSubscriber.onNext(OperatorZip.java:321)
@li2
li2 / c.md
Created June 17, 2018 09:23
Upstream vs Downstream #tags: rx-terms
           upstream                           downstream
source <------------- operator (parameters) -------------> consumer/further operators

Some operators have multiple upstreams such as zipWith which is an instance convenience for zip(upstream1, upstream2, func2).

@li2
li2 / c.md
Last active July 1, 2018 05:44
UT will failed and throws "rx.exceptions.OnErrorNotImplementedException: Stub" when .subscribe() didn't handle the error. #tags: android-rx

Presenter

mView.onFeaturesUsedUpdated().subscribe(new Action1<List<String>>() {
    @Override
    public void call(List<String> features) {
        AppLogger.d(TAG, "onFeatureSelected " + features.toString()); // 
        mDataset.featuresUsed = features;
    }
});