Skip to content

Instantly share code, notes, and snippets.

View mahdi-malv's full-sized avatar

Mahdi Malvandi mahdi-malv

  • Framna (Formerly Shape)
  • Copenhagen, Denmark
  • 23:57 (UTC +02:00)
View GitHub Profile
@mahdi-malv
mahdi-malv / pushe_web_snippet.html
Created September 10, 2020 12:15
Web push snippet to add pushe to your website
<script src="https://static.pushe.co/pusheweb.js"></script>
<script>
Pushe.init("app_id"); // App_id is retrieved via console.pushe.co
Pushe.subscribe({"showDialog":true,"showBell":false,"icon":"https://static.pushe.co/d/webpush/default-icon.png","title":"Get the latest news bro :D","content":"You want to be notified of every new event happenning to My site? Click OK then.","position":"top-center","direction":"ltr","acceptText":"OK, sure","rejectText":"Nuh","promptTheme":"pushe-prompt-theme2","mobilePosition":"top","dialogRetryRate":0});
</script>
@mahdi-malv
mahdi-malv / caster.py
Last active June 20, 2020 06:17
Download a course from caster.io using scrapy and youtube-dl
"""
Prerequisites:
1. Scrapy: python3 -m pip install scrapy
2. Youtube-dl: python3 -m pip install youtube-dl
(Use conda or miniconda for windows to install scrapy. Or use WSL and install python3 on it)
It's also possible to modify this to get other courses from caster.io or even other sites.
"""
from scrapy.spiders import Spider
from scrapy.crawler import CrawlerProcess
import youtube_dl
@mahdi-malv
mahdi-malv / cancelJob.java
Created December 28, 2019 13:36
cancelAndroidJob
public static void cancelJob(Context c, int jobId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
JobScheduler jobScheduler =
(JobScheduler) c.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.cancel(jobId);
}
}
// Call it like this
@mahdi-malv
mahdi-malv / maven_search.sh
Created September 30, 2019 07:08
Get maven repo details using cUrl
curl https://api.bintray.com/search/packages/maven\?g\=co.pushe.plus | python3 -mjson.tool | grep -i name
# Bintray REST: https://bintray.com/docs/api
# ?g is group
# python3 -mjson.tool will beautify the output json
# grep name will get only module names
@mahdi-malv
mahdi-malv / AdbCommands.md
Created July 1, 2019 09:06 — forked from Pulimet/AdbCommands
Adb useful commands list

Adb Server

adb kill-server
adb start-server 

Adb Reboot

adb reboot
adb reboot recovery 
@mahdi-malv
mahdi-malv / CustomToast.java
Created November 10, 2018 08:27
Custom Toast
public static void toast(Context context) {
Toast toast = Toast.makeText(context, "This is a Toast.", Toast.LENGTH_SHORT);
View toastView = toast.getView();
TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message);
toastMessage.setTextSize(19);
toastMessage.setTextColor(Color.BLACK);
toastMessage.setGravity(Gravity.CENTER);
toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_small, 0, 0, 0);// Add an icon to textView
toastMessage.setCompoundDrawablePadding(16); // Add padding to icon
toastView.setBackgroundColor(Color.WHITE);
@mahdi-malv
mahdi-malv / Screenshot.java
Created November 10, 2018 08:25
Take screenshot from screen and save it.
public static void takeScreenshot(Activity activity) {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/Screenshot_" + now + ".jpg";
// create bitmap screen capture
View v1 = activity.getWindow().getDecorView().getRootView();
@mahdi-malv
mahdi-malv / ListScrllingDetection.java
Created November 10, 2018 08:22
Detect scrolling up and down in a recyclerView
//تشخیص اسکرول کردن در لیست
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
//Scrolling down
} else if (dy < 0) {
//Scrolling up
}
@mahdi-malv
mahdi-malv / Convert.java
Created November 10, 2018 08:19
change dp or sp to px in android
public static float dpOrSpToPx(final Context context, final float dpOrSpValue) {
return dpOrSpValue * context.getResources().getDisplayMetrics().density;
}
@mahdi-malv
mahdi-malv / CollectionSort.java
Created November 10, 2018 08:18
Sort objects of the list by an attribute of them.
//Sort objects by a value
Collections.sort(songList, new Comparator<Song>(){
public int compare(Song a, Song b){
// Here song is a class that has some attrs including title.
// We want to sort songs by title
return a.getTitle().compareTo(b.getTitle());
}
});