Posts

\r issue in shell script

 When we create a shell script in windows machine. It add \r\n as end of line, when we move this script to unix machine then we get issue for \r character. In order to resolve this issue, please follow any of of below options.  1. replace \r character in shell script with blank using sed command in unix.  2. for small file recreate the file in unix.  3. if you have notepad++ then go to Edit -> EOL conversion -> Unix this will change the end of line character.  Thank you!!!

Reading QR code in Python

We learned how to create QR code in last blog. Now, let's see how we can read these QR code using python.  Package Required:     pip install opencv-python We can use below code to read a QR code image.  import cv2 det = cv2 .QRCodeDetector() img_1 = cv2 .imread( "sample_1.png" ) val_1 , _ , _ = det .detectAndDecode( img_1 ) print ( "Sample_1 Data =" , val_1 ) if image is not in gray or RGB. it might not able to decode, For example I created a QR code with fill color as yellow and back color as black and it couldn't decode this code. One more step I tried to read this image in gray scale, picture was not very clear. May be due to this it couldn't decode.  After changing fill color as purple, green or red and back color as white, message was decoded successfully.  In order to read image in gray scale and save using cv2, we can use below code.  img_2 = cv2 .imread( "sample_2.png" , 0 ) cv2 .imwrite( 'gray_sample2.png' , img_2 ) Thank y

Create QR code using qrcode in python

We need to install qrcode module to create QR code using python. Use below command to install using pip. pip install qrcode  Now let's check below code to create a png image with some sample data.  import qrcode msg = "Welcome to Code Adhyayana!!!" img_qr = qrcode .make( msg ) img_qr .save( 'sample.png' ) Error: ModuleNotFoundError: No module named 'Image' if you are getting above module not found error, while executing this code then you need to install PIL module using below command: pip install Pillow for conda users: conda install -c anaconda Pillow after installing Pillow, re-execute the code, this time you should get sample.png image with QR code. We can scan and validate if it's correct or not.  Let's check how we can create qrcode with custom color and size.  import qrcode qr_obj = qrcode .QRCode( box_size = 20 ,                 border = 2 ) qr_obj .add_data( "Welcome to Code Adhyayana" ) qr_img = qr_obj .make_image( fill_

Read File using Relative Path

  file_name = "..//..//data//data//test.txt" This code will move 2 back folder then look for data//data/text.txt file. This way you can navigate to relative folder while reading any file in python.

Create and read QR code

QR codes are machine readable 2 dimensional pixelated barcodes which can be used to store some information.  QR = quick response Let see some of usecase.  1. online payments 2.  check hotel menu, 3. wifi password sharing  People carry their mobile all the time, it's part of life now. QR provide option to scan a code and get information in your mobile. Is it cool.  Steps to generate QR code.  Install qrcode package using below command.  pip install qrcode Code to create QR code.  import qrcode qr_code = qrcode.make('Hi, I am from Code Adhyayana team.'  ) qr_code.save('intro_qr.png') Additional properties of qrcode module. 1. Version : there are 40 version available, starting from smallest 1 to largest 40. 2. error_correction : ERROR_CORRECT_L, M, Q, H 3. box_size 4. border 5. add data 6. make 7 . make image qr_object = qrcode.QRCode(     version=2,     error_correction=qrcode.constants.ERROR_CORRECT_L,     box_size=12,     border=8, ) qr_object.add_data("Hi, I a

Git Command

1. git clone -b branchName url Copy url from git clone option from repository.  2. git status  To check if git there is any new file or not and basic git status.  3. git branch  To get details about git branches. If star ⭐ is in front then it's currently points to that branch.  4. git branch branchName  Create a new branch.  5. git checkout branchName Points to branch name specified.  6. git add .  All the files from local to staging.  7. git add fileName Add a particular file. 8. git commit -m "first commit" Commit all files in staging so that it will be ready for migration. 9. git config --get remote.origin.url Just to verify if code is pointing to right repository.  10. git push -u origin branchName Move code to git repository. 11. Create a pull request to merge code from branchName to master branch. Error 1. Some of the files are not moving to staging area in git add .  Files were in state modified/ Untracked  Structure was like below. Main folder:     - .git      - s

Virtual Environment for Python

Image
How to Create Virtual Environment for Python Development? First we need to understand that why do we need virtual environment. It helps us to create isolated environment for python development.  Let's try to understand problem without virtual environment. You are working on two different project say Project A and Project B. Now Project A need pyarrow version 4.0.1 and Project B need 3.0.0 as dependency. If you have only one environment for development then you can keep one of them. Now using virtual environment we can have multiple environment let's say env 1 for project A and env 2 for project B, this way both of them will have their requirement version of package.  Steps to create a virtual environment in Windows Machine. Step 1. Install virtualevn using below command              >  Pip install virtualenv  Step 2. Create a virtual environment "myenvA"            > virtualenv myenvA Step 3. Activate virtual environment.            >  myenvA\Scripts\activate