Skip to content

Instantly share code, notes, and snippets.

View gb103's full-sized avatar

Gaurav Bansal gb103

View GitHub Profile
@gb103
gb103 / createtable.py
Created January 6, 2021 10:52
Create People table
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
@gb103
gb103 / createdb.py
Created January 6, 2021 10:50
To create a DB
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to a SQLite database """
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
@gb103
gb103 / OpenCVInstall.txt
Created January 6, 2021 10:42
Python code for face matching/detection
pip install opencv-python
pip install opencv-python-headless
pip install opencv-contrib-python
@gb103
gb103 / facedata.py
Created January 6, 2021 10:12
1. Get the face images data from webcam
import cv2
import numpy as np
import sqlite3
#faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
faceDetect = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0);
def insertOrUpdate(Id,Name,Age,Gen,CR):
@gb103
gb103 / BasicUtility.kt
Created January 2, 2021 04:31
Basic utility methods
//To check if a module is already installed
val installedModules: Set<String> = splitInstallManager.installedModules
//To Uninstall modules
splitInstallManager.deferredUninstall(listOf("pictureMessages", "promotionalFilters"))
@gb103
gb103 / AccessInstallModule.kt
Created January 2, 2021 04:30
Access installed module
// Generate a new context as soon as a request for a new module
// reports as INSTALLED.
override fun onStateUpdate(state: SplitInstallSessionState ) {
if (state.sessionId() == mySessionId) {
when (state.status()) {
...
SplitInstallSessionStatus.INSTALLED -> {
val newContext = context.createPackageContext(context.packageName, 0)
// If you use AssetManager to access your app’s raw asset files, you’ll need
// to generate a new AssetManager instance from the updated context.
@gb103
gb103 / MyApplication.kt
Created January 2, 2021 04:29
Add entry into application class to install split compat features.
class MyApplication : SplitCompatApplication() {
...
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
// Emulates installation of future on demand modules using SplitCompat.
SplitCompat.install(this)
}
@gb103
gb103 / AndroidManifest.xml
Created January 2, 2021 04:27
manifest entry to support split compat modules
<application
...
android:name="com.google.android.play.core.splitcompat.SplitCompatApplication">
</application>
@gb103
gb103 / CancelRequest.kt
Created January 2, 2021 04:25
to cancel install request
SplitInstallManager
// Cancels the request for the given session ID.
.cancelInstall(mySessionId)
@gb103
gb103 / UserConfirmation.kt
Created January 2, 2021 04:23
To handle user confirmation on dynamic feature download dialog
override fun onSessionStateUpdate(state: SplitInstallSessionState) {
if (state.status() == SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION) {
// Displays a dialog for the user to either “Download”
// or “Cancel” the request.
splitInstallManager.startConfirmationDialogForResult(
state,
/* activity = */ this,
// You use this request code to later retrieve the user's decision.
/* requestCode = */ MY_REQUEST_CODE)
}