Skip to content

Instantly share code, notes, and snippets.

View NsAveek's full-sized avatar
🏠
Working from home

Aveek NsAveek

🏠
Working from home
View GitHub Profile
@NsAveek
NsAveek / BaseContext.kt
Created March 2, 2019 16:28
A class that contains the Base Context and interfaces for handling the States
class BaseContext(private var state: IBaseState) {
fun getState(): IBaseState {
return state
}
}
interface IBaseState {
fun setPackageExpiryVisibility()
}
interface IState1 : IBaseState {
@NsAveek
NsAveek / StateClass.kt
Last active March 2, 2019 16:24
State Classes that extends from Base interface
class State1 : IState1 {
var featureAvailable = false
private set
get() = field
var totalFeature = ""
private set
get() = field
var consumedFeature = ""
private set
@NsAveek
NsAveek / fileReader.py
Created December 8, 2018 15:08
(Python) Find out the genbank, fasta and cluster format from the file and print the nucleotides
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 / GetFile.java
Last active November 9, 2018 10:09
Select Video Using Intent
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 / GetRealPathFromURI.kt
Created November 9, 2018 06:24
Pass an Uri and get the actual path of the file in device
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 / DatabaseRepository
Created October 12, 2018 04:41
The Database class with Repository pattern
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 October 12, 2018 04:40
Repository interface
interface IStoreRepository {
fun saveStudentData(student: Student) : Boolean
fun updateStudentData(student: Student) : Int
fun deleteStudentData (student: Student) : Boolean
}
@NsAveek
NsAveek / Builder
Created September 11, 2018 15:19
Builder Pattern example
public class Student {
private String name;
private String address;
private String email;
private String phoneNumber;
private String passportNumber;
private int age;
@NsAveek
NsAveek / DatabaseHelper.java
Created August 19, 2018 05:11
The magic method createTable() to handle creation of the given fields automatically
private void createTable(String tableName, Map<String, String> fields, SQLiteDatabase db) {
Iterator iter = fields.entrySet().iterator();
String columns = "(";
Log.d("column", columns);
int counter = 1;
while (iter.hasNext()) {
Map.Entry mEntry = (Map.Entry) iter.next();
columns += mEntry.getKey() + " " + mEntry.getValue();
if (counter == fields.size()) {
columns += ")";
@NsAveek
NsAveek / DatabaseInfo.java
Last active August 19, 2018 05:24
Database tables
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";
}