Skip to content

Instantly share code, notes, and snippets.

View rishadbaniya's full-sized avatar
:shipit:
Busy hacking myself

Rishad Baniya rishadbaniya

:shipit:
Busy hacking myself
View GitHub Profile
@rishadbaniya
rishadbaniya / DpToPxAndPxToDp
Created January 4, 2021 03:07 — forked from laaptu/DpToPxAndPxToDp
Android convert dp to px and vice versa
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);
@rishadbaniya
rishadbaniya / DpToPxAndPxToDp
Created January 4, 2021 03:07 — forked from laaptu/DpToPxAndPxToDp
Android convert dp to px and vice versa
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);
@rishadbaniya
rishadbaniya / answer.md
Last active September 18, 2021 08:05
How to URL encode a SHA1 "buffer" provided by crypto method in Node JS?

URLencode a SHA1 "buffer" provided by crypto method in NODE JS :

First of, lets talk about how i got motivation to write this guide in the form of "gist"?

So one day, god(literally : 😂) sent me a message : "Hey Rishad, go and build your own torrent client (an application that downloads torrents)". I took it as an order from god, and i started to explore possible ways to build it. After many !hours but minutes of google searches, i got myself stuck reading a blog/article/guide written by ALLEN KIM and the reference blogs mentioned there, which were written by other developers.

Link : https://allenkim67.github.io/programming/2016/05/04/how-to-make-your-own-bittorrent-client.html

I was reading it thoroughly and on the way i found that in order to get "peer list", i must make a "GET" request to a tracker URL which was stored in "announce" field of bencode encoded torrent file. I found that the params of GET request's URL /?xyz=abc&mno=pqr must have one of them as a field named "hash_value" and its va