Posts

Couchbase Golang "failed to get query provider: not connected to cluster | {"statement":"*"}"

Image
Go (also known as Golang) is an open source programming language developed by Google Couchbase is a NoSQL database built for business-critical applications. While using Golang sdk 2.0 for Couchbase, I encountered an error "failed to get query provider: not connected to cluster | {"statement":"*"}" But this error had a strange behaviour, whenever I run any insert or update operation via Sdk function prior running  Cluster. Query (query, &gocb.QueryOptions{NamedParameters: params})  this error didn't occurred.  Running Just  Cluster. Query (query, &gocb.QueryOptions{NamedParameters: params})  after connection directly would get  "failed to get query provider: not connected to cluster | {"statement":"*"}" What I did to  tackle this is, prior to the Query function or immediately after running the connect function I ran a atomic function  collection. Binary (). Increment ( "serverUp"

RSA encryption in python 🐍

Image
RSA Encryption in Python 3.8 First install the dependencies ie pycryptodome library [pycryptodome 3.9.7]: pip3 install pycryptodome from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP import binascii keyPair = RSA.generate(3072) pubKey = keyPair.publickey() pubKey = pubKey.exportKey() pubKey = pubKey.decode('utf-8') privKey = keyPair.exportKey() privKey = privKey.decode('utf-8') key = RSA.importKey(pubKey) msg = b'A message for encryption' encryptor = PKCS1_OAEP.new(key) encrypted = encryptor.encrypt(msg) encrypted = binascii.hexlify(encrypted) encrypted = encrypted.decode('utf-8') print(encrypted) key = RSA.importKey(privKey) decryptor = PKCS1_OAEP.new(key) encrypted = encrypted.encode('utf-8') encrypted = binascii.unhexlify(encrypted) decrypted = decryptor.decrypt(encrypted) decrypted = decrypted.decode('utf-8') print('Decrypted:', decrypted)

Playing with dates in python

Image
Date in python In this tutorial you will be able to. Get current date/time Get weeks first and last date based on current date/time Get months first and last date based on current date/time First we will find current date time Step 1: Import necessary libraries (for above all task this is necessary step) from datetime import datetime, timedelta from calendar import monthrange Step 2: Get current date/time and just print it today = datetime.now() print(today) Now we will find weeks first and last date based on current date/time start = datetime.now() - timedelta(days=datetime.now().weekday()) end = start + timedelta(days=6) print(start) print(end) Now we will find months first and last date based on current date/time start = datetime.now().replace(day=1) end = datetime.now().replace(day=monthrange(datetime.now().year, datetime.now().month)[1]) print(start) print(end) Complete code: from datetime import datetime, timedelta from cale

Validate your ArrayAdapter with Espresso test case

Image
This tutorial is based on ArrayAdapter which returns custom object on getItem() function of the adapter. In this demo our custom object is as follows. (Note this things are in Recycler view or ArrayAdapter ) public static class HelloCustomList {         private String label;         private String subLabel;         public HelloCustomList (String label, String subLabel) {             this.label = label;             this.subLabel = subLabel;         }         public String getLabel() {             return label;         }         public void setLabel(String label) {             this.label = label;         }         public String getSubLabel() {             return subLabel;         }         public void setSubLabel(String subLabel) {             this.subLabel = subLabel;         }     } private List<HelloCustomList> mylist; public HelloCustomList getItem(int position) {      //This returns custom object instead of Predefined Type such as int string

Writing to external SD card in Android 5.0 and above

Android: EACCES (Permission denied) Writing files in Android system is easy with respect to internal storage, but when it comes to writing in external removable storage it may be a problem after android 4.4 release. Apart from android 6 permission we need to gain permission to write in external removable storage, as it can throw a EACCES (Permission denied) Error even if android.permission.WRITE_EXTERNAL_STORAGE is granted. So the following code will ensure that you can write in External media with the necessary permission apart from android.permission.WRITE_EXTERNAL_STORAGE. Call the following function to open the system dialog to gain access with external removable storage. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, 42); also the Activity Result Listener as follows: @Override     public void onActivityResult(int requestCode, int resultCode, Intent data) {         if (resultCode == RESULT_OK &&a

Get IP address of WIFI or Hotspot in Android

Image
The following function will get your job done public String getWifiApIpAddress() {     try {          for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {           NetworkInterface intf = en.nextElement();                 if((intf.getDisplayName().toLowerCase().contains("wlan")||intf.getDisplayName().toLowerCase().contains("ap"))) {                 for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {                     InetAddress inetAddress = enumIpAddr.nextElement();                     if (!inetAddress.isLoopbackAddress()&& (inetAddress.getAddress().length == 4)) {                         return inetAddress.getHostAddress();                     }                 }             }         }     } catch (SocketException ex) { }     return null; } NetworkInterface class represents a Network Interface made up of a n

Add/Set array in Firestore with the Firebase Admin SDK : Python 🐍

Image
The Admin SDK lets you interact with Firebase from privileged environments to perform actions like: ·          Read and write Realtime Database data with full admin privileges ·          Programmatically send Firebase Cloud Messaging messages using a simple, alternative approach to the FCM server protocols. ·          Generate and verify Firebase auth tokens. ·          Access Google Cloud Platform resources like Cloud Storage buckets and Firestore databases associated with your Firebase projects. ·          Create your own simplified admin console to do things like look up user data or change a user's email address for authentication. Currently Node.js, Java, Python, Go, C# are supported languages in Admin SDK. This tutorial demonstrates adding array in Firestore database through Admin SDK using python. Few things to note: ·           Your system needs   Python 2.7+ or 3.x . ·          You need to generate Firebase