<?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 Milton Marma on Medium]]></title>
        <description><![CDATA[Stories by Milton Marma on Medium]]></description>
        <link>https://medium.com/@miltonmarma120?source=rss-109f0bf34562------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xi4XNu2XF-ZV3emklVosKA.jpeg</url>
            <title>Stories by Milton Marma on Medium</title>
            <link>https://medium.com/@miltonmarma120?source=rss-109f0bf34562------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:36:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@miltonmarma120/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[Create Custom Pipe in Angular to Replace Null Value With a Text]]></title>
            <link>https://javascript.plainenglish.io/create-custom-pipe-in-angular-to-replace-null-value-with-a-text-376b58b15b61?source=rss-109f0bf34562------2</link>
            <guid isPermaLink="false">https://medium.com/p/376b58b15b61</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Milton Marma]]></dc:creator>
            <pubDate>Tue, 06 Oct 2020 15:35:04 GMT</pubDate>
            <atom:updated>2022-12-15T12:00:40.623Z</atom:updated>
            <content:encoded><![CDATA[<h4>Basic pipe overview and step by step process to create a custom pipe in Angular</h4><h4>A Little Bit Of Background</h4><p>Pipe in Angular is a way to transform data in the HTML template. It doesn’t change the value of the data in the TypeScript file. A pipe takes in data as input and transforms it into the desired output. A good use case of the pipes is in transforming date format. Generally, the date-time format we get from the API data is not the format that we want to show the users. That’s when we can use the pipes to transform the data into the desired format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1bRfAeWhhc9-2YB-" /><figcaption>Photo by <a href="https://unsplash.com/@oskaryil?utm_source=medium&amp;utm_medium=referral">Oskar Yildiz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Built-in Pipes</h4><p>Angular provides <a href="https://angular.io/api/common#pipes">built-in pipes</a> for typical data transformations e.g. DatePipe, UpperCasePipe, LowerCasePipe, etc. so that we can transform our data into the desired format in the HTML template. Now, let’s see some examples with DatePipe.</p><p>In the below code(a slightly modified version of the official <a href="https://angular.io/api/common/DatePipe#usage-example">example</a>), we are using the <strong>date </strong>pipe. We have to place the pipe after a vertical line(|) in the template expression.</p><p>A pipe can accept optional parameters to modify the output. To pass parameters to a pipe, simply add a colon and the parameter value to the end of the pipe expression. In the below code, we are passing ‘shortTime’, ‘medium’ as a parameter for the <strong>date</strong> pipe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aea4fb0556c9803e7d8736522bdd9d2/href">https://medium.com/media/6aea4fb0556c9803e7d8736522bdd9d2/href</a></iframe><p>We will get the below output in the browser.</p><pre>Today is Sep 25, 2020</pre><pre>Or if you prefer, 09/25/2020</pre><pre>The time is 2:16 PM</pre><pre>Date from time stamp is Sep 25, 2020, 2:11:19 PM</pre><h4>Motivation for Our Custom Pipe</h4><p>We all love to give users the best user experience possible. So, if a value is null users won’t see anything in the browser. Not a good user experience. We will solve that problem by creating our own custom pipe that will replace the null or undefined value with a given text in the template expression.</p><h4>Let’s Create Our Custom Pipe</h4><p>We will use Angular CLI to create our own custom pipe using the below command.</p><pre>ng generate pipe replace-null-with-text</pre><p>Angular CLI will generate a skeleton file for our custom pipe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9c054904cf2d356408f32b327c9835/href">https://medium.com/media/bf9c054904cf2d356408f32b327c9835/href</a></iframe><p>The <strong>name </strong>specified in the <strong>@Pipe </strong>decorator is the name of the pipe (e.g. <strong>replaceNullWithText</strong>). We will use that name in HTML like the <strong>date </strong>pipe example.</p><p>In the <strong>transform </strong>method, the <strong>value</strong> parameter is the<strong> </strong>value<strong> </strong>we get from the HTML template, and <strong>args</strong> is the optional parameter we want to send to our custom pipe. Note that, you don’t have to use the same parameter name but remember that parameter position matters. The first parameter will always get the value from the HTML template and at least one parameter is mandatory.</p><p><em>If you are creating the pipe inside an Angular module like SharedModule then don’t forget to export it from the module.ts file otherwise you won’t be able to use it in the other modules. Or if you are not using Angular CLI to generate the skeleton file then you have to add the custom pipe class name in the module declarations too.</em></p><p>For our custom pipe, we want it to return a text value that we will pass from the template expression as a parameter when the value from the HTML template is null. So, in the below code we are checking the value from the HTML template is null or undefined. If the value is null/undefined then we are returning the <strong>replaceText</strong> parameter value or we are returning the same value.</p><p>We also added a default value ‘N/A’ for <strong>replaceText</strong>. So, if we don’t pass any parameter from our HTML template then for null/undefined value our custom pipe will return ‘N/A’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6661ffb0da7cb9be73d0af6123f60bec/href">https://medium.com/media/6661ffb0da7cb9be73d0af6123f60bec/href</a></iframe><p>Now Let’s see our custom pipe in action. 😃</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/093279998f6117fab2c6e5316a9008ec/href">https://medium.com/media/093279998f6117fab2c6e5316a9008ec/href</a></iframe><p>We will get the following output in our browser.</p><pre>Book Name : Awesome Book</pre><pre>Author Name : Author Name Not Available</pre><pre>Published at : Published Date Not Available</pre><pre>Price: N/A</pre><p>The<strong> book </strong>variable is not null so, our custom pipe won’t change the value and we won’t see any kind of transformation of book value in the output. But as our <strong>author </strong>and <strong>publishedAt </strong>value are null, our custom pipe will return the <strong>replaceText</strong> value which we passed from the HTML template as a parameter for our custom pipe, and for <strong>price</strong> we didn’t pass any parameter value to replace the null, so our custom pipe is returning the default replace text value which is ‘N/A’.</p><p>Yeah! 😃 We got our custom pipe in Angular.</p><p><em>I am also learning Angular almost every day. So, if I made any mistake please feel free to correct me and put your suggestions in the comment section.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=376b58b15b61" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/create-custom-pipe-in-angular-to-replace-null-value-with-a-text-376b58b15b61">Create Custom Pipe in Angular to Replace Null Value With a Text</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing with Python]]></title>
            <link>https://medium.com/@miltonmarma120/playing-with-python-8879797e10bb?source=rss-109f0bf34562------2</link>
            <guid isPermaLink="false">https://medium.com/p/8879797e10bb</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Milton Marma]]></dc:creator>
            <pubDate>Sat, 24 Aug 2019 17:39:43 GMT</pubDate>
            <atom:updated>2019-08-24T17:39:43.339Z</atom:updated>
            <content:encoded><![CDATA[<p>You heard that Python is a very cool programming language, right! So, why not take a look at it.</p><blockquote>The main focus of this blog is to introduce Python to someone who already knows at least the basics of programming and would like to explore the world of Python <em>😍</em>. So, If you are a completely new in programming thenn sorry mate! maybe this is not the right blog post for you. One more thing, we are using Python 3.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PBmchF3mz6W2JIx8" /><figcaption>Photo by <a href="https://unsplash.com/@robbie36?utm_source=medium&amp;utm_medium=referral">Robert Collins</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>Variables</strong></h4><p>You don’t need to define the type of a variable in Python and don’t need to add a semicolon too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f12236998cccd9d97f395a58257af09e/href">https://medium.com/media/f12236998cccd9d97f395a58257af09e/href</a></iframe><p>In the above code, the lucky_number variable is assigned with integer value 7 so Python will treat lucky_number as an int type and the same thing goes for other variables too.</p><p>The output of the above code is given below.</p><pre>7<br>10.5<br>Harry Potter and the Goblet of Fire<br>True</pre><p>But there is a catch! If you assign again lucky_number variable with a string or floating point number, Python won’t give you an error. Everything in Python is an object. So, it will just create a new object of string or floating point type and lucky_number variable will have a reference to that newly created object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54caecacad383295dc2127c90ab7197e/href">https://medium.com/media/54caecacad383295dc2127c90ab7197e/href</a></iframe><p>The output of the above code is given below. From the output, we clearly see that the type of lucky_number variable is changing with respect to the assigned value.</p><pre>7<br>&lt;class &#39;int&#39;&gt;<br>101.101<br>&lt;class &#39;float&#39;&gt;<br>My lucky number is Seven<br>&lt;class &#39;str&#39;&gt;</pre><h4><strong>Taking Input</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4923cbd6ebb86eba5567ffd1dc1efc29/href">https://medium.com/media/4923cbd6ebb86eba5567ffd1dc1efc29/href</a></iframe><h4><strong>Conditional Statement</strong></h4><p>The basic <strong>if </strong>statement in Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a829d0cd9daea0e51e9c9b35d38407f/href">https://medium.com/media/4a829d0cd9daea0e51e9c9b35d38407f/href</a></iframe><p><strong>If</strong> statement with <strong>and</strong> <strong>or </strong>logic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc374986f9ce4377f8f19162a9a5889/href">https://medium.com/media/6fc374986f9ce4377f8f19162a9a5889/href</a></iframe><h4><strong>Loop</strong></h4><p>This while loop will print 1 to 10.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d7f05bc9e1a96c816249ccaf6b983ad/href">https://medium.com/media/1d7f05bc9e1a96c816249ccaf6b983ad/href</a></iframe><p>This will print all the even number e.g. 2, 4, 6, 8, 10.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e92c48f90417f8d62f0c0a200dc9e81/href">https://medium.com/media/9e92c48f90417f8d62f0c0a200dc9e81/href</a></iframe><p>This for loop will print 1 to 10. Here I used <a href="https://docs.python.org/3/library/stdtypes.html#range">range</a> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fbee4a36940a010548f4a9515a0036b/href">https://medium.com/media/1fbee4a36940a010548f4a9515a0036b/href</a></iframe><p>This will print all the odd number in the range e.g. 1, 3, 5, 7, 9</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cfad867f2172c76915ddeaa8f66810b/href">https://medium.com/media/9cfad867f2172c76915ddeaa8f66810b/href</a></iframe><h4><strong>Function</strong></h4><p>Functions don’t need to define a return type in Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c516cdc2e39cbf2d6ed4ead3274e88b8/href">https://medium.com/media/c516cdc2e39cbf2d6ed4ead3274e88b8/href</a></iframe><h4><strong>List</strong></h4><p>A List is like an array in other programming language but more versatile. It is used to store a list of values.</p><p>Let’s take a look at lists with different data types. Python list indexes also start from 0.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab1c988f7471ad732c39f053553aafd4/href">https://medium.com/media/ab1c988f7471ad732c39f053553aafd4/href</a></iframe><p>You can also loop through the list easily. This will print all the prime number in the <strong>prime_number_list</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40b31364e7929b0632e427124a7a0d2c/href">https://medium.com/media/40b31364e7929b0632e427124a7a0d2c/href</a></iframe><h4><strong>Tuple</strong></h4><p>A Tuple is similar to list but Tuple is <strong>immutable</strong>.</p><p><em>“Wait! What is </em><strong><em>immutable</em></strong><em> ?”</em></p><p>In Object Oriented Programming <strong>mutable</strong> objects can be changed after it is created and <strong>immutable</strong> objects can’t be changed after creation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5903f328cb685b35ef9df339f8b0a11/href">https://medium.com/media/a5903f328cb685b35ef9df339f8b0a11/href</a></iframe><h4><strong>Set</strong></h4><p>Set in Python is a data structure equivalent to sets in mathematics. Every element in Set is unique (e.g. duplicate element is not allowed) and must be <strong>immutable. </strong>Though all the elements in Set must be <strong>immutable</strong> Set itself is <strong>mutable</strong> e.g you can add and remove elements from a Set.</p><p>Set is an <strong>unordered</strong> collection. This means that if you loop through the set, elements may not appear as your input order or in which order you initialized the set.</p><p><em>“But Why??? It doesn’t look that much cooler!”</em></p><p>Calm down, folk! 😊 This allows checking if an element belongs to a set faster than just going through all the elements of the set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a6ce0495d4c1cc623eab25dea9e2974/href">https://medium.com/media/0a6ce0495d4c1cc623eab25dea9e2974/href</a></iframe><p>In duplicate_value_set there are some duplicate values but when we are printing we are seeing just unique elements because the set doesn’t allow duplicate elements.</p><h4><strong>Dictionary</strong></h4><p>Dictionary is a key: value data structure in Python. Each key is mapped to a value and each key is unique. You can get the value using the key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f393427c0c791155372d300c449536d8/href">https://medium.com/media/f393427c0c791155372d300c449536d8/href</a></iframe><p><strong><em>“But Hey !!! Where is our favorite main function???”</em></strong></p><p>At first, we have to learn about a particular variable, <strong>__name__</strong> that Python interpreter defines before executing the source code. __name__ is automatically set to <strong>__main__ </strong>if the program is executed by itself. If the python source file is imported as a <a href="https://docs.python.org/3/tutorial/modules.html">module,</a> python interpreter sets the __name__value to that module name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ac99427a5e540e0e336242899265a5e/href">https://medium.com/media/2ac99427a5e540e0e336242899265a5e/href</a></iframe><p>The output of the above code when the source file is directly executed.</p><pre>i love python.<br>__name__ value : __main__</pre><p>Python doesn’t have a defined entry point (e.g. main function) like C++, Java. It executes a source file sequentially. We are using <strong>if </strong>statement to create the <strong>main</strong> function which will be executed if the file is loaded as the &quot;__main__&quot; module rather than as a library in another module.</p><p>Okay. Let’s look at an example with the main function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/554bdedfcc94d1f09ba3094b460f578e/href">https://medium.com/media/554bdedfcc94d1f09ba3094b460f578e/href</a></iframe><h4>Variable Length Argument</h4><p>Variable length argument means a function can receive any number of arguments.</p><p>First, let’s take a look at some positional and keyword argument example to get a clear idea.</p><pre>foo(1, 2)          # two positional argument 1 and 2<br>foo(city=&#39;Dhaka&#39;)  # one keyword argument with keyword city<br>foo(5, a=6)        # one positional argument, one keyword argument</pre><p>In the below code *args can receive any number of positional arguments and the type of *args will be tuple.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d1832dd21974feb223834647b186976/href">https://medium.com/media/4d1832dd21974feb223834647b186976/href</a></iframe><p>Python first fills the slots given formal arguments by passing positional actual arguments. Any leftover positional arguments are received by a variable prefixed with *.</p><p>In the below code, lucky_number will get the first argument of the my_args function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b38614babae7f85bf0dbc57551cc4eb8/href">https://medium.com/media/b38614babae7f85bf0dbc57551cc4eb8/href</a></iframe><p>The output of the above code.</p><pre>lucky number: 1<br>other numbers: (2, 3, 4)<br>lucky number: 7<br>other numbers: (10, 2)</pre><p>In the below code **kwargs can receive any number of keyword arguments and the type of **kwargs will be dictionary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a1bb853ac5d1557bff5861a0905a03e/href">https://medium.com/media/2a1bb853ac5d1557bff5861a0905a03e/href</a></iframe><h4><strong>Class</strong></h4><p>Here we are creating a circle class and using __init__()<strong> </strong>method to initialize the radius value. __init__() is a special method which is called after a new object is created.</p><p>In Python, we have to pass the class instance as the first parameter of a method and the below code we named it as <strong>self</strong>.</p><p><strong><em>self </em></strong><em>is not a reserved keyword in Python, it’s just the convention that everyone follows.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5645415cd061a43ac122dc81814bcf9/href">https://medium.com/media/a5645415cd061a43ac122dc81814bcf9/href</a></iframe><p>Notice that get_area method has a parameter named self but we didn’t pass any value for self when calling my_circle.get_area() because whenever an object calls its method Python automatically passes the object instance as the first argument.</p><p>The term <strong>method </strong>and <strong>function </strong>is not the same<strong> </strong>in Python. Methods are associated with object instance or classes and they need to pass the object instance as the first argument.</p><p>Now let’s learn about <strong>class variable</strong> and <strong>instance variable</strong>.</p><p>Class variables are shared by all the instances of a class.</p><p>Instance variables are unique to all instance of a class and defined inside a class method.</p><p>In the below code, we removed the hard coded value of pi with a class variable named pi So in every Circleclass instance the value of pi will be 3.1416.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe73c79788093edca682589e18db401d/href">https://medium.com/media/fe73c79788093edca682589e18db401d/href</a></iframe><blockquote><em>If you want to change the value of a class variable then you have to do it with the notation ClassName.ClassVariableName. Otherwise, you will end up creating a new instance variable with the same name as the class variable.</em></blockquote><pre>print(my_circle.pi) # it will print 3.1416<br>my_circle.pi = 5    # it creates a new instance variable named pi<br>print(my_circle.pi) # it will print 5<br>print(Circle.pi)    # it will print 3.1416</pre><p>When you try to access a variable from an instance of a class then it first looks at its <strong>instance </strong><a href="https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces"><strong>namespace</strong></a>. If it finds the variable then returns the associated value. If not found then it goes to the <strong>class namespace</strong></p><p>so when you do print(my_circle.pi) the variable pi won’t be found in <strong>instance namespace</strong>, it will be found in the <strong>class namespace</strong>. So it will give 3.1416 as output.</p><p>After doing my_circle.pi = 5 , a new instance variable is created and assigned with value 5. So now print(my_circle.pi) will give 5 as the variable pi will be found in <strong>instance namespace.</strong></p><h4>Higher Order Function</h4><p>A higher order function is a function that does at least one of the following:</p><ul><li>takes one or more functions as argument</li><li>returns a function as its result</li></ul><p>I have borrowed the definition from <a href="https://en.wikipedia.org/wiki/Higher-order_function">Wikipedia</a> 😊</p><p>Now we have to learn a little bit about <a href="https://en.wikipedia.org/wiki/First-class_citizen">first-class</a> citizens or objects in the programming language. First-class objects or citizens in the programming language is an entity which supports all the operations generally available to other entities such as being passed as an argument, returned from a function, modified, and assigned to a variable.</p><p>In Python, functions are treated as the first-class object. So, you can pass one or more functions as argument, return a function and assign a function to a variable.</p><p>Let’s look at an example of a function which takes another function as argument. In the below example, if we pass increment_by_one function to my_counter then the number will be incremented by one and if we pass decrement_by_one the number will be decremented by one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9194ecbff0d59f9442ef6d0a85c0047/href">https://medium.com/media/a9194ecbff0d59f9442ef6d0a85c0047/href</a></iframe><p>In the below example, get_proper_counter function is returning a function (increment_by_one or decrement_by_one) according to counter_type and we are assigning the returned function to a variable. Then we can use the variable as function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94804675bd09171c8a0313c9052cf26b/href">https://medium.com/media/94804675bd09171c8a0313c9052cf26b/href</a></iframe><h4>Closure</h4><p>To learn closure, we have to learn about <strong>nested function</strong> in Python first.</p><p>A function that is defined inside another function is called a nested function. Nested functions can access the variables of the enclosing scope. In the below example, outer_function is the enclosing function, message is the enclosing variable and inner_function is the nested function. inner_function is accessing the non-local variable message and printing it’s value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/200b1d8067db3bdaf2a7fc7874df5f51/href">https://medium.com/media/200b1d8067db3bdaf2a7fc7874df5f51/href</a></iframe><p>A Closure is a function object that remembers values in enclosing scopes even if they are not present in memory. Now let’s update the above code to a closure.</p><p>In the below code, even if we deleted the outer_function the inner function can print the value of the message variable e.g. ‘“hello world”. Notice that we are now returning inner_function .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb0035eb1994eaf1e6787ce659b24a67/href">https://medium.com/media/eb0035eb1994eaf1e6787ce659b24a67/href</a></iframe><p>In the below code, multiplicand value is attached to multiplier function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b55b01ec2a5c85a39b71c606e90bac99/href">https://medium.com/media/b55b01ec2a5c85a39b71c606e90bac99/href</a></iframe><h4>Decorator</h4><p>Python decorator is the function that receives a function as an argument and returns another function as the return value. Decorators are called before the definition of a function you want to decorate.</p><p>In the below code capitalize is a decorator. It takes hello_python function as argument and returns capitalized value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac64165ce6c1a11abc4179adaad74ec/href">https://medium.com/media/1ac64165ce6c1a11abc4179adaad74ec/href</a></iframe><p>We can use the @ symbol along with the name of the decorator function and place it above the definition of the function to be decorated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af93367c3954837b4c6c3b8169c6fd5c/href">https://medium.com/media/af93367c3954837b4c6c3b8169c6fd5c/href</a></iframe><p>Decorators can also take argument. In the below code, formatting decorator is taking lower_case argument and returns the result according to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabe897f154d0609c78dda88f066ec35/href">https://medium.com/media/fabe897f154d0609c78dda88f066ec35/href</a></iframe><p>A function can be decorated many times. But the order of decoration affects how the final output will be.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98e82233124349f2a0469dab5b8ff361/href">https://medium.com/media/98e82233124349f2a0469dab5b8ff361/href</a></iframe><p>here, the interpreter is just doing hello_python = a(b(c(hello_python)))</p><p>If you are interested in algorithms and data structure implemented using Python then you can look at this Github <a href="https://github.com/TheAlgorithms/Python">repository</a>.</p><p><em>I am also learning Python as a beginner and don’t familiar with many advanced and intermediate-level Python features and concepts. So, if I made any mistake please feel free to correct me and put your suggestions in the comment section.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8879797e10bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git for beginner++]]></title>
            <link>https://medium.datadriveninvestor.com/git-for-beginner-f438adfc3599?source=rss-109f0bf34562------2</link>
            <guid isPermaLink="false">https://medium.com/p/f438adfc3599</guid>
            <category><![CDATA[gitflow]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Milton Marma]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 20:16:02 GMT</pubDate>
            <atom:updated>2018-11-28T16:45:10.579Z</atom:updated>
            <content:encoded><![CDATA[<p>You know the basic of git workflow and familiar with some basic commands like add, commit, push, pull then maybe this post is for you. This post is mainly focused on daily git use improvement, fixing some common mistakes and a step towards advance git learner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Oyf1Blvxr3Tsr37O" /><figcaption>“closeup photo of eyeglasses” by <a href="https://unsplash.com/@ikukevk?utm_source=medium&amp;utm_medium=referral">Kevin Ku</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong># Scenario with add</strong></h4><p>You just want to add files with specific extension in your staging area. Of course you can add all the files one by one. But you can use *.&lt;extension_name&gt; to include all files with that extension. Following command will add all python files.</p><pre>git add *.py</pre><p>You want to add files with specific extension and also want to specify directory name then you can run the following command. The following command will add all python files from sub directories of models/ directory.</p><pre>git add models/\*.py</pre><h4># Scenario with clean</h4><p>You created some new files or folders in your branch. After some time you realized that you don’t want those files or folders. You need your working tree clean. These are untracked files in git.</p><p><em>Untracked files are those which you didn’t add already using </em><em>git add</em></p><p>To make your working tree clean you can run the following command. This command will delete all files and directories that are not tracked by git.</p><pre>git clean -df</pre><p>If you want to see which untracked files will be removed before removing then you can run this command.</p><pre>git clean -dn</pre><h4># Scenario with rm</h4><p>Now you want to delete your tracked files. You can delete your tracked file using this command.</p><pre>git rm &lt;file-path&gt;</pre><p>If your file is in staging area then you have to give additional <strong>force flag.</strong></p><pre>git rm &lt;file-path&gt; -f</pre><p>You want to delete files from git repository but not from your file system then you can run this command.</p><pre>git rm --cached &lt;file-path&gt;</pre><h4><strong># Scenario with branch</strong></h4><p>You have made a typo in your branch name or you want to change your branch name, then the following command will change your branch name.</p><pre>git branch -m &lt;old-branch-name&gt; &lt;new-branch-name&gt;</pre><p>You want to change the current branch name, then you can just run the following command.</p><pre>git branch -m &lt;new-branch-name&gt; </pre><p>If you’ve already pushed the branch with old name, then there are a couple of extra steps required. You need to delete the old branch from the remote and push up the new one.</p><pre>git push &lt;remote-name&gt; --delete &lt;old-branch-name&gt;<br>git push &lt;remote-name&gt; &lt;new-branch-name&gt; </pre><p>You want to push your local branch code but your local branch name doesn’t match with the name of remote repository branch name. Then you can run the following command.</p><pre>git push &lt;remote-name&gt; &lt;local-branch-name&gt;:&lt;remote-branch-name&gt; </pre><h4># Scenario with log</h4><p>You want to see your commit history so you just ran a git log command. This shows a lot of information but you just need to see commit id and message. Then you can run the following command.</p><pre>git log --oneline</pre><p>git log --oneline will show the following kind of output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1NZBtY_zieo9YV_P9Is7w.png" /></figure><p>The first seven character in above output is the <strong>shorthand commit id</strong> and then we have our commit message. The commit id is shorthand because the full commit id is forty hexadecimal characters that specify a 160-bit SHA-1 hash. Notice Head -&gt; master . This means we are now in master branch.</p><p>If you want to see the commit message of a specific author, then you can run the following command. I am assuming the author name is John Doe.</p><pre>git log --author=&quot;John Doe&quot;</pre><h4># Scenario with stash</h4><p>You are working in a branch and made some changes. Now, you want to just see the output or code of that branch before you made those changes. Then you can run stash command. It will make your working tree clean.</p><pre>git stash</pre><p>If you want your changes back then you have to run the following command.</p><pre>git stash pop</pre><p>If you don’t want those changes back then you have to run the following command.</p><pre>git stash drop</pre><p>You changed some files in wrong branch. Then you can stash your changes and<strong> checkout </strong>to your desired branch and run git stash pop there. You will get your changes in your desired branch.</p><h4># Scenario with checkout</h4><p>You want to switch to a branch. Then you can just run the following command.</p><pre>git checkout &lt;branch-name&gt;</pre><p><em>If you already changed some file in your current branch, then be sure to </em><em>stash your changes or </em><em>commit the changes. . If you don’t </em><em>stash or </em><em>commit those changes, it will also reflect in your switched branch which you may not want or need.</em></p><p>You have a branch name development and you want to make a branch from development and switch to your new branch directly. Then you can run the following command.</p><pre>(development)$ git checkout -b &lt;your-new-branch-name&gt;</pre><p>You can also checkout using commit id. You can use shorthand commit id safely if your project isn’t very large.</p><pre>git checkout &lt;commit-id&gt;</pre><p><em>This will fall in </em><strong><em>detached head </em></strong><em>state in git. </em><strong><em>Head</em></strong><em> is simply a reference to the current commit (latest) on the current branch</em>.<em> Generally, </em><strong><em>Head </em></strong><em>in git can point to a branch or a commit. When Head points to a branch, git doesn’t complain. But when head points to a commit, but not a branch then it goes to a </em><strong><em>detached head</em></strong><em> state.</em></p><p>You want to develop a feature from this <strong>detached head</strong> state then you have to make a branch from this state and develop your feature there.</p><pre>git checkout -b &lt;your-new-branch-name&gt;</pre><h4># Scenario with commit</h4><p>You just added a commit message and realized that there is a typo in your commit or you just want to make your commit message more expressive and understandable. Then you can use the following git command.</p><pre>git commit --amend -m &quot;your-new-commit-message&quot;</pre><p>If you just added some files or fixed a bug but don’t want to add another commit message then you can use following git command with --no-edit flag.</p><pre>git commit --amend --no-edit</pre><p><em>Here one thing is very important to remember that amending the last commit rewrites the commit history. It means your </em><strong><em>commit id</em></strong><em> will change when you amend a commit.</em></p><p>If you already pushed your code in the remote repository and then you realized that you have to amend your commit message then after amending, you have to make a <strong>force push. </strong>Assuming your remote name as origin you can run the following command.</p><pre>git push origin &lt;branch-name&gt; -f</pre><h4># Scenario with reset</h4><p>You want to discard your last some commits. Then you can use git reset to discard those commits. There are three flag for git reset that you should know.</p><ul><li>--soft</li><li>--mixed</li><li>--hard</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gv06pFgMVOT5x4yJvcGRrQ.png" /></figure><p>Let’s assume you want to discard the changes until <strong>added two.txt </strong>which has commit id<strong> 96b037c</strong></p><p>Now, let’s run git reset command with --soft flag.</p><pre>git reset --soft 96b037c</pre><p>git reset --soft will make <strong>orphan </strong>all the commits after that commit id (e.g. 96b037c) but the files will not be deleted. The files will be in the staging area.</p><p><strong>Orphaned</strong> commit means there is no direct path from a ref to access them. These orphaned commits can usually be found and restored using git reflog Git will permanently delete any orphaned commits after it runs the internal garbage collector. By default, git is configured to run the garbage collector every 30 days.</p><p>So, if you run git status you will see the following output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAD1jfH8Xx5a6spnFLWGxA.png" /></figure><p>If you run git log --oneline you will see that previous commits are deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8sZRcyP4kky7RsqGG2qCw.png" /></figure><p>If you run reset command with --mixed flag then your commits will be <strong>orphaned</strong> and the files will not be in staging area but the files will be found in the file system. If you don’t specify any flag in reset then git will use --mixed flag as default.</p><p>If you run git status then you will see the following output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnhPheN0MvBqdalJDarGoQ.png" /></figure><p>If you want to permanently delete the files then you can run reset command with --hard flag.</p><p><em>A good practice you can follow that you first run reset command with </em><em>--soft flag and see the affected files. If you are sure that you don’t want those changes then you can run the reset command with </em><em>--hard flag.</em></p><p>You should never use git reset &lt;commit-id&gt; when any snapshots after &lt;commit-id&gt; have been pushed to a public repository. Removing a commit that other team members have continued developing poses serious problems for collaboration.</p><h4># Scenario with revert</h4><p>You are working in a public repository and you want to undo a commit. Then you can run the following command.</p><pre>git revert &lt;commit-id&gt; --no-commit</pre><p>After running the above command, you can check the affected files using git status . Then you have to make a commit using git commit -m &quot;commit-message&quot; .</p><p><em>git revert will not</em><strong><em> orphan </em></strong><em>a commit. It will just undo the changes of your reverted commit id.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gwJgqYECujtC3__mDX68zw.png" /></figure><p>Let’s assume you want to revert the last commit. Then after reverting your status will look like following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egKJ4OeiGOItiDEJZPyBrQ.png" /></figure><p>Before the last commit <strong>six.txt </strong>file was not added, so it is deleted and<strong> five.txt </strong>is changed back to it’s previous state. Now, after committing your commit history will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiWmXUWG5LLk3Q5QMMJprA.png" /></figure><p>You want to revert multiple commits within a range then you can run the following command.</p><pre>git revert &lt;oldest-commit-id&gt;..&lt;recent-commit-id&gt; --no-commit</pre><p>If you want to revert multiple commits that are not within a range then you have to provide every commit id that you want to revert.</p><pre>git revert &lt;commit-id-1&gt; &lt;commit-id-2&gt; --no-commit</pre><h4># Scenario with cherry-pick</h4><p>You are working in a branch and you need a commit(e.g. a bug fix commit) from another branch to work in your current branch. Then you can use cherry-pick command to get that commit in your current branch. It is also helpful if you committed in the wrong branch and want the commit in another branch.</p><p>First, you have to switch to the branch that has the commit. Copy the commit id of that commit and switch back to your own working branch. Then run the following command to get the commit in your working branch.</p><p><em>git cherry-pick is like copying something from a folder and pasting it in another folder. So, it will not delete the commit from where you cherry picked and in destination branch commit id will also be different.</em></p><pre>git cherry-pick &lt;commit-id&gt;</pre><p><em>I am also learning git almost everyday and don’t consider myself as an advance git user. So, if I made any mistake please feel free to correct me and put your suggestions in the comment section.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f438adfc3599" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/git-for-beginner-f438adfc3599">Git for beginner++</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>