Boost Ubuntu 16.04/17.10 Network Performance by Enabling TCP BBR

Install Linux Kernel 4.9 or Above
TCP BBR is supported by Linux since kernel version 4.9. Use the following command to check your Linux kernel version.

uname -r

Simply install the Hardware Enablement Stack (HWE), which provides newer kernel for Ubuntu LTS releases

sudo apt install --install-recommends linux-generic-hwe-16.04
sudo nano /etc/sysctl.conf
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
sudo sysctl -p

References
https://www.linuxbabe.com/ubuntu/enable-google-tcp-bbr-ubuntu

Combining text & image on a Button on Android

Just use a LinearLayout and pretend it’s a Button – setting background and clickable is the key:

<LinearLayout
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:drawable/btn_default"
    android:clickable="true"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="5dp"
        android:src="@drawable/image" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_margin="5dp"
        android:text="Do stuff" />
</LinearLayout>

References
https://stackoverflow.com/questions/1532876/android-combining-text-image-on-a-button-or-imagebutton

Set android shape color programmatically

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid android:color="#666666" />

    <size
        android:width="8dp"
        android:height="8dp" />
</shape>
            <ImageView
                android:id="@+id/imageViewStep2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="4dp"
                android:layout_marginRight="4dp"
                android:background="@drawable/ic_stepper"
                android:contentDescription="@string/step_2" />
        Drawable background = imageViewStep1.getBackground();

        if (background instanceof ShapeDrawable) {
            // cast to 'ShapeDrawable'
            ShapeDrawable shapeDrawable = (ShapeDrawable) background;
            shapeDrawable.getPaint().setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        } else if (background instanceof GradientDrawable) {
            // cast to 'GradientDrawable'
            GradientDrawable gradientDrawable = (GradientDrawable) background;
            gradientDrawable.setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        } else if (background instanceof ColorDrawable) {
            // alpha value may need to be set again after this call
            ColorDrawable colorDrawable = (ColorDrawable) background;
            colorDrawable.setColor(ContextCompat.getColor(this, R.color.md_blue_500));
        }

References
https://stackoverflow.com/questions/17823451/set-android-shape-color-programmatically

Maximum simultaneous connections on a mosquitto broker

nano /etc/sysctl.conf
fs.file-max = 999999
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_syncookies = 1
# this gives the kernel more memory for tcp
# which you need with many (100k+) open socket connections
net.ipv4.tcp_mem = 50576   64768   98152
net.core.netdev_max_backlog = 2500
nano /etc/security/limits.conf
*       soft    nofile  262144
*       hard    nofile  262144
*       soft    nproc  262144
*       hard    nproc  262144
cat /proc/sys/net/ipv4/ip_local_port_range
cat /proc/sys/kernel/threads-max
nano .bashrc
ulimit -t unlimited
ulimit -c unlimited
ulimit -a

References
https://lists.launchpad.net/mosquitto-users/msg00163.html

Detect when there is an Internet connection available on Android

In this method just current activity receive this event
Add to android Manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

In your activity, create a Broadcast Receiver:

private BroadcastReceiver networkStateReceiver=new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = manager.getActiveNetworkInfo();
        doSomethingOnNetworkChange(ni);
    }
};
@Override
public void onResume() {
    super.onResume();
    registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
}

@Override
public void onPause() {
    unregisterReceiver(networkStateReceiver);
    super.onPause();
}

References
https://stackoverflow.com/questions/6169059/android-event-for-internet-connectivity-state-change