<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tharuja Sandeepanie on Medium]]></title>
        <description><![CDATA[Stories by Tharuja Sandeepanie on Medium]]></description>
        <link>https://medium.com/@kmtsandeepanie?source=rss-55a4826be761------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6od5Y_gfBDUwrqst4DUd7g.jpeg</url>
            <title>Stories by Tharuja Sandeepanie on Medium</title>
            <link>https://medium.com/@kmtsandeepanie?source=rss-55a4826be761------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:45:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kmtsandeepanie/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Set up multiple Firebase environments in Flutter]]></title>
            <link>https://kmtsandeepanie.medium.com/set-up-multiple-firebase-environments-in-flutter-9f88bc284454?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f88bc284454</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flavor]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 20:32:06 GMT</pubDate>
            <atom:updated>2022-06-20T16:43:58.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*9CW-mMozre-AaUF6P-Pv-w.png" /></figure><p>When building a mobile app, it is a good practice to configure our application for different development environments or release types. Most developers use separate environments such as,</p><ul><li>Dev environment — for development purposes.</li><li>QA environment — for testing purposes.</li><li>Production environment — for end-users.</li></ul><p>If you’re using Firebase in your Flutter project, we need to separate the Firebase project for each environment so that when we work with our environments, the relevant Firebase project must be connected to the corresponding environment.</p><h3>Creating Flavors for Flutter</h3><p>In Flutter, configuring different environments can be achieved through <strong>Flutter</strong>-<strong>flavors</strong>. Here, ‘flavor’ means ‘version’. We create multiple flavors in our mobile app, meaning that we build different versions of our app with different configuration options.</p><p>Through this article, I will explain both Android and iOS configurations of using these flavors. Before starting, let’s assume we need to configure 2 environments as <strong>prod</strong> and <strong>dev</strong> and our application Ids (bundle Id for iOS) for both environments are as follows:</p><ul><li><strong>prod</strong> environment: “com.example.tools.prod”</li><li><strong>dev</strong> environment: “com.example.tools.dev”</li></ul><h4>Step 1 - Firebase Configuration</h4><p>Create applications for iOS and Android in the Firebase console and download the <strong>google-services.json </strong>and <strong>GoogleService-Info.plist </strong>files for each Firebase project. Don’t forget to use the package names as defined above.</p><h4>Step 2- Set up Android configuration</h4><p>Android has a very straightforward method since flavors are already defined in their framework as <a href="https://developer.android.com/studio/build/build-variants#product-flavors"><strong>productFlavors</strong></a>.</p><p><strong>1</strong>- Open <em>android/app/build.gradle </em>file<em>. </em>Here inside the android block, add the below code. It indicates all the flavors (environments) you need to have and you can specify any extra options such as <em>applicationId, applicationIdSuffix, versionName, versionNameSuffix, and versionCode </em>in each flavor.</p><blockquote>If you didn’t provide those options, that flavor considers the properties in defaultConfig.</blockquote><pre>flavorDimensions &quot;env&quot;<br>productFlavors {</pre><pre>    dev {<br>        dimension &quot;env&quot;<br>        applicationId &quot;com.example.tools.dev&quot;<br>    }</pre><pre>    prod {<br>        dimension &quot;env&quot;<br>        applicationId &quot;com.example.tools.prod&quot;<br>    }<br>}</pre><p>All flavors must be assigned to a named flavor dimension, which is a group of product flavors. If a given module specifies only one flavor dimension, the Android Gradle plugin automatically assigns all of the module’s flavors to that one dimension.</p><p>In Android, it creates build variants based on our build types and product flavors, and names them according to &lt;product-flavor&gt;&lt;Build-Type&gt;. For example, now we created &quot;dev&quot; and &quot;prod&quot; product flavors, and in Flutter, we have &quot;debug&quot; and &quot;release&quot; build types. So, Gradle creates the following build variants. We can customise each build variant with its own features and resources.</p><ul><li><em>devDebug</em></li><li><em>devRelease</em></li><li><em>prodDebug</em></li><li><em>prodRelease</em></li></ul><p><strong>2-</strong> In <em>android/app/src/ folder create </em>new folders as <strong><em>prod</em></strong> and <strong><em>dev </em></strong>as shown below. This folder name must match the flavor name specified in productFlavors. Put the downloaded google-services.json files into the correct folders considering the relevant environment. So, this will automatically connect to the correct firebase project according to the flavor we are running on.</p><pre>android/<br>     app/<br>        src/<br>           dev/ google-services.json<br>           prod/ google-services.json</pre><p>That’s all for the Android configuration. Now you can run your app using:</p><pre>flutter run --flavor &lt;flavor-name&gt;</pre><h4>Step 3- Set up iOS configuration</h4><p>For iOs configuration, we need to use Xcode Schemes which is same as product flavors in Android. Open ios/Runner.xcworkspace from Xcode and click on the Runner scheme as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*WrIBIoAva_6qMz6y3jGQyQ.png" /></figure><p><strong>1 </strong>- Here, go to “New Scheme” and create a new scheme as “<strong>dev</strong>”. Give Runner as the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*lQSJ8-YnJLoxzGm8fokduQ.png" /></figure><p><strong>2 </strong>- Next, go to “Manage Scheme” and rename the default scheme — “Runner” as <strong>prod.</strong></p><p>Run the project with --flvor dev argument. You may notice it will give an error saying that Flutter needs a <em>build configuration</em> named as <strong>Debug-dev</strong> or similar. So, if we need to use the <strong>dev</strong> flavor(scheme) , we must create new build configurations named as <strong>Debug-dev </strong>for Debug mode<strong> , Release-dev </strong>for Release mode and <strong>Profile-dev </strong>for Profile mode.</p><p><strong>3</strong> - Select Runner project -&gt;Info -&gt; Configurations. Click on the plus icon and give “Duplicate Debug Configuration”. Then, rename the duplicated configuration as <strong>Debug-dev</strong>. Do the same process for duplicated release and profile configurations too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dj4mjsya1MJZ4TNCH2oFDw.png" /></figure><p><strong>4</strong> - Then, rename the default build configurations as below in order to make them run in the <strong>prod </strong>environment.</p><ul><li>Debug as <strong>Debug-prod</strong></li><li>Release<strong> as Release-prod</strong></li><li>Profile<strong> as Profile-prod</strong></li></ul><p>Alright !! :D Now we have 2 schemes as <strong>prod</strong> and <strong>dev. </strong>And we have 6 build configurations as</p><ul><li>1- Debug-prod. 2- Debug-dev</li><li>3- Release-prod. 4- Release-dev</li><li>4- Profile-prod 5- Profile-dev</li></ul><p><strong>5 </strong>- Now, we need to connect each build configuration to the correct scheme. First, select <strong>dev</strong> scheme and go to “Edit Scheme”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*XIv1SfCkEmoLMUi8CHOdbg.png" /></figure><p>In below window, Select “Run” and give “Debug-dev” as the build configuration. Give the correct build configurations in “Test”, “Profile”, Analyze” and “Archive” actions too as shown in the following image. Do this same process for <strong>prod</strong> scheme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*030Ey9Zr36_bR7H-K5_BsQ.png" /></figure><p>Alright !! :D Now we have connected all the actions in our 2 schemes to the correct build configuration.</p><p><strong>6</strong> - Next, we are going to change the bundle identifier for each scheme. Select “Runner” Target. Go to Build Settings -&gt; Packaging -&gt; Product Bundle Identifier. Here, you can give a bundle identifier for each build configuration. For build configurations in <strong>prod</strong> scheme we used -“com.example.tools.prod” and for build configurations in <strong>dev</strong> scheme we used-“com.example.tools.dev”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*HZpwFbfeM351OeUWe0ScEw.png" /></figure><p><strong>7</strong> - Now we need to connect our 2 schemes to relevant Firebase projects. For that, we create a new folder named “config” separately and inside it, we create two new folders as <strong>prod</strong> and <strong>dev</strong>. Put the downloaded GoogleService-Info.plist files into the correct folder considering the environment.</p><p>Then <strong>drag and drop </strong>this config folder explicitly into XCode inside to “Runner”.</p><pre>ios/<br>    config/<br>           dev/ GoogleService-Info.plist<br>           prod/ GoogleService-Info.plist</pre><p>Next, we are going to instruct the build process to copy the correct GoogleServices-Info.plist file into the real location where Firebase init code expects to find GoogleServices-Info.plist file. For that, select “Runner” Target. Go to “Build Phases” , click on plus icon and give “New Run Script Phase”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ot3J0XxuTqCQzESVEsHh7A.png" /></figure><p>Then a new step named as “Run Script” will be added at the bottom. Rename it to a suitable name and drag it to be between “Run Script” and “Compile Sources” steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nIM2WlQpvO4VkjEujGBvig.png" /></figure><p>Expand our new step, there we have to add a script which instructs to copy the correct GoogleServices-Info.plist file into the correct location considering the environment (scheme) we are running on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33lZ4zX_ZL2E9Wi9t0BjiQ.png" /></figure><p>The script is as follows:</p><pre><br># Get a reference to the destination location for the GoogleService-Info.plist<br># This is the default location where Firebase init code expects to find GoogleServices-Info.plist file.</pre><pre>PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app</pre><pre># We have named our Build Configurations as Debug-dev, Debug-prod etc.<br># Here, dev and prod are the scheme names. This kind of naming is required by Flutter for flavors to work.<br># We are using the $CONFIGURATION variable available in the XCode build environment to get the build configuration.</pre><pre>if [ &quot;${CONFIGURATION}&quot; == &quot;Debug-prod&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Release-prod&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Profile-prod&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Release&quot; ]; then<br>cp &quot;${PROJECT_DIR}/config/prod/GoogleService-Info.plist&quot; &quot;${PLIST_DESTINATION}/GoogleService-Info.plist&quot;</pre><pre>echo &quot;Production plist copied&quot;</pre><pre>elif [ &quot;${CONFIGURATION}&quot; == &quot;Debug-dev&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Release-dev&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Profile-dev&quot; ] || [ &quot;${CONFIGURATION}&quot; == &quot;Debug&quot; ]; then<br>cp &quot;${PROJECT_DIR}/config/dev/GoogleService-Info.plist&quot; &quot;${PLIST_DESTINATION}/GoogleService-Info.plist&quot;</pre><pre>echo &quot;Development plist copied&quot;</pre><pre>fi</pre><p><strong>8 </strong>- As the last step, in the “Build Phases” -&gt; “Copy Bundle Resources” phase, we need to delete the resource - “GoogleServices-Info.plist in Runner” in order to avoid copying of such file during the build time. We really don’t need to copy it since we are now instructing to copy the correct GoogleServices-Info.plist file from our “config” folder (step-7). I got it from <a href="https://stackoverflow.com/a/64984210/9375830">here</a>..Thanks !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQiPT4k6Uhx86I8ENd43xA.png" /></figure><p><strong>9 </strong>- Additional step - If you are using google sign in with firebase authentication, you need to copy the REVERSED_CLIENT_ID from GoogleServices-Info.plist file into the Info.plist file. Since, now we are using different firebase environments, we need to specify a variable in Info.plist and get the correct REVERSED_CLIENT_ID considering the environment we are running on. For that, I used this <a href="https://stackoverflow.com/a/61468903/9375830">method</a>..Thanks for that answer..!!</p><p><strong>A)</strong> In ios/Flutter/Debug.xcconfig and ios/Flutter/Release.xcconfig files, create a user-defined variable by adding this code line at the bottom.</p><pre>GOOGLE_SERVICE_REVERSED_CLIENT_ID = {Your REVERSED_CLIENT_ID found in GoogleService-Info.plist file}</pre><p><strong>B)</strong> In ios/Runner/info.plist file, replace the hard-coded REVERSED_CLIENT_ID with $(GOOGLE_SERVICE_REVERSED_CLIENT_ID) variable as below.</p><pre>&lt;key&gt;CFBundleURLSchemes&lt;/key&gt;<br>&lt;array&gt;<br>&lt;!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID --&gt;&lt;string&gt;$(GOOGLE_SERVICE_REVERSED_CLIENT_ID)&lt;/string&gt;<br>&lt;/array&gt;</pre><p><strong>C)</strong> Open Xcode and select “Runner” target. Then go to Build Settings -&gt; User-Defined section. Here, you may find that, the variable which you have defined earlier as GOOGLE_SERVICE_REVERSED_CLIENT_ID has been added into this section. Now, you can set the actual environment specific REVERSED_CLIENT_ID for each build type.</p><pre>Debug-dev = com.googleusercontent.apps.{dev client-id}<br>Debug-prod = com.googleusercontent.apps.{prod client-id}<br>Profile-dev = com.googleusercontent.apps.{dev client-id}<br>Profile-prod = com.googleusercontent.apps.{prod client-id}<br>Release-dev = com.googleusercontent.apps.{dev client-id}<br>Release-prod = com.googleusercontent.apps.{prod client-id}</pre><p>And, finally we are done !! :D That’s all for the iOS configuration. Now you can run your app using :</p><pre>flutter run --flavor &lt;flavor-name&gt;</pre><p>Hope this article helps you get a clear understanding on setting up multiple Firebase environments to your Flutter app.</p><h4>References</h4><ul><li><a href="https://medium.com/@matt.goodson.business/separating-build-environment-configurations-in-flutter-with-firebase-doing-it-the-right-way-c72c3ad3621f">https://medium.com/@matt.goodson.business/separating-build-environment-configurations-in-flutter-with-firebase-doing-it-the-right-way-c72c3ad3621f</a></li><li><a href="https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b">https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b</a></li><li><a href="https://medium.com/flutter-community/multiple-builds-environment-in-flutter-for-firebase-using-provider-and-flavor-883b1a30096d">https://medium.com/flutter-community/multiple-builds-environment-in-flutter-for-firebase-using-provider-and-flavor-883b1a30096d</a></li><li><a href="https://www.tengio.com/blog/multiple-firebase-environments-with-flutter/">https://www.tengio.com/blog/multiple-firebase-environments-with-flutter/</a></li><li><a href="https://www.ptrbrynt.com/how-to-set-up-multiple-firebase-environments-in-a-flutter-app/">https://www.ptrbrynt.com/how-to-set-up-multiple-firebase-environments-in-a-flutter-app/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f88bc284454" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Operations on Images using OpenCV]]></title>
            <link>https://kmtsandeepanie.medium.com/basic-operations-on-images-using-opencv-c7de77cc38a3?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7de77cc38a3</guid>
            <category><![CDATA[opencv-python]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Mon, 11 May 2020 19:39:23 GMT</pubDate>
            <atom:updated>2020-05-11T20:00:04.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0Pm9LlQfg7dpVJ-J.jpg" /></figure><p>By my previous article, I explained how to setup the environment to work with OpenCV ( <a href="https://medium.com/@kmtsandeepanie/getting-started-with-opencv-70076c9eb5ee">link</a>). So, now I will explain some basic operations we can do on images using OpenCV.</p><h3>First we will see how to load an image.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*2MaUpQ0WZpf8-58BLhJ2Hg.png" /></figure><blockquote>Here, if the file does not exist, the imread function will not raise any exception and a none value will be returned instead.</blockquote><h3>Display your image</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*Zz6ukhkGa2CVzdJSYt_boQ.png" /></figure><p>This will display your image in a separate window. Since my image is too large, I have to resize it into a smaller size to be shown in the window. The cv.waitKey() is to let the system “wait” without closing the window. We can give time duration to wait the window in the (). cv.waitKey(0) will wait continuously until the user press any key.Without this instruction, the system would return immediately without actually displaying the image. The cv2.destroyAllWindows() function is used to close all open windows.</p><p>Here I display the image using OpenCV ,but when working with Jupyter notebook, it is better o use matplotlib to display images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*w-yokCwgryD3hF45uMEvfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*gZ-tiV5unKjEaQnMncc03A.png" /></figure><p>Here, colors are not correct. It is becuase OpenCV reads images in the BGR format, while matplotlib reads images in the standard RGB format. <br>If you want to change the color type, do</p><pre><strong># cv2.cvtcolor function for color conversions.<br>     img2 = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)</strong></pre><pre><strong>OR</strong></pre><pre><strong># numpy indexing can flip the order of the channels.<br>     plt.imshow(img[…,::-1])  </strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*Y26pPCxAwnDft0t2RNnG3Q.png" /></figure><h3>Check image properties</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*wBK2lp3KazAN2gLVqVMrRQ.png" /></figure><p>Here, you can find that the loaded image is a numpy array.</p><p>And<strong> img.shape </strong>indicates the number of pixels (2469 X 3704) with three channels (since this is a RGB color image). If the image is gray-scale, image shape contains only number of rows and columns.</p><p>The data type of the image is uint8, i.e., 8 bit unsigned int (numbers from 0 to 255) as indicated by <strong>img.dtype</strong>.</p><p>Minimum and maximum number in the matrix can be checked using the <strong>min</strong> and <strong>max</strong> functions.</p><p>Total number of pixels can be obtained by <strong>img.size</strong></p><h3>Access and modify color of the pixels</h3><pre><strong># Access and print a value in a pixel<br>    print(img[10,10])           <br># Output shows the color value of that pixel as [38 30 31]</strong></pre><pre><strong># Change the color of an area (range of pixels) <br>    img[10:20, 10:20] = [255,255,255]</strong></pre><pre><strong>OR</strong></pre><pre><strong># Certain region of image (ROI) is obtained using Numpy indexing <br>    ball = img[500:1000, 1500:2000]<br>    img[273:773, 100:600] = ball</strong></pre><h3>Basic Image processing operations</h3><h4>1- Convert a color image to gray-scale image</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*7MjhO6slNbTOjeLJmN5O6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*Neoy1UlLB3rPykCg4XGvKw.png" /></figure><h4>2- Gaussian Blur</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*xzbwyiy7kYUc5RnT2AA51w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*RPgB8CnNswp4uaE2BQubAw.png" /></figure><h4>3. Image Blending</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*XId6rvF4JNLW8qFWsAvRDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*R9PeijVwP5Jf6FDiQLYNJg.png" /></figure><p>The arrays obtained from each picture must be with the same size otherwise an error will be triggered. So , need to resize the images first to have the same height and weight.</p><p>In OpenCv we can blend images (similar to image addition) using the <strong>cv2.addWeighted </strong>function, It will apply the following equation on an image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*r55Ms8g5d8AwwhMqQdOApQ.png" /></figure><p><strong>cv2.addWeighted(img, 0.7, img2, 0.5, 0) — </strong>Here , numbers after the image name are the weights as in the above equation. They can be varied from 0 to 1. According to that weight it determines how much to blend the two images in other words whether to make them more/less transparent. The additional 0 at the end of the line of code represents gamma.</p><h4>4. Edge Detection</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*yYl2Oa3XwSP3K6Ve1bui1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*ILwayHRyWnnNZpybuJ3r-g.png" /></figure><h4>5. Sobel Derivatives</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*HHqbM-2tz_WyFoM6XugA4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*WUwie7EM64RqvDil3ya2mg.png" /></figure><h3>Draw Objects</h3><p>Using OpenCV we can draw objects(shapes like circles, rectangles..) on images. First we will create a blank image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*R234IqdG6kFaa5FiLQrXsg.png" /></figure><p>So, now we can draw objects as shown below on this blank image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*st1Ecb4NNADPEacuEJ1Dxw.png" /></figure><p>Parameters in each function indicate following properties of the shapes.</p><p><strong>cv2.line(image, startPoint(x,y), endPoint(x,y), rgb, thinkness)</strong></p><p><strong>cv2.rectangle(image, topLeft(x,y), bottomRight(x,y), rgb, thinkness)</strong></p><p><strong>cv2.circle(image, center(x,y), radius, rgb, thinkness)</strong></p><p><strong>cv2.ellipse(image, center, axes, angle, startAngle, endAngle, rgb, thinkness)</strong></p><p><strong>cv2.polylines(image, points, isClosed, rgb, thinkness, lineType, shift)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*Je7s89lUCJzy0Co_kiyQxw.png" /></figure><h4>Add a text on an image</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*GSuSEkSiiUYA-SKWa0L6Tg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*9DMoBR0pEoRmclhUol_3Qg.png" /></figure><p>cv2.putText(img, ‘Dog’, (1000,400), font, 15, (0,0,255), 30, cv2.LINE_AA)— here parameters represents following properties of the text.</p><p><strong>cv2.putText(image, text to be displayed , bottom-left(x,y coordinates ), font type, font scale, rgb color value, thickness, line type)</strong></p><h4>Acquire video from a camera</h4><p>We can obtain a video stream from the webcam as below:</p><pre><strong># Constructor of this class gets the index of the device we want to use. If we just have a single camera connected to the computer, we can pass the value 0. It indicates the default camera.</strong></pre><pre><strong>cap = cv2.VideoCapture(0)</strong></pre><pre><strong>#This reads a frame &quot;img&quot; and a return value &quot;r&quot;, set to true if there are no errors.<br>r,img = cap.read() </strong></pre><pre><strong>while r:<br>    #show the obtained frame <br>    cv2.imshow(&#39;Frame&#39;,img)</strong></pre><pre><strong>    #process current frame <br>    img_c = cv2.Canny(img,180,200)<br>    #show processed frame<br>    cv2.imshow(&#39;Canny&#39;,img_c) </strong></pre><pre><strong>    a=cv2.waitKey(20) #wait for 20 ms (i.e., 25 fps)<br>    if a != -1:   #if any key was pressed:<br>        r = False <br>    else:<br>        r,img = cap.read() #else, read new frame</strong></pre><pre><strong><br># Release the video capture object<br>cap.release()</strong></pre><pre><strong># Close all the frames<br>cv2.destroyAllWindows()</strong></pre><h4>References</h4><p><a href="https://docs.opencv.org/master/d9/df8/tutorial_root.html">https://docs.opencv.org/master/d9/df8/tutorial_root.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7de77cc38a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with OpenCV]]></title>
            <link>https://kmtsandeepanie.medium.com/getting-started-with-opencv-70076c9eb5ee?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/70076c9eb5ee</guid>
            <category><![CDATA[opencv-python]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Mon, 11 May 2020 10:23:04 GMT</pubDate>
            <atom:updated>2020-05-11T20:01:25.816Z</atom:updated>
            <content:encoded><![CDATA[<p>How to setup the working environment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V9RSOdq6KWiIpy4z" /></figure><p><strong>OpenCV is a library of programming functions mainly aimed at real-time computer vision. I</strong>t is a library used for Image Processing and mainly used to do all the operations related to Images.</p><p><strong>OpenCv can be used to :<br></strong>1. Read and Write Images.</p><p>2. Detection of faces and its features.</p><p>3. Detection of shapes like Circle,rectangle etc in a image.</p><p>4. Drawing objects and adding texts</p><p>5. Text recognition in images. e.g Reading Number Plates.</p><p>6. Modifying image quality and colors.</p><p>7. Developing Augmented reality apps.</p><p>From this article, I’m going to explain how to setup the environment to work with OpenCV .</p><h3>Install OpenCV on Windows using Anaconda Navigator</h3><p>Here, I’m going to work with Jupyter Notebook using Anaconda Navigator.So that, first you have to download it via this <a href="https://www.anaconda.com/products/individual">link</a> and install it into your machine. Make sure to select <strong>Add Anaconda to my PATH environment variable </strong>when installing.</p><p>After installing it open Anaconda Navigator and you can see the below view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsHw6J0SJnaYnfjNs67q1w.png" /></figure><p>Then give launch in Jupyter Notebook. So, you can see that it will run on a localhost on your default web browser. If you want to open it in your project location, go to Anaconda prompt and change the directory to your project location. Then give <strong>Jupyter notebook </strong>as the command. So, it will launch Jupyter in your given file location on the local host.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*QBXtCkZI30ud4V8U3DCpLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMzqT21KrdvPjejx1x0Rxw.png" /></figure><p>Now inside your project location you have to create a new notebook. For that, select <strong>new -— &gt; Python 3 </strong>Notebook. Note that, in your notebook dashboard (in the web browser) you can run codes separately in empty boxes.</p><p>Then after, we need to import some packages that might need for this.</p><blockquote><strong>NumPy - a Python package used for numerical computation.</strong></blockquote><blockquote><strong>Matplotlib -a Python package used to build 2D static plots.</strong></blockquote><p>These are preinstalled with Anaconda but in order to make sure if those packages are installed well, type the following into one of the cells and do run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*P3z02v2SVxXMdFNi9iU86Q.png" /></figure><p>If any error occurred, you need to install the packages by giving the below commands in Anaconda Prompt.</p><ul><li>To install OpenCv ,</li></ul><pre><strong>pip install opencv-python</strong></pre><ul><li>To install numpy,</li></ul><pre><strong>pip install numpy     OR<br></strong><strong>conda install numpy</strong></pre><ul><li>To install matplotlib,</li></ul><pre><strong>pip install matplotlib    OR <br></strong><strong>conda install matplotlib</strong></pre><p>OK. Now everything is alright and you can start your coding... From my next article, I will explain some basic operations we can do using OpenCv on images. (<a href="https://medium.com/@kmtsandeepanie/basic-operations-on-images-using-opencv-c7de77cc38a3">link</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70076c9eb5ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing HTTP Cookies in Ballerina]]></title>
            <link>https://kmtsandeepanie.medium.com/managing-http-cookies-in-ballerina-53545ede3a3e?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/53545ede3a3e</guid>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 11:17:14 GMT</pubDate>
            <atom:updated>2020-04-20T11:17:14.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iva2Pu4L5ug4Q9KbPPaUvw.png" /></figure><p>By this article, I am going to explain you how to manage HTTP Cookies using Ballerina language. If you are interested in using Ballerina language into your project and need to use HTTP Cookies in it, then I hope this article will help you for it in the best way.</p><p>Ballerina is a general-purpose programming language designed for network distributed application development.It is currently being developed by WSO2. For more details about Ballerina — <a href="https://ballerina.io/">link</a>.</p><p>From my previous article, I indicated some basic facts regarding HTTP Cookies. You can go through it if you feel ,you have less understanding about HTTP Cookies :- <a href="https://medium.com/@kmtsandeepanie/http-state-management-using-cookies-ebab25d5c7e6">link</a></p><p>Ballerina supports both<strong> Server side APIs and Client side API</strong>s to you in order to manage HTTP Cookies. Further more , It gives you to support both session and persistent cookies. All these APIs in Ballerina are developed according to the<strong> RfC — 6265</strong> specification (HTTP State Management Mechanism<strong>)</strong></p><p>I will explain step by step how to use HTTP Cookies using Ballerina language from both server side and client side.But before this I want you to be familiar with HTTP client &amp; server implementations in Ballerina . For that you can refer this site :- <a href="https://ballerina.io/learn/by-example/">link</a></p><h3>Server-side APIs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*uQpiCnBJ4U-6vFs_gDU98g.png" /></figure><ul><li>Server can create a new cookie , assign values for its attributes and add it to server’s response as follows.</li></ul><pre><strong>http:Cookie cookie1 = new(&quot;SID001&quot;, &quot;239d4d34&quot;);<br>cookie1.path = &quot;/sample&quot;;<br>cookie1.domain = &quot;localhost:9253&quot;;<br>cookie1.httpOnly = true;<br>cookie1.secure = true;<br>cookie1.expires = &quot;2030-06-26 05:46:22&quot;;<br>cookie1.maxAge = 36000;</strong></pre><pre><strong>http:Response res = new;<br>res.addCookie(cookie1);  // Add a cookie into Response.</strong></pre><blockquote>Note that Ballerina has provided a separate object called “Cookie” inside the HTTP module to be used when you are managing cookies .</blockquote><p>Make sure that you assign valid attribute values according to the RfC-6265 spec , otherwise it will trigger an error message and cookie will not be added into the response. Things to be considered :- Name and Values of the cookie must be given when creating a new cookie……, Blank values can not be assigned to any attribute……, Path value must be started with “/” and it must not contain query strings….., Expires values must conform with the <strong>yyyy-mm-dd hh:mm:ss </strong>format and maxAge value should not be less than zero.</p><p>After add this cookie into the response, It will add a header named “Set-Cookie” with indicating all the cookie values inside the HTTP response.</p><ul><li>Server can remove a specific cookie from the client’s cookie store as follows. Here, when removing cookies by server, “expires” attribute value of the cookies which server wants to remove will be set to a past date and send those cookies under separate “Set-Cookie” headers in the response.</li></ul><pre><strong>http:Response res = new;<br>res.removeCookiesFromRemoteStore(cookie1);</strong></pre><ul><li>Server can obtain cookies from the inbound request as follows. Note that Cookies are sent in the request under “Cookie” header as a string and here an array of cookie objects parsed from this string value will be returned when calling this API.</li></ul><pre><strong>http:Cookie[] reqstCookies = request.getCookies();</strong></pre><h3>Client-side APIs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*FXzpkrhGkgOpBYb9bcvboQ.png" /></figure><ul><li>Client can enable cookies in the client configuration when creating the client as follows.</li></ul><pre>http:Client cookieClientEndpoint = new (&quot;http://localhost:9253&quot;, {</pre><pre><strong>cookieConfig: { enabled: true }</strong></pre><pre>});</pre><p>When a user enables for cookies, a cookie store will be initialized for each client. This cookie store acts as a place where all the cookies (both session and persistent) can be stored.</p><p>Specificity of the cookie client is when a user sends a request to a server, before sending it, it checks whether there are any cookies in the cookie store which have been sent earlier by that server. If so, it sends those cookies under the “Cookie” header in the request to that server with indicating the cookie name &amp; value. The order of cookies included in the Cookie header is according to the rules in RfC-6265 specification.</p><p>After sending the cookies to the server, then server may send the response with or without cookies. So, before returning the response to the client, client gets the cookies from the response if there are and add those cookies into the cookie store (according to the rules in RfC-6265 specification) . Then after the response is returned to the client.</p><blockquote>Even though client sends multiple requests concurrently, adding cookies to cookie store for each request is done one after the other because of the concurrency management of cookies in Ballerina.</blockquote><p>So, that is the process happening when sending requests and responses when a client enables cookies as above.</p><ul><li>Client can define maximum number of cookies per domain, maximum total number of cookies stored in the cookie store (according to his needs) and whether to block or unblock third party cookies by using the cookie configurations as below.</li></ul><pre>http:Client cookieClientEndpoint = new (&quot;http://localhost:9253&quot;, {</pre><pre>cookieConfig: { enabled: true, <br>                  <strong> maxCookiesPerDomain: 20,<br>                   maxTotalCookieCount: 1000, <br>                   blockThirdPartyCookies: true</strong> }<br>});</pre><p>Here, when adding a cookie to cookie store, if cookies per domain or total number of cookies in the cookie store exceeds the above configured values, it will return an error to the user with giving a message.</p><ul><li>If a client wants to store cookies persistently, he must assign either a CsvPersistentCookieHandler object or his own mechanism used object with referring the PersistentCookieHandler abstract object to the field- “persistentCookieHandler” in cookie configuration record.</li></ul><pre>// Creates CsvPersistentCookieHandler object.<br><strong>http:CsvPersistentCookieHandler myPersistentStore = new(&quot;./test/myFile.csv&quot;);</strong></pre><pre>http:Client cookieClientEndpoint = new (&quot;http://localhost:9253&quot;, {</pre><pre>cookieConfig: { enabled: true,<br>                    <strong>persistentCookieHandler : myPersistentStore</strong> }</pre><pre>});</pre><p>Here, when creating CsvPersistentCookieHandler object user must give a csv file name to where the cookies should be stored. Because of this, separate csv files can be created to store cookies for each cookie client.</p><blockquote>Note that Ballerina has provided an abstract object named PersistentCookieHandler and also a CsvPersistentCookieHandler object inside HTTP module.</blockquote><p>If client wants to store persistent cookies with his own mechanisms ( using a database or a file system…etc) he should create an object by referring the PersistentCookieHandler abstract object with implementing all the following methods.</p><pre><strong>public function storeCookie(Cookie cookie) returns CookieHandlingError?;</strong></pre><pre><strong>public function getAllCookies() returns Cookie[]|CookieHandlingError;</strong></pre><pre><strong>public function removeCookie(string name, string domain, string path) returns CookieHandlingError?;</strong></pre><pre><strong>public function removeAllCookies() returns CookieHandlingError?;</strong></pre><p>For the clients who don’t want to write their own implementation, can use CsvPersistentCookieHandler object directly which can store persistent cookies as records in a csv file . (as above example) So that is the default PersistentCookieHandler object given by Ballerina with referring the PersistentCookieHandler abstract object. It has all built in methods to write cookie objects to the file, read cookie objects from the file, remove a specific cookie from the file and clear all persistent cookies. So, you don’t need to write your own methods to store persisgtent cookie because of this.</p><ul><li>If a client is not configured to use persistent cookies and the server sends persistent cookies, he will get a warning message about persistent cookies for his first request as follows.</li></ul><pre><strong>log:printWarn (&quot;Client is not configured to use persistent cookies. Hence, persistent cookies from &quot;&lt;domain name&gt;&quot; will be discarded.&quot;);</strong></pre><ul><li>Client can remove a specific session or persistent cookie by specifying the cookie name, domain and path respectively.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br>  <strong> var removeResult =          myCookieStore.removeCookie(&quot;SID001&quot;,&quot;localhost:9253&quot;, &quot;/cookie/cookieBackend_1&quot;);</strong></pre><pre>if (removeResult is error) {<br>      io:println(removeResult);<br>   }<br>}</pre><ul><li>Client can remove all the session and persistent cookies as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br>    <strong>var removeResult = myCookieStore.removeAllCookies();<br>    </strong>if (removeResult is error) {<br>        io:println(removeResult);<br>    }<br>}</pre><ul><li>Client can remove all the expired cookies as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br>   <strong>var result = myCookieStore.removeCookiesByDomain(&quot;google.com&quot;);</strong><br>   if (result is error) {<br>      io:println(result);<br>   }<br>}</pre><ul><li>Client can remove cookies by domain as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>    if (myCookieStore is http:CookieStore) {<br><strong>var result = myCookieStore.removeCookiesByDomain(&quot;google.com&quot;);</strong><br>    if (result is error) {<br>       io:println(result);<br>    }<br>}</pre><ul><li>Client can retrieve all the cookies in the cookie store as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br>   <strong> http:Cookie[] cookies = myCookieStore.getAllCookies();</strong><br>}</pre><ul><li>Client can get the cookies by domain as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br>    <strong>http:Cookie[] cookies =           myCookieStore.getCookiesByDomain(&quot;google.com&quot;);</strong><br>}</pre><ul><li>Client can get the cookies by cookie name as follows.</li></ul><pre>http:CookieStore? myCookieStore = clientEndpoint.getCookieStore()<br>if (myCookieStore is http:CookieStore) {<br> <strong>http:Cookie[] cookies = myCookieStore.getCookiesByName(&quot;SID002&quot;);</strong><br>}</pre><p>Hope, this will be helpful for you if you have a need to use HTTP Cookies using Ballerina language. Thank You..!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53545ede3a3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP State Management using Cookies]]></title>
            <link>https://kmtsandeepanie.medium.com/http-state-management-using-cookies-ebab25d5c7e6?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebab25d5c7e6</guid>
            <category><![CDATA[http-cookie]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Fri, 21 Feb 2020 19:12:04 GMT</pubDate>
            <atom:updated>2020-02-22T05:48:10.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>…..All you need to know about HTTP cookies…..</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*u3erGrUtZ401Wte5" /></figure><h3>What are HTTP Cookies..?</h3><p>As you all know, HTTP is a stateless protocol which means that the client-server connection is lost once the transaction ends between them. So, HTTP server does not save details about each client. Hence, server can not decide whether a request came from a client who has requested before or from a new one.</p><p>Cookie is used as a stolution for this problem. It is a small piece of data sent from server and stored on client’s computer by the web browser when a client sends a request to a particular server. It is reliable mechanism to remember stateful information since HTTP is stateless.</p><p>HTTP cookie is a combination of following components.</p><ul><li>Name</li><li>Value</li><li>Attributes- Domain, Path, Expires, Max-Age, HttpOnly, Secure</li></ul><p>A) The <strong>Domain</strong> and <strong>Path</strong> attributes are the scope of the cookie. They define to which website the cookie belongs to. If a cookie’s Domain and Path attributes are not specified by the server, they default to the domain and path of the resource that was requested. So that, the cookie will only be sent only for that domain and path (also known as a host-only cookie). If domain and path are specified, all sub domains and sub directories are also included.</p><p>B) The <strong>Expires</strong> attribute defines a specific date and time for when the browser should delete the cookie. The date and time are specified in the form “Wdy, DD Mon YYYY HH:MM:SS GMT” format according to the RfC -6265 specification. Alternatively, the<strong> Max-Age </strong>attribute sets the cookie’s expiration using seconds, relative to the creation time of the cookie. If any of these two are not specified, it will be a session cookie.</p><p>C) The <strong>HttpOnly </strong>attribute tells browser to send cookies only to HTTP (and HTTPS) requests.</p><p>D) The <strong>Secure </strong>attribute tells browsers to use cookies only via secure/encrypted connections (HTTPS)</p><h3>State management using Cookies…</h3><blockquote>Cookies use two HTTP headers:<strong> Set-Cookie</strong> and <strong>Cookie</strong>.</blockquote><p>When receiving an HTTP request, a server can send cookies using the “Set-Cookie” header in an HTTP response and send to the user. When sending multiple cookies server must use separate Set-Cookie headers for each cookie.</p><pre>HTTP/1.0 200 OK<br>Content-type: text/html<br><strong>Set-Cookie: theme=light<br>Set-Cookie: lang=eng; Expires=Wed, 09 Jun 2021 10:18:14 GMT </strong></pre><p>These cookies are stored by the browser temporarily or persistently in client’s cookie store, and then relevant cookies are sent with each subsequent requests to that particular server inside a “Cookie” HTTP header.</p><pre>GET /spec.html HTTP/1.1<br>Host: www.sample.com<br><strong>Cookie: theme=light; lang=eng </strong></pre><p>Through this way, server can get to know that this request is sent by a client who has previously requested to this server. The server can add new cookies, modify existing cookies, or remove cookies of the client by including more Set-Cookie headers in the response.</p><p>If the server wants to modify the value of an existing cookie , server can send the modified cookie under a Set-Cookie header in the response to a page request. Then browser replaces the old cookie with the new cookie. According to the RfC -6265 specification , two cookies are considered as similar cookies if both have same name,same domain and same path values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*jfn5cTWZ7OHboyNfR_kQZA.png" /><figcaption>Over all process of HTTP cookies</figcaption></figure><h3>Types of cookies</h3><ol><li><strong>Session cookie</strong> — It exists only in temporary memory while a user is visiting a website. Once the user closes the web browser, these cookies are removed by the browser. They do not have an expiration date value, which signals the browser that they are session cookies.</li><li><strong>Persistent cookie</strong> — A persistent cookie expires at a specific date or after a specific length of time. During that time period, this cookie will be sent to the server every time the user visits the website that it belongs to. These cookies are stored in the client’s cookie store using a database or in a file system for the specified time duration.</li><li><strong>Secure cookie </strong>— A secure cookie is sent only to a server with an encrypted request over the HTTPS protocol.</li><li><strong>HTTP-only cookie</strong> — Cookies with HttpOnly attribute are sent only with HTTP requests.</li><li><strong>Third-party cookie</strong>- They are cookies that are set by a website other than the one client is currently visiting. When rendering an HTML document, a user agent often requests resources from other servers (such as advertising networks). These third-party servers can use cookies to track the user even if the user never visits the server directly. For example, if a user visits a site that contains content from a third party and then later visits another site that contains content from the same third party, the third party can track the user between the two sites.</li></ol><h3>Purpose of cookies</h3><p>When a user visits a website for several times, the server will consider each and every request as unique. To uniquely remember a user, the server sends the cookies along with the response which is saved in user’s local machine. Then next time user hits the same server, he will get a response which matches with his preferences such that server can recognize him.</p><p>Cookies are mainly used for three purposes: <br>A) Session management — Logins, shopping carts or anything else the server should remember.</p><p>B) Personalization — User preferences, themes, language, country and other settings.</p><p>C) Tracking — Recording and analyzing user behavior.</p><h3>Removing cookies</h3><p>If server wants to remove a cookie, server must returns that cookie with a past expiration date. This will signal to the browser that the cookie should be removed. Session cookies must be removed after the browser is closed and all expired persistent cookies must be removed by web browser from the cookie store if, at any time, an expired cookie exists in the cookie store.</p><blockquote>Note:- This article is based on the rules in RfC-6265 specification..</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebab25d5c7e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Git Basics -2]]></title>
            <link>https://kmtsandeepanie.medium.com/understanding-git-basics-2-418f4af1d2f6?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/418f4af1d2f6</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 18:31:52 GMT</pubDate>
            <atom:updated>2021-05-25T06:59:20.982Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Git Basics -Part-2</h3><p>In this article , I’m focusing on basic Git commands , which would be helpful for you when working with Git. From my previous article you can get a basic idea about working with git repositories :- <a href="https://medium.com/@kmtsandeepanie/understanding-git-basics-5bd1163dc828">link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x1RAgeK3_dcBilSE.png" /></figure><h3>Initialize a local repository</h3><p>From my previous article I described how to set up a Git repo by cloning. Now we will see, <strong>how to initialize a local repository from existing code in your machine.</strong></p><p>In the terminal navigate to your project directory and give :-</p><pre>git init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*rcTl24rnWtEioSFccPLiBg.png" /></figure><p>This will create a .git folder in your working directory and create a new master branch. Now your project can be tracked by Git. If you have some files/folders which are not needed to track by Git, then simply create a .gitignore file and give those files. So, those files will not be tracked by Git.</p><p>Now do “git add” and “git commit” commands as I described in my previous article. Add .gitignore file too.</p><h3>Connect local repository with remote repository</h3><p>Now we want to add your local repo to Github, first you must create a remote repo in Github. Go to your Github account and create a new repo as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*6yGdqU82XpMWsFhEAuQdUQ.png" /></figure><p>Now , give below commands to add your remote repo as an origin and push the committed files into that remote repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*GSNixC8ymH94RDH1T4xXCw.png" /></figure><pre>git remote add origin <a href="https://github.com/Tharuja/Hello--World.git">https://github.com/Tharuja/Hello--World.git</a><br>git push -u origin master</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*jf_bfyoTH68KtXAu_g-dPQ.png" /></figure><p>Refresh your created remote repo in Github and you can see your local project has been added to it.</p><h3>Create a new branch</h3><p>By default , you are in the branch named “master” and you can create different branches for your desired features.</p><pre>git branch &lt;branch-name&gt;  // Create a new branch<br>git checkout &lt;branch-name&gt;   // Switch to a branch</pre><pre>git checkout -b &lt;branch-name&gt;  // Create a new branch and switch to that  branch</pre><pre>git checkout -b &lt;branch-name&gt; origin/&lt;branch&gt;   //Break a new branch from a given repo &amp; branch , can use upstream repo too.</pre><pre>git branch  //List down all the branches in local repo<br>git branch -a  // List down all the branches including remote branches.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*7NuDfwO6H85AFCGYa_HaNA.png" /></figure><p>After switching to a new branch you can add and commit the changes you did and do “<strong><em>git push origin &lt;new-branch&gt;” . </em></strong>It will create such a new branch in your remote repo with those changes.</p><h3>Merge a branch</h3><p>Suppose you created a new branch named “test” and did some changes there.And if you want to merge this test branch to master branch follow below steps.</p><pre>git checkout master<br>git pull origin master // this is only to get the latest updates   of master branch</pre><pre>git merge test(branch you want to merge) //test branch will be merged into master in your local repo.</pre><pre>git push origin master  //Push those changes to origin/master branch.</pre><h3>Delete a branch</h3><p>If you want to delete a specified branch then follow below steps:</p><pre>git branch -d &lt;branch-name&gt; </pre><pre>git branch -a  // You can see this branch has been deleted from local repo but it is still in remote repo</pre><pre>git push origin --delete &lt;branch-name&gt;  // Delete that branch from remote repo.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*vFSgApzlefmipdbjY2Ariw.png" /></figure><h3>Other basic Git commands :-</h3><pre>-To check your current version of Git in your machine<br><strong>git --version</strong></pre><pre>-To get the manual page for the git commands <strong><br>git help</strong></pre><pre>-Show the state of the working directory and the staging area, which branch you are currently in.<br><strong>git status</strong></pre><pre>-To display all of the commits in a repository’s history.(each commit’s: Secure Hash Algorithm (SHA),author,date,commit message)<br><strong>git log</strong></pre><pre>-To undo a commit<br><strong>git revert &lt;commit hash&gt;</strong></pre><p>Git stash is used to temporarily save changes (both staged and unstaged) you’ve made to your working directory for later use and then you are free to do changes, switch branch and pull updates..etc. Stash is local to your Git repository; stashes are not transferred when you push.</p><pre>git stash</pre><pre>//Apply the stashed changes again <em>and</em> keep them in your stash<br>git stash apply</pre><pre>//Apply the stashed changes again and remove them from stash<br>git stash pop</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=418f4af1d2f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Git Basics]]></title>
            <link>https://kmtsandeepanie.medium.com/understanding-git-basics-5bd1163dc828?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd1163dc828</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 09:53:18 GMT</pubDate>
            <atom:updated>2021-05-25T06:56:50.256Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Git Basics- Part-1</h3><p>In this article , I’m focusing on working with Git repositories, which would be needed for you if you are a programmer and still haven’t used Git as the version control system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*oMC83-7fB27k1tTMxDfRaQ.png" /></figure><p>First, you need to understand the git working flow. When working with git , there are <strong>3 types of repositories</strong> you have to deal with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*azrY-lW7BOHETxDR8ssXtQ.png" /></figure><p>1- <strong>Local repository </strong>— When you are working on your local machine that working directory is your local repository.</p><p>2-<strong>Remote repository</strong> — It is a common repository that all your team members can use to exchange their changes. Such remote repositories are GitHub and BitBucket.</p><p>3-<strong>Upstream repository</strong> — It is the Parent/Original repository from where you forked your repository. Then , forked one will act as a remote repository.</p><h3>Fork</h3><p>Forking is getting a copy of an upstream repository for you. So you can do your own changes freely without affecting the original repository. You can fork a repository as below in the upstream repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*5UJjy3Qs8-6cAYk-qfMpCA.png" /></figure><p>Once you forked a repository you will have an individual copy of it in your GitHub account.</p><h3>Clone</h3><p>After forking the upstream repository , you can make a copy of it into your local machine by cloning the remote repository. Go to your remote repository and copy the link as shown below. Then give the following command in terminal in where you want to create the local repository.Make sure that you have installed Git into your machine before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*f-kj2e5eF1CsBe6qQ3AXcg.png" /></figure><pre>git clone &lt;copied link&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*Jlw39TUh464FhjRIGgSgLw.png" /></figure><p>Now you will have a local repository in your machine, which is an exact copy of your remote repository and you can do any of your changes as you want in your local repository.</p><h3>Commit and Push</h3><p>There are 3 GIT modes for your changes — unstaged, staged &amp; committed.</p><p>1- When we modify files or add new files, they are in the unstaged mode. Using<strong> “git add”</strong> those changed files will be moved to staged mode, which means into the queue to be committed later.</p><pre>git add .   //to add all the changed files<br>git add &lt;file-name&gt;   //to add a specified file</pre><p>Here we have an option to return back to unstaged mode, so you can do further new changes or undo previous changes.</p><p>2- Then after, we can <strong>commit</strong> the files , which were added to staged mode using below command. It will create a new revision with a log.</p><pre>git commit -m “commit message”    // if commit message is not      given, text editor will be appeared to give the message.</pre><pre>git commit -a    //stages the changes of all <strong>tracked files</strong> and commits them. (git add -u + git commit)</pre><p>3 - Now, you can push these committed files to your remote repository using <strong>“git push</strong>” . (As you created this local repo using cloning your remote repo, no need to add the remote repo here. Name origin refers the remote repo.)</p><pre>git push -u origin &lt;branch-name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*W19_Iaum3Jhf0XNUy9Iv0Q.png" /></figure><p>This will create such a branch in your remote repository, if there was no such branch before. If you are publishing a local branch for the first time for the remote, the “-u” option is helpful. It will create a tracking connection between the local and the newly created remote branch. After having a tracking connection, you can use only git push command without options.</p><pre>git push</pre><h3>Send Pull Requests</h3><p>After adding your changes to your remote repository, to merge those changes to the parent/upstream repository , you should create a pull request as shown below.</p><p>1-Go to your remote repo and checkout to the branch to which you pushed your changes and give “new pull request”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*9CxPRYWe1tO3zXLehTe6vg.png" /></figure><p>2- Give “create pull request” and make sure that you send the PR to correct base repo/branch. You can see your individual changes here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*ER9cIGrVyY639VzG_jAWYg.png" /></figure><p>3- Give a name to your PR and create the PR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*Sbs5pduSFy3gW-MxTdx8-A.png" /></figure><p>Once you created a PR , a member from the upstream repo, will initiate a build of your pull request and can review your PR and then if there are no any conflicts , your PR can be merged to upstream repository successfully.</p><h3>Syncing your repository with upstream repository</h3><p>As you wanted to merge your changes to upstream repo , there will be so many other members whose PRs might have been merged already to upstream repo after you forked it. So, if they have done a change in a file in where you also changed later , it will cause <strong>merge conflicts</strong>.</p><p>To avoid these conflicts, you need to <strong>sync your local repo</strong> with upstream repo with any later changes made in the upstream repo, before starting your changes. Once you forked and clone a project, no need to repeat these steps, instead you can do sync with few steps.</p><p>1- First, we need to add the parent repository as an upstream remote for our repo.</p><ul><li>Copy the URL of upstream repo.</li><li>Inside the local repo directory give below command:</li></ul><pre>git remote add upstream &lt;URL&gt;</pre><p>Give “<strong>git remote</strong>” to see your current remotes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*TW0E_n5NHdtMkiIbW3CJeg.png" /></figure><p>2- After that, update your local repo using following steps. It will pull down any changes in upstream repo and will do the syncing. Before updating, you need to commit or stash all the changes if you did any.</p><ul><li>Fetch all of the branches from the upstream repository. This will display the branches that were downloaded:</li></ul><pre>git fetch upstream     , or <br>git fetch upstream &lt;branch&gt;  //only fetch the specified branch.</pre><ul><li>Switch to your branch that need to do sync and do merge.</li></ul><pre>git checkout &lt;branch&gt;<br>git merge upstream/&lt;branch&gt;</pre><p>Or, instead of doing both fetch and merge, you can simply use following “git pull” to do the fetch and merge at once.</p><pre>git pull upstream &lt;branch-name&gt;</pre><p>Merge will fail if any conflicts occurred here. Then you have to resolve them and do commit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd1163dc828" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to change a commit message in Git…]]></title>
            <link>https://kmtsandeepanie.medium.com/how-to-change-a-commit-message-in-git-e7578f451522?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7578f451522</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Sun, 01 Dec 2019 05:14:40 GMT</pubDate>
            <atom:updated>2021-05-25T06:58:27.815Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Change a Commit Message in Git…</h3><p>By this article , let’s see how to change a commit message in Git ..Sometimes due to the incorrect commit messages, you may have found yourself in a situation where you want to edit a commit message. 😩 Your commit may be a most recent or a very old one, or may be already pushed or may not. However, let’s see how to change your commit message for all of these scenarios one by one 😉</p><h4>A) Changing the most recent and not pushed commit message</h4><p>If you haven’t pushed your commit to remote repository yet, simply type following command to change your most recent commit message.</p><pre>git commit --amend -m <strong>&quot;correct commit message&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*7_6aQsgJxrY2MdfMQfPXJg.png" /></figure><p><strong>or </strong>, type following command and press enter.</p><pre>git commit --amend</pre><p>Then your text editor will appear as shown in below and you can type the new commit message and save the commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*VfRx8hXn_BPahUWQABIRWg.png" /></figure><p>( I recommend you to change your default text editor for Git into <strong>vim editor..</strong> for Ubuntu users you can download vim editor using <a href="https://phoenixnap.com/kb/how-to-install-vim-ubuntu">this</a> link. After downloading you can configure it using the following command. )</p><pre>git config --global core.editor vim</pre><blockquote>In your vim editor , press <strong>i </strong>to edit a line and after editing press<strong> esc</strong> and <strong>:wq</strong> and enter to save and close the editor .</blockquote><h4>B) Changing the most recent and pushed commit message</h4><p>If you have already pushed your commit to remote repo , edit the message just like above and force push the update using below command.</p><pre>git commit --amend -m <strong>&quot;correct commit message&quot;<br></strong>git push origin &lt;branch-name&gt; --force</pre><h4>C) Changing an old and not pushed commit message</h4><p>We need to do an interactive rebase to find the commit you want to correct. Type below command and it will display the last n number of commits in your text editor.</p><pre>git rebase -i HEAD~n      // n is the number of commits to go back</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*048KvfvEqmYn7hVUyTWxwg.png" /></figure><p>There are two ways to change the commit message here.</p><ol><li>Simply replace the <strong>pick</strong> word with <strong>reword</strong> for the commits you want to correct the message.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*4H_u4Gk8IZwBHckOqcoWZg.png" /></figure><p>Then save and close the editor and now you can correct the commit message in each resulting commit file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*dJrcMR6SYey6tJc5xv0xUw.png" /></figure><p>Save and close the each commit file. Then your commit messages will be changed successfully.</p><p><strong>or ,</strong></p><p>2. Simply replace the <strong>pick</strong> word with <strong>edit</strong> for the commits you want to correct and save and close the editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*EIH6zpxqYvtm4lOKIytuig.png" /></figure><p>And then you can change the commit message using following command.</p><pre>git commit --amend -m <strong>&quot;correct commit message&quot;</strong></pre><p>And then type this to go to the next commit which you want to change the message.</p><pre>git rebase --continue</pre><p>Do this for each commit and finish the rebase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*-fFmK1Msrawpvu7Kug4VGQ.png" /></figure><p>Then your commit messages will be changed successfully.</p><blockquote>In any case, if you go wrong inside the rebase , you can type below command and abort the changes in rebase.</blockquote><pre>git rebase --abort</pre><h4>D) Changing an old and pushed commit message</h4><p>Here , you can edit the message as in part C) and then force push the updates using below command.</p><pre>git push origin &lt;branch-name&gt; --force</pre><p>Happy Coding !! 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7578f451522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write clean code…]]></title>
            <link>https://kmtsandeepanie.medium.com/how-to-write-clean-code-82aa5db6889d?source=rss-55a4826be761------2</link>
            <guid isPermaLink="false">https://medium.com/p/82aa5db6889d</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tharuja Sandeepanie]]></dc:creator>
            <pubDate>Sun, 17 Nov 2019 05:26:41 GMT</pubDate>
            <atom:updated>2021-05-25T06:57:27.418Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Write Clean Code….</h3><p>Have you ever suffered from the bad code? If you are a programmer you definitely have felt so.You may have totally messed up by your own bad code…</p><p><strong><em>The only valid measurement of code quality is WTFs/minute.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*BFMHALYy5jG9H-10bNfFnw.jpeg" /></figure><p>Writing just only a well functioning code is not enough. It should be a clean code as well. Because it makes the code readable and makes easy to understand by anyone, doesn&#39;t matter whoever wrote the code. So it is the time to be a good programmer, not just a programmer. By this article, I will give you some tips on how to write clean code based on the knowledge I gained through the book “<strong><em>Clean Code by Robert C.Martin</em></strong>”.</p><p><em>So, What is clean code….?</em></p><p>If your code is elegant, efficient, simple, readable , contains no duplication, having expressiveness and runs all the tests, then it is simply a clean code.</p><p><strong>1-</strong> First let’s see,<strong> formatting</strong> in a code.Why do we need to focus on formatting? Because having accurate formatting in a code improves the readability of your code and it makes easy to change and maintain your code.</p><p><strong>A)</strong> In a code , group of lines represents a complete thought.(package name, imports, classes, functions ) When considering vertical formatting , better to separate complete thoughts by a blank line as shown in below.</p><pre><strong>package </strong>org.ballerinalang.stdlib.services.nativeimpl.cookie;<br><br><strong>import </strong>org.testng.Assert;<br><strong>import </strong>org.testng.annotations.BeforeClass;<br><strong>import </strong>org.testng.annotations.Test;<em><br><br></em><strong>public class </strong>CookieFunctionTest {</pre><pre>}</pre><p><strong>B)</strong> And also , concepts that are closely related to each other should be kept vertically close. For example: -</p><ul><li>Better to declare variables as much as close to their usage. When considering local variables, it is better if they are declared at the top of each function, control variables used in for loops should be declared within the loop statement. Instance variable declaration should appear at the top of the class.</li><li>When considering dependent functions , they should be vertical closed as the caller function is above the callee. Functions should appear in the code according to the order of they are used.</li><li>Based on the direct dependence such as a function calling to another or a function uses a variable or group of functions perform a similar task , their affinity becomes stronger and so that their vertical distance should be lesser. Follow below code.</li></ul><pre><strong>Cookie cookie = new;</strong></pre><pre><strong>function </strong>addPersistentCookie(Cookie cookie) {<br>    <strong>if </strong>(isExpired(cookie)) {<br>         self.allCookies[self.allCookies.length()] = cookie<strong>;</strong>    <br>    }<br>}<br><em><br></em><strong>function </strong>isExpired(Cookie cookie) returns boolean<strong> </strong>{<br>    time:Time curTime = time:currentTime()<strong>;<br>    if </strong>(cookie.expires &lt; curTime.time) {<br>        <strong>return true;<br>    </strong>} <strong>else </strong>{<br>        <strong>return false;<br>    </strong>}<br>}</pre><p><strong>C)</strong> Horizontal white space can be used to associate strongly related things and disassociate weakly related things.</p><ul><li>Keep a white space in both side of the assignment operator. These spaces make the variable name and value separation obvious .</li></ul><pre><strong>int </strong>maxAge = 0<strong>;</strong></pre><ul><li>In a while or if block , keep a space between if/while and parentheses and braces . See, how spaces are kept in below code.</li></ul><pre><strong>if </strong>(<strong>self</strong>.expires == <strong>&quot;&quot; </strong>&amp;&amp; <strong>self</strong>.maxAge == 0) {<br>    <strong>return false;<br></strong>} <strong>else </strong>{<br>    <strong>return true;<br></strong>}<br></pre><pre><strong>while </strong>(i &lt; myArray.length()) {<br>    i = i + 1;<br>}</pre><ul><li>Don’t keep space between function name and parameters.</li><li>Keep a comma and space between arguments in a function.</li></ul><pre><strong>boolean isPersistent</strong>(maxAge, expires)<strong> </strong>{<br>    <strong>if </strong>(expires == <strong>&quot;&quot;  &amp;&amp; </strong>maxAge == 0) {<br>        <strong>return false;<br>    </strong>} <strong>else </strong>{<br>        <strong>return true;<br>    </strong>}<br>}</pre><ul><li>Keep spaces to focus attention on the precedence of operators.</li></ul><pre>  (-b - Math.sqrt(determinant)) / (2*a);</pre><ul><li>Better to use unaligned variable declaration and assignment (unless we tempt to look at only variable names without looking at the type or values or assignment operator).</li></ul><pre><em>//Avoid this                                                   <br></em><strong>public string    </strong>name =         <strong>&quot;SID003&quot;;                     <br>public string    </strong>value =        <strong>&quot;7388984hjs&quot;;                 <br>public string    </strong>domain =       <strong>&quot;example.com&quot;;              <br>public string    </strong>path =         <strong>&quot;/sample&quot;;                    <br>public int       </strong>maxAge =       3600<strong>;                         <br>public </strong>time:Time creationTime = time:currentTime()<strong>;         <br><br></strong><em>//Use this<br></em><strong>public string </strong>name = <strong>&quot;SID003&quot;;<br>public string </strong>value = <strong>&quot;7388984hjs&quot;;<br>public string </strong>domain = <strong>&quot;example.com&quot;;<br>public string </strong>path = <strong>&quot;/sample&quot;;<br>public int </strong>maxAge = 3600<strong>;<br>public </strong>time:Time creationTime = time:currentTime()<strong>;</strong></pre><ul><li>We must pay more attention to the indention in the code.Class declaration are not indented but functions within a class are indented one level to the right of the class. Contain of the method is indented one level to the right of the method . This rule also applies to the indention of a block contain. (if block or while block) .Most of time, we consider a one level indent as four spaces (one tab) .Check how indention is used in following code.</li></ul><pre>class Cookie {</pre><pre>    <strong>string </strong>name = <strong>&quot;SID003&quot;;<br>    string </strong>value = <strong>&quot;38748bnndx&quot;;<br>    <br>    boolean </strong>isValid(name<strong>, </strong>value) {<br>        <strong>if </strong>(name == <strong>&quot;&quot; </strong>|| value == <strong>&quot;&quot;</strong>) {<br>            <strong>return false;<br>        </strong>} <strong>else </strong>{<br>            <strong>return true;<br>        </strong>}<br>    }<br>}</pre><ul><li>Do not tempt to break this rule for short if or while loops or short functions.</li></ul><pre><em>//Avoid this<br></em><strong>public string </strong>render() throws Exception { <strong>return &quot;&quot;; </strong>}<br><br><em>//Use this<br></em><strong>public string </strong>render() throws Exception {<br>    <strong>return &quot;&quot;;<br></strong>}</pre><ul><li>And make sure dummy bodies in certain blocks in your code are also properly indented.</li></ul><pre>while (this.read(buf, 0, readBufferSize) != -1) <br>    ;</pre><p><strong>2-</strong> Next, we will see how to use<strong> meaningful names</strong> in your code. When we do programming , we have to use different different names in our code to declare variables, constants , functions and classes…But don’t forget to use meaningful names unless wtfs/minute rate for your code will get higher :D :D</p><p><strong>A)</strong> Always try to use intention revealing names. Name should be able to tell what is the purpose and why it exists.</p><pre><strong>int </strong>d<strong>; </strong><em>//days since creation        -  dirty code<br></em><strong>int </strong>daysSinceCreation;              -  clean code</pre><p><strong>B)</strong> Avoid using disinformation (inconsistent spellings and false conclusions) in names.</p><p>Example:- Use of lower-case L or uppercase O can be confused with one and zero. And using name as <em>accountList</em> but it is not actually a List , then it can give disinformation.</p><p><strong>C)</strong> Use pronounceable names as much as possible.</p><pre>--dirty code                   --clean code<br> Date genymdhms<strong>;               </strong>Date generationTimeStamp<strong>;<br> </strong>String rqstPath<strong>;              </strong>String requestPath<strong>;<br> </strong>String cmt<strong>;                   </strong>String comment<strong>;</strong></pre><p><strong>D)</strong> Use searchable names . Single letter names should only be used as local variables inside a short method. Length of a name is decided according to the size of its scope. If the name is used in multiple places , better to use a search friendly name.</p><p>Example :-If we use a constant as WORK_DAYS_PER_WEEK <em>to represent 5, it will be more easier to find it </em>rather than finding in all places where 5 was used.</p><p><strong>E)</strong> Don’t break the traditional variable names and make readers to mentally translate the names they already know, into other names.</p><p>Example:-Use loop counter as <em>i or j or k . Don’t use other names for loop counter.</em></p><p><strong>F)</strong> Make meaningful distinctions so that the reader can get to know what the difference offer by two names. You can’t use the same name to refer two different things in same scope.</p><p>Example:- “<em>product, productData, productInfo”-</em> these are different names but they have meaningless difference. “<em>info</em> and <em>data”</em> , “<em>a</em> and <em>an” </em>are indifferent noise words. Don’t use such names. Another examples for indifferent names are “<em>product</em> and <em>theProduct</em>” , “<em>customer</em>, <em>customerObject </em>and <em>customerInfo</em>”, “<em>money</em> and <em>moneyAmount.</em></p><p><strong>G)</strong> Use noun or noun phrase,but not a verb for class names. And use verb or verb phrase for method names (set, get prefixes can be used) .</p><p><strong>H) </strong>Try to add meaningful context if possible.</p><p>Example :-suppose we have to form an address using variables.We can use name as <em>“addStreet” , “addState</em>” for the variables rather than using “<em>street</em>” and “<em>state</em>”.</p><p><strong>I)</strong> All variables, functions and classes should use CamelCase style. The only difference is a first letter of class should be capital.Constants should use all capital letters and divided with underscore if have two words.</p><pre><strong>class Example {<br>    int </strong>maxAge = 0<strong>;<br>    boolean </strong>httpOnly = <strong>false;<br>    const string </strong>EQUALS = <strong>&quot;=&quot;;<br>    boolean isValid() {<br>        //body<br>    }<br>}</strong></pre><p><strong>3-</strong> Using of <strong>unit tests </strong>is also a very important part as much as the production code.Because unit tests increase the flexibility , maintainability and usability in our code. Readability makes a test as a clean test . Here make sure that every test has one and only one assert statement and also only a single concept should be tested in each test function. Clean tests should have below five features.</p><ul><li>Fast - tests should run quickly.</li><li>Independent -test functions should not depend on each other.</li><li>Repeatable -tests should have the ability to run in any kind of environment.</li><li>Self-validating -tests should have a boolean output whether pass or fail.</li><li>Timely -unit tests should be written before the production code .Test functions should be in a timely fashion.</li></ul><p>Hope, this would be helpful for you in writing clean code. By my next article I will describe about functions and use of comments…. :D Happy Coding !!</p><h4>References :</h4><p>Clean Code — “A handbook of Agile Software Craftsmanship” — Robert C.Martin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82aa5db6889d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>