Persian Text in Matplolib

from bidi.algorithm import get_display
import arabic_reshaper
def make_farsi_text(x):
reshaped_text = arabic_reshaper.reshape(x)
farsi_text = get_display(reshaped_text)
return farsi_text
xlabel = "یک محور همینجوری"
ylabel = "یک محور دیگه همینجوری"
title = "یک نمودار همینجوری"
 
 
plt.scatter(X[:,0],X[:,1],c = y, cmap = 'spring')
plt.xlabel(make_farsi_text(xlabel),fontsize = 15)
plt.ylabel(make_farsi_text(ylabel),fontsize = 15)
plt.title(make_farsi_text(title) , fontsize = 20)
plt.show()
font_title = {'family': 'B Farnaz',
'color':  'red',
'weight': 'normal',
'size': 30,
}
font_labels = {'family': 'B Nazanin',
'color':  'black',
'weight': 'normal',
'size': 20,
}
 
plt.scatter(X[:,0],X[:,1],c = y, cmap = 'spring')
plt.xlabel(make_farsi_text(xlabel),fontdict = font_labels)
plt.ylabel(make_farsi_text(ylabel),fontdict = font_labels)
plt.title(make_farsi_text(title) ,fontdict = font_title)
plt.show()

References
http://imuhammad.ir/2017/09/23/farsi-plots-python/
https://pypi.org/project/python-bidi/
https://github.com/mpcabd/python-arabic-reshaper

How to get data received in Flask request

from flask import request

For URL Query parameter, use request.args

search = request.args.get("search")
page = request.args.get("page")

For Form input, use request.form

email = request.form.get('email')
password = request.form.get('password')

For data type application/json, use request.data

# data in string format and you have to parse into dictionary
data = request.data
dataDict = json.loads(data)

References
https://stackoverflow.com/questions/10434599/how-to-get-data-received-in-flask-request

Sort Java Strings in a Collection using Collator

           Collections.sort(parentList, new Comparator<ListParentAdapter.Parent>() {
                @Override
                public int compare(ListParentAdapter.Parent o1, ListParentAdapter.Parent o2) {

                    //return o1.getName().compareToIgnoreCase(o2.getName());

                    Locale locale=new Locale("fa","IR");
                    Collator collator= Collator.getInstance(locale);
                    return collator.compare(o1.getName(),o2.getName());
                }
            });

References
http://tutorials.jenkov.com/java-internationalization/collator.html
https://stackoverflow.com/questions/16949074/sorting-arabic-words-in-java

Run SoftEther VPN Client on Linux

sudo vpnclient start

Run SoftEther VPN Client Manager and configure it, then connect

sudo dhclient vpn_vpn
sudo ip route add 160.235.81.120/32 via 192.168.1.1 dev wlp3s0
sudo ip route del default via 192.168.1.1 dev wlp3s0

Then change the dns in resolv.conf

Detect when the last item is shown on RecyclerView

public abstract class OnVerticalScrollListener
        extends RecyclerView.OnScrollListener {

    @Override
    public final void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        if (!recyclerView.canScrollVertically(-1)) {
            onScrolledToTop();
        } else if (!recyclerView.canScrollVertically(1)) {
            onScrolledToBottom();
        } else if (dy < 0) {
            onScrolledUp();
        } else if (dy > 0) {
            onScrolledDown();
        }
    }

    public void onScrolledUp() {}

    public void onScrolledDown() {}

    public void onScrolledToTop() {}

    public void onScrolledToBottom() {}
}

Useful info

visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

References
https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview