Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Aveek NsAveek

🏠
Working from home
View GitHub Profile
@NsAveek
NsAveek / StateViewHolder.kt
Last active Mar 4, 2019
A view holder class with State design pattern implemented
View StateViewHolder.kt
class StateViewHolder(binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
lateinit var viewModel: BaseViewModel
fun bind(info: Pair<Pair<Boolean, String>, Int>, remaining: Int) {
@DrawableRes val icon: Int
val stateContext: BaseStateContext
if (AppFlavor.country == Country.Bangladesh) {
icon=R.drawable.ico_state_1
@NsAveek
NsAveek / fileReader.py
Created Dec 8, 2018
(Python) Find out the genbank, fasta and cluster format from the file and print the nucleotides
View fileReader.py
import os.path
import re
def is_cluster_format(line):
cluster_format_matcher = re.compile(clusterFormat)
cluster_format_result = cluster_format_matcher.findall(line)
return cluster_format_result.__len__() > 0
@NsAveek
NsAveek / GetRealPathFromURI.kt
Created Nov 9, 2018
Pass an Uri and get the actual path of the file in device
View GetRealPathFromURI.kt
fun getRealVideoPathFromURI(contentResolver: ContentResolver,
contentURI: Uri): String? {
val cursor=contentResolver.query(contentURI, null, null, null, null)
if (cursor == null)
return contentURI.path
else {
cursor.moveToFirst()
val idx=cursor.getColumnIndex(MediaStore.Video.VideoColumns.DATA)
try {
return cursor.getString(idx)
@NsAveek
NsAveek / UploadFile.kt
Created Oct 20, 2018
Upload file using Retrofit
View UploadFile.kt
private void uploadFile(File file){
RequestBody videoBody = RequestBody.create(MediaType.parse("video/"), file);
MultipartBody.Part vFile = MultipartBody.Part.createFormData("upload-file", file.getName(), videoBody);
UploadVideoService videoService = RetrofitClientInstance.Companion.getRetrofitInstance();
Call<ResponseBody> serverCom=videoService.uploadVideo(vFile);
serverCom.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
ResponseBody body = response.body();
try {
@NsAveek
NsAveek / GetFile.java
Last active Nov 9, 2018
Select Video Using Intent
View GetFile.java
public void getFile(View view) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_CODE_PICKER);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@NsAveek
NsAveek / DatabaseRepository
Created Oct 12, 2018
The Database class with Repository pattern
View DatabaseRepository
class DatabaseRepository : IStoreRepository {
private var realm: Realm = Realm.getDefaultInstance()
override fun saveStudentData(student: Student): Boolean {
try {
realm.executeTransaction {
realm.insertOrUpdate(student)
}
} catch (e: Exception) {
@NsAveek
NsAveek / IRepository
Created Oct 12, 2018
Repository interface
View IRepository
interface IStoreRepository {
fun saveStudentData(student: Student) : Boolean
fun updateStudentData(student: Student) : Int
fun deleteStudentData (student: Student) : Boolean
}
@NsAveek
NsAveek / Builder
Created Sep 11, 2018
Builder Pattern example
View Builder
public class Student {
private String name;
private String address;
private String email;
private String phoneNumber;
private String passportNumber;
private int age;
View EnumFields.java
public enum EnumFields {
PRIMARY("INTEGER PRIMARY KEY"),
INTEGER("INTEGER"),
TEXT("TEXT");
// Add more types
private String fields;
Fields(String fields){
this.fields = fields;
}
public String getField(){
@NsAveek
NsAveek / DatabaseInfo.java
Last active Aug 19, 2018
Database tables
View DatabaseInfo.java
public class DatabaseInfo {
// Database Tables
public static String DATABASE_TABLE_A = "table_A";
public static String DATABASE_TABLE_A_DETAILS = "table_a_details";
public static String DATABASE_TABLE_B = "table_B";
public static String DATABASE_TABLE_B_DETAILS = "table_b_details";
}