<?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 Anurag Ambuja on Medium]]></title>
        <description><![CDATA[Stories by Anurag Ambuja on Medium]]></description>
        <link>https://medium.com/@anuragambuja?source=rss-4221b3ff2d6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MJM1Mg6JlbZXOiyX9hQtlw.jpeg</url>
            <title>Stories by Anurag Ambuja on Medium</title>
            <link>https://medium.com/@anuragambuja?source=rss-4221b3ff2d6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 30 May 2026 22:37:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anuragambuja/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[Getting started with Prefect 2]]></title>
            <link>https://medium.com/@anuragambuja/getting-started-with-prefect-2-57f281a9b042?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/57f281a9b042</guid>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[orchestration]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[prefect]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Sun, 04 Dec 2022 14:41:19 GMT</pubDate>
            <atom:updated>2022-12-04T14:41:19.907Z</atom:updated>
            <content:encoded><![CDATA[<h4>Accelerate development, Testing and Deployment of Workflows</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WwTs8yvtEgLWNMiXUw-e7Q.jpeg" /></figure><p>Prefect is a python based orchestration tool. But why Prefect when we already have multiple workflow management system in place ? Why one should prefer Prefect over Airflow, Dragster, ControlM etc. Well, I won’t go into that debate. Lets explore Prefect as of now and see if that suits your requirement.</p><p>This guide is here to help you get started with next gen of Prefect — Prefect 2.</p><p>The article will guide you how to:</p><ul><li>Install Prefect locally</li><li>Write a basic ETL flow using Python</li><li>Run Flow locally and use Orion Server</li><li>Run Flow using Prefect Cloud</li></ul><p><em>Below code has been run on Windows machine using VS code but will work alike in mac/Linux environment.</em></p><p>Basic Terminology</p><blockquote>Tasks — A <em>task</em> is a Python function that handle workload. It optionally takes inputs, performs action and produces output.</blockquote><blockquote>Flows — Prefect refers to a workload as a “flow”. Loosely stated — they are like DAGs of Airflow. <em>Flow</em> consists of <em>tasks</em>. <em>It </em>describes the order in which the <em>tasks</em> are executed. Flows can include calls to tasks as well as to child flows, which are “sub flows” in this context.</blockquote><blockquote>Prefect Cloud — A hosted UI to orchestrate workflows and provide visualization into the status of different flows and runs.</blockquote><blockquote>Agents - Daemon process running on your local/cloud machine which executes flows when scheduled using Prefect Cloud.</blockquote><p><strong>Step 1: Installation</strong></p><p>Prefect 2 requires Python 3.7 or later. There are multiple ways to <a href="https://docs.prefect.io/getting-started/installation/">install Prefect</a>.</p><p>Here, we will create a virtual environment and install requests, pandas and prefect which will be used in the demo script.</p><pre># set up virtual environment in Windows machine. <br>python -m venv venv # create the env <br>Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Optional<br>.\venv\Scripts\activate # activate the virtual env</pre><p>Install Prefect along with modules used in the script using pip</p><pre>pip install requests pandas prefect</pre><p><strong>Step 2: Write ETL flow and run it locally</strong></p><p>The ETL pipeline will download data from a <a href="https://jsonplaceholder.typicode.com/posts">dummy API</a>, do basic transformation and save the file on the disk. Below is the description of different functions used in script:</p><blockquote>extract(url: str) -&gt; dict makes a GET request to the url parameter which returns a dictionary else raises an exception.</blockquote><blockquote>transform(data: dict) -&gt; pd.DataFrame — transforms the data i.e. the output returned by extract by keeping just id, userid and title and returns the transformed data as a Pandas dataframe.</blockquote><blockquote>load(data: pd.DataFrame, path: str) -&gt; None — does not return anything. It saves the transformed data to a CSV file at path and append a timestamp to the file name.</blockquote><p>Let’s create a python file, call it demo.py and a directory data to store the transformed data as CSV.</p><p><strong>Code Snippet</strong></p><pre>import json<br>import requests<br>import pandas as pd<br>from datetime import datetime<br>from prefect import task, flow<br><br><br>@task(name=&quot;Extract Task&quot;, description=&quot;Makes request.&quot;, retries=10, retry_delay_seconds=10)<br>def extract(url: str) -&gt; dict:<br>    res = requests.get(url)<br>    if not res:<br>        raise Exception(&#39;URL seems unavailable!&#39;)<br>    return json.loads(res.content)<br><br>@task(name=&quot;Transform Task&quot;, description=&quot;Transform Existing Data.&quot;)<br>def transform(data: dict) -&gt; pd.DataFrame:<br>    transformed = []<br>    for user in data:<br>        transformed.append({<br>            &#39;ID&#39;: user[&#39;id&#39;],<br>            &#39;UserId&#39;: user[&#39;userId&#39;],<br>            &#39;Title&#39;: user[&#39;title&#39;]<br>        })<br>    return pd.DataFrame(transformed)<br><br>@task(name=&quot;Load Task&quot;, description=&quot;Persists data to disk.&quot;)<br>def load(data: pd.DataFrame, path: str) -&gt; None:<br>    data.to_csv(path_or_buf=path, index=False)<br><br>@flow(name=&quot;ETL Flow&quot;)<br>def etl_flow(p_url):<br>    users = extract(url=p_url)<br>    df_users = transform(users)<br>    load(data=df_users, path=f&#39;data/posts_{int(datetime.now().timestamp())}.csv&#39;)<br>    return flow<br><br>if __name__ == &#39;__main__&#39;:<br>    flow = etl_flow(p_url=&#39;https://jsonplaceholder.typicode.com/posts&#39;)</pre><p>Run the flow locally and check the output.</p><pre>python .\demo.py </pre><p>The pipeline is complete and we can see detailed information about each task’s states. Once complete, a CSV file gets created in data directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*yRAhfciLhMUzDPvGAP-6mg.jpeg" /><figcaption>Sample Flow Run</figcaption></figure><p><strong>Step 3: Flow Orchestration</strong></p><p>Orchestration of Flows helps in scheduling and deploying workflows. Prefect Orion API server and orchestration engine receives state information from workflows and provides flow run instructions for executing deployments. You can spin up an instance of Orion anytime using CLI</p><pre>prefect orion start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*mNJEiUaq_7tcEey55w7yqw.jpeg" /><figcaption>Prefect Orion Terminal</figcaption></figure><p>Hit the URL : <a href="http://127.0.0.1:4200/">http://127.0.0.1:4200/</a> (check the server output) to view the Prefect Dashboard listing the details of the flows and runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFTzAr6m-DV752hfmYH7Gg.jpeg" /></figure><p><strong>Scheduling the flow-runs through</strong> deployment build.</p><p>The deployment build will create a deployment definition etl_flow-deployment.yaml file. Path to the flow is specified in the format path-to-script:flow-function-name — The path and filename of the flow script file, a colon, then the name of the entrypoint flow function. If configured, it will upload the flow files to the configured storage location and will submit the deployment to the work queue demo(will create if it doesn’t exist).</p><pre>prefect deployment build demo.py:etl_flow -n demo-deployment -q demo --cron &quot;0 0 * * *&quot;<br>prefect deployment apply etl_flow-deployment.yaml</pre><p>The deployment file will look similar as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*itwZwhAI9O-iO5elb7lbgw.jpeg" /></figure><p>Once deployment apply is executed, an deployment entry and work queue is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WCprpS-E8DgLP5EBIj2gA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9j6JMDc281Xvog_tbxK8gQ.jpeg" /></figure><p>You can edit the deployment configuration by editing the deployment entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWah9fDhLuVSD769FexsOw.jpeg" /><figcaption>Prefect UI Deployment</figcaption></figure><p>To execute flow runs from this deployment, start an agent that pulls work from the demo work queue.</p><pre>prefect agent start -q demo</pre><p>To run the flows manually you can also trigger it from UI: Deployment &gt; Runs &gt; Run. Once triggered, the agent will execute the flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkpMW2Y2Q5M9fJ7nA62mtw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*O6aQlz5_09qC77E2YuttWg.jpeg" /><figcaption>Terminal Log of Agent</figcaption></figure><p><strong>NEXT: Running Flow with Prefect Cloud</strong></p><p>To get started with Prefect cloud:</p><ol><li><a href="https://app.prefect.cloud/">Sign In / Register</a> a Prefect cloud account and create a workspace.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joFkkC4UMq7AWk-73kL18g.jpeg" /><figcaption>Workspace UI</figcaption></figure><p>Create an API key for authorizing the execution environment. This can be an agent running locally on your machine or into the cloud environment. Login to your cloud account and set the workspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Ip2OFyZ6pozOHevxU-zzg.jpeg" /><figcaption>UI shows the created workspace</figcaption></figure><pre>prefect cloud login -k &lt;Key&gt;<br>prefect cloud workspace set --workspace &quot;&lt;accountname&gt;/demo&quot;</pre><p>Now all the flow run can be administered on the Prefect cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*3dkNH3VlbqTAU8zbajsohA.jpeg" /><figcaption><em>Execution of the flow locally</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0RRK2bzPGwRIdsIx3GIvA.jpeg" /><figcaption><em>Perfect Cloud Dashboard showing Flow Runs</em></figcaption></figure><p>Re-Build and Apply deployment configuration which will create an entry in Prefect Cloud Deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGMjWuW1e7BwwXuygW7llA.jpeg" /><figcaption>Deployment Page of UI</figcaption></figure><p>Run the agent locally to execute the workflow. You can also run your agents in the cloud to run your workflows orchestrated in Prefect Cloud.</p><p>Please refer to the <a href="https://docs.prefect.io/">official Documentation</a> for advanced topics and configurations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57f281a9b042" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Got a Whatsapp ? Was that He/She or ‘It’ ?]]></title>
            <link>https://medium.com/@anuragambuja/got-a-whatsapp-was-that-he-she-or-it-466ee933eb6f?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/466ee933eb6f</guid>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[whatsapp]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 10:51:50 GMT</pubDate>
            <atom:updated>2018-12-15T17:03:50.673Z</atom:updated>
            <content:encoded><![CDATA[<h3>Got a WhatsApp ? Was that He/She or ‘It’ ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Wr_MnguzF8ouiB1yyKnKrQ.jpeg" /></figure><p>No ! It’s not a regular write up to reveal the already known features of the WhatsApp. It’s purely technical, yet funny stuff dedicated to our “lazy” tech enthusiasts.</p><p>Okai ! Let me ask you something. Have your nightmare of not wishing your dear one’s due to your oblivious behavior turned into reality ? Or, Do you ever wished to integrate your business with WhatsApp ? If yes, then Go ahead. Here we will try to send a message to individual or group using python.</p><p><strong>Requisites:</strong><br>1. <strong>python 2.7</strong><br>2. <a href="https://chromedriver.storage.googleapis.com/index.html"><strong>Chrome Driver</strong></a>: Download compatible version of the driver and the chrome/chromium w.r.t. your OS<br>3. Connection to internet and WhatsApp installed phone</p><p>PS: Below snippets has only been run and tested on Windows 10 but should run smoothly on others too with some tweaks.<br>** If any module is not installed, use pip.</p><p>To learn more about chrome drivers → <a href="https://sites.google.com/a/chromium.org/chromedriver/">click me</a>.</p><p>Now everything is set, lets cook some code.</p><p><strong>Import the necessary modules</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab4db6061fb852701d1e3d02a0b778c5/href">https://medium.com/media/ab4db6061fb852701d1e3d02a0b778c5/href</a></iframe><p>Set up the message to be sent and the corresponding xpath. You may need to take help of chrome’s developer tool (in case below doesn’t work).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69d1eccc54f37cf80ea997fbdfe5722b/href">https://medium.com/media/69d1eccc54f37cf80ea997fbdfe5722b/href</a></iframe><p>Integrate the codes and run. <br>* Change paths accordingly, just reminded. :D</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/004ce0cd6d6494476b6b156fab4f631f/href">https://medium.com/media/004ce0cd6d6494476b6b156fab4f631f/href</a></iframe><p>Once you have run the above code, a new instance of the browser will be forked. Below is the page alike that you will see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*iYOlY8Iz-1MMPnXYh6pdvw.png" /></figure><p>On the mobile app, click the “WhatsApp Web” from the right corner three dots under “chats” tab as shown below and scan the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*UH3eq6vYr2_ERmw63v-Ckg.jpeg" /></figure><p>Ta Ta-ra-a-an !! You are done.</p><p>PS: I don’t take any responsibility if your friend blocks you, or you are evicted from any group, or even WhatsApp blocks you. ;)</p><p><em>Let’s make this world a better place for the eggs yet to be hatched.<br>Clap if you liked.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=466ee933eb6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Your NodeMCU ESP8266]]></title>
            <link>https://medium.com/@anuragambuja/test-your-nodemcu-esp8266-8c92999035a2?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c92999035a2</guid>
            <category><![CDATA[nodemcu]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Fri, 23 Nov 2018 18:09:58 GMT</pubDate>
            <atom:updated>2018-11-24T08:13:27.633Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cook your first IoT Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjP4WGfP8FUg0Vc70i-I9Q.jpeg" /></figure><p>I started it out of my interest for IoT and thought of sharing it to the bigger community. It’s a simple blog to setup, deploy and test sample code on your MCU.</p><p>Let me know if it was helpful to you in any way.</p><p>* All the steps listed below are performed in Windows 10 and on Nodemcu esp8266</p><p><strong>Setup your Arduino IDE:<br></strong>1. <strong>Download and install the </strong><a href="https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers"><strong>driver</strong></a><strong> to port codes to MCU</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*JVe9qvEi7e6hBYyo-DKDig.png" /></figure><p><strong>Verify the driver installation:</strong> Connect the <a href="https://www.amazon.in/dp/B010O1G1ES/ref=cm_sw_r_cp_ep_dp_SKb-Bb38P6PQ2">device </a>(nodemcu) and navigate to <strong>Device Manger &gt; Ports</strong>. You will see the connected device listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*uMewO0KbTW4pOQXO6tK4aA.png" /></figure><p><strong>2</strong>.<strong> Download and install the </strong><a href="https://www.arduino.cc/en/Main/Software"><strong>IDE</strong></a><br>Go to<strong> File &gt; Preferences</strong> and type below URL into “Manger URL” text box as shown below. Install the package for esp8266. Restart the IDE.</p><p><strong>URL</strong>: <a href="http://arduino.esp8266.com/stable/package_esp8266com_index.json">http://arduino.esp8266.com/stable/package_esp8266com_index.json</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*5Yva7p7mG2ahvJ-4E4o1Bw.png" /></figure><p>Navigate to <strong>Tools &gt; Board</strong>. Select ESP8266 (shown below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*6QxoW192KdtofV2BNyys-Q.png" /></figure><p><strong>Test your NodeMCU</strong>:<br>The below sample code snippet makes ESP8266 to blink at regular interval.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd3a73903430a65f2fe6804aa9b823f0/href">https://medium.com/media/fd3a73903430a65f2fe6804aa9b823f0/href</a></iframe><p>Push the code to MCU:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*uCmCPAeeSLwWGw84iWlJhg.png" /></figure><p>Once Compiled, the LED will start blinking. Done.</p><p><em>Let’s make this world a better place for the eggs yet to be hatched.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c92999035a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exceptions in Life, So in code.]]></title>
            <link>https://medium.com/@anuragambuja/exceptions-of-life-826496b6bfa8?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/826496b6bfa8</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[exception]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 17:32:23 GMT</pubDate>
            <atom:updated>2018-12-15T17:07:14.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*ThqQ4BSoWTDU2rWVO5CbPg.png" /></figure><p>Life would have been too easy if everything would have got in place as per your plan. Alas ! There are unexpected impediments on the way and those who don’t plan for it are bound to ‘exit’ before the end. Programming and life does imitate each other.</p><p>‘Exceptions’ are ‘RUN TIME ERRORS’ or ‘EXECUTION TIME ERRORS’. When we feel there is a part of code which may not work as expected if conditions are not met, we handle those situations in exceptions.</p><p>If a function doesn’t handle it, the exception is passed to the calling function, then that function’s calling function, and so on “up the stack.” If the exception is never handled, your program will crash. Python will print a “traceback” to standard error, and that’s the end of that.</p><p>Below are couple of examples when you don’t handle the exceptions and the program exits. No code is executed from the point an error is raised.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/561f7e3749b85fc7d664702c8266cf76/href">https://medium.com/media/561f7e3749b85fc7d664702c8266cf76/href</a></iframe><p>But, what if you have to continue execution even if there is an exception just like life doesn’t end if something goes wrong.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3f57fe1f39023b8ff97eca3b4896ea9/href">https://medium.com/media/e3f57fe1f39023b8ff97eca3b4896ea9/href</a></iframe><p>There are few built in exceptions which can be raised directly without defining when they need to catch the exceptions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/012f94b29e139491c8d6a71ba57f3930/href">https://medium.com/media/012f94b29e139491c8d6a71ba57f3930/href</a></iframe><p><strong>Common Built-in-Exceptions:</strong></p><blockquote><strong>StopIteration:</strong> Raised when the next() method of an iterator does not point to any object.<br><strong>SystemExit</strong>: Raised by the sys.exit() function.<br><strong>ArithmeticError</strong>: Base class for all errors that occur for numeric calculation.<br><strong>OverflowError</strong>: Raised when a calculation exceeds maximum limit for a numeric type.<br><strong>FloatingPointError</strong>: Raised when a floating point calculation fails.<br><strong>ZeroDivisonError</strong>: Raised when division or modulo by zero takes place for all numeric types.<br><strong>AttributeError</strong>: Raised in case of failure of attribute reference or assignment.<br><strong>EOFError</strong>: Raised when there is no input from the input() function and the end of file is reached.<br><strong>ImportError</strong>: Raised when an import statement fails.<br><strong>KeyboardInterrupt</strong>: Raised when the user interrupts program execution, usually by pressing Ctrl+c.<br><strong>IndexError</strong>: Raised when an index is not found in a sequence.<br><strong>KeyError</strong>: Raised when the specified key is not found in the dictionary.<br><strong>NameError</strong>: Raised when an identifier is not found in the local or global namespace.<br><strong>UnboundLocalError</strong>: Raised when trying to access a local variable in a function or method but no value has been assigned to it.<br><strong>ValueError</strong>: Raised when the built-in function for a data type has the valid type of arguments, but the arguments have invalid values specified.<br><strong>FileNotFoundError</strong>: Raised when a file or directory is requested but doesn’t exist.<br><strong>TypeError</strong>: Raised when an operation or function is applied to an object of inappropriate type.</blockquote><p>But, what if you don’t know the type of exception that will be thrown. Just write an except block for all the unknown error and it’s done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/643e573e3ab18e57272501c812713572/href">https://medium.com/media/643e573e3ab18e57272501c812713572/href</a></iframe><p>But, what if we want to catch undefined errors specifically and don’t want to club all the undefined exceptions into one. User defined exceptions comes to rescue. Exceptions need to be derived from the <strong>Exception </strong>class, either directly or indirectly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76c64e26c679bf537d687ab239939b13/href">https://medium.com/media/76c64e26c679bf537d687ab239939b13/href</a></iframe><p><strong><em>If something goes unplanned, make sure you catch it.</em></strong></p><p>Reference: <a href="https://docs.python.org/3/library/exceptions.html">https://docs.python.org/3/library/exceptions.html</a></p><p><em>Let’s make this world a better place for the eggs yet to be hatched.<br></em> <em>Clap if you liked.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=826496b6bfa8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can we pickle it ?]]></title>
            <link>https://medium.com/@anuragambuja/can-we-pickle-it-ab88243a5111?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab88243a5111</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pickling]]></category>
            <category><![CDATA[pickles]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Wed, 18 Jul 2018 11:50:31 GMT</pubDate>
            <atom:updated>2018-12-15T17:10:09.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*6-JsM6F1nyjAmW-wegk4Jg.jpeg" /></figure><p>No. No. No. The image has no relevance with the text below. I am not talking about granny’s method to make pickle out of anything under the sun. So, non programmers, my apologies, you can go ahead and click the red-cross-box on the right upper corner. Adieu.</p><p>Serialization (or, pickling) is the act of converting a class’s object into a byte stream. The process is also referred to as deflating, flattening or marshalling. The opposite operation, i.e. extracting a data structure from a series of bytes, is deserialization (also called inflating or unmarshalling or unpickling).</p><p>Okai ! That’s cool. But, why we need serialization ?</p><p>Whenever we need persistence i.e. want to save the state of an object between user sessions (or, even users), or pass it over the network, share it with other processes, serialization comes to rescue.</p><p>In python, inbuilt “pickle” class supports serialization.</p><p>Great ! But, How can I do it ?</p><p><strong><em>pickle.dump()</em></strong> function in the pickle module takes a serializable* python data structure, serializes it into a binary, Python-specific format using the latest version of the pickle protocol, and saves it to an opened file.<br>*Not every Python data structure can be serialized by the pickle module.</p><p><strong><em>pickle.load()</em></strong> function takes the serialized data stream and returns the restructured data structure.</p><p>Let’s pickle now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e0b7634fef151be4021b91f28c7480d/href">https://medium.com/media/6e0b7634fef151be4021b91f28c7480d/href</a></iframe><p><strong><em>pickle.dumps()</em></strong><em> </em>function instead of taking a stream object and writing the serialized data to a file on disk, it simply returns the serialized data.</p><p><strong><em>pickle.loads()</em></strong> function instead of taking a stream object and reading the serialized data from a file, it takes a bytes object containing serialized data, such as the one returned by the pickle.dumps() function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb2bf5017aaa17e12cb05ce724ff66a0/href">https://medium.com/media/fb2bf5017aaa17e12cb05ce724ff66a0/href</a></iframe><p>When the Pickler encounters an unpicklable object, it raises a PicklingError. This class inherits from PickleError. Best way to avoid an error is to know, what we can pickle and unpickle.</p><ol><li>All python supported datatypes : numbers, bools, strings, bytes, streams, numbers, tuples, sets, lists, dictionary.</li><li>Built-in functions, user defined functions (using def, not lambda) and classes defined at module’s top level</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bd74767ad8e58c37a52af259acdd13e/href">https://medium.com/media/8bd74767ad8e58c37a52af259acdd13e/href</a></iframe><p>Happy Pickling !!</p><p><em>Let’s make this world a better place for the eggs yet to be hatched.<br></em> <em>Clap if you liked.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab88243a5111" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Red]]></title>
            <link>https://medium.com/@anuragambuja/red-dfc41cd21b37?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfc41cd21b37</guid>
            <category><![CDATA[art]]></category>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[literatura]]></category>
            <category><![CDATA[random-tiny-tales]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Tue, 17 Jul 2018 04:13:00 GMT</pubDate>
            <atom:updated>2018-12-15T17:10:53.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>r/red</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y84WUjg0dOnfItIqpGkPoQ.jpeg" /></figure><p>Roses are red,<br>Red is the blood that it’s thorns give you.</p><p>Red is the sky when its dawn,<br>When its dusk, its still red.</p><p>Red signals danger,<br>Red denotes life too.</p><p>Anger turns you red, <br>Red are you, when you blush.</p><p>Red is the color of passion, <br>It’s the same red when you denote prohibition.</p><p>Red is your hand when you are being married, <br>Red is your hand when you end a life.</p><p>Red are the stains on the sheet when you are born,<br>Red is it when you end yourself.</p><p><em>Let’s make this world a better place for the eggs yet to be hatched.<br>Clap if you liked.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfc41cd21b37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Truths and Dares of Life]]></title>
            <link>https://medium.com/@anuragambuja/truths-and-dares-of-life-3f0701a2dd2f?source=rss-4221b3ff2d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f0701a2dd2f</guid>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[truth]]></category>
            <category><![CDATA[stories]]></category>
            <category><![CDATA[truth-and-life]]></category>
            <dc:creator><![CDATA[Anurag Ambuja]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 17:49:26 GMT</pubDate>
            <atom:updated>2018-12-15T17:11:14.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*cQcpPp4smOc_1cKEmR1oww.png" /></figure><p>You may call these notions as ‘Facts of Life’ or may call them just ‘Life’. We sabotage the reality by sugarcoating the facts and try to live in an illusion created by ourselves. But, the truth is, life is quite gross and will always be the same. Quite brutal.</p><p>My notions/opinions may look quite absurd and contradictory on the plane. But, once you start digging deep in your life, you will encounter it’s grains of wisdom. Lets dare to face the truths from my perspective in the most crude way. Hope, I am able to do justice with them.</p><ol><li><strong>No One Cares.</strong> Pained ? Depressed ? Broken or Broke ? Guess What ! No one cares. Why should anyone ? Everyone has already lived the pain sometime, somewhere in his/her life in some or the other form. Pain is meant to be felt. Get used to it. Free yourself from the shackels of expectations.</li><li><strong>Out of Sight is Out of Mind. </strong>“We will be together forever”, “You are in my thoughts wherever I go”, “Our friendship will always be the same” bla bla — I wish I could say they hold true irrespective of timelines. But, Alas ! Life shows too many shades, bright and dull in such a short split of time, that promises remain the same, just the promisee changes. Its not anyone’s fault. Its just the priorities of life are much defined by the proximity of space, time and relationship. Don’t complain.</li><li><strong>Learn to say ‘NO’</strong>. Don’t mistake me to have negative approach to everything that comes in your life. But, do say ‘NO’ to all the things for which you are convinced is not a good idea to follow currently. Don’t get swayed away by emotions. If you are important to them, they will empathize. If they don’t, ‘NO’ was the best you can bestow.</li><li><strong>No Escape from Karma. </strong>There is no such thing as ‘Let Bygones be Bygones’. If your past was turbulent, make peace with it. Don’t run. Don’t hide. Face it. Your past will keep revisiting you in your present. Best way to escape your past is make your present worth memorable. Remember, nothing f**ks harder than time, and past was the time which was once your present.</li><li><strong>Don’t be Credulous. </strong>Don’t mistake me in being cynical of everything.<strong> </strong>Just don’t reveal your secrets to everyone who empathize with your emotions. Be selective. You never know when a friend may empathize with your foe. Remember ! You won’t be shown mercy for your naivety.</li><li><strong>Stop being imprisoned to the notion of Perfection. </strong>Perfection is an illusion. You won’t be ever able to achieve it. There is a reason to it. Everyone has his/her version of being perfect. So, Stop trying being perfect. Just try being a better individual every passing day.</li><li><strong>Pleasing Everyone is sure shot mantra for despondency. </strong>Just don’t try. Rather please yourself. There is nothing wrong in it until you become sadist. Loving yourself eliminate the chances of being ignored for your efforts.</li><li><strong>Money don’t buy happiness.</strong> Rather than earning pennies, earn memories, a good one. When you will look back 10 years hence, you will have reason to smile. No matter whatever be your pace, money will always be faster. Remember ! When you are at the deathbed, those nights and holidays spent in office, away from your family, will be for nothing.</li><li><strong>Practice Gratitude. </strong>Don’t end your day without a Thanks for the abundance you have been bestowed with. Find a reason to thank, even if it is just for a beautiful smile which she/he gave you.</li><li><strong>You have been bluffed with the notion of Eternal Happiness. </strong>You wont find it. Stop searching for it. Happiness is quite relative. The joy of riding a bike may not be the same five years hence. The perfect time to be happy is — Now. Be happy, spread happiness.</li><li><strong>Don’t mistake crush for love. </strong>You may screw your life. There is no litmus test to distinguish between them. You can only know when time has elapsed. If the collywobbles dies with time, it was crush. Just give yourself — Time.</li><li><strong>Don’t try to copy someone else’s life.</strong> You owe a different set of shoes. Neither you have walked down his path. So, be original version of you. You are unique in this whole cosmos. Create your version of life. Live life from yours perspective.</li><li><strong>Be revengeful but only in dreams. </strong>It’s wicked.<strong> </strong>It’s sadist. Hate for hate will leave the whole world hateful — without love.Vengeance is fed by ego and ego only gives temporary joy and permanent misery.</li><li><strong>Just Love is not Enough.</strong> Why it should be ? Did it solve your financial problem or your relationship problems ? Were you spared of your debts since you were in love ? NO. Love does not guarantee compatibility, neither empathy nor ‘eternal’ commitment.</li><li><strong>Looks matters (but not always and isn’t everything). </strong>It’s often said — First impression is last impression (BTW, I don’t agree). And, looks does the same. It paves the path to break the ice. You may call it ‘Appearance’ or whatever, and I know it’s quite superficial, but it does matter. Bullshit is the theory that — ‘Beauty is in eyes of beholder’. Yeah, there will be differences on the degree of beauty but everyone will agree with the beauty of Marilyn Monroe ! Right ?</li><li><strong>Dream. And Work for it. </strong>Dreaming is important but don’t ‘just’ dream. Don’t wait for a Genie to give wings to your dreams. Dream to build the castle but be ready to put the effort to lay down its foundation.</li><li><strong>Spend time with yourself for yourself. </strong>By ‘Yourself’ — I mean your priorities.<strong> </strong>In noway I am suggesting to not shoulder your responsibilities, but decide the priorities of your life and work accordingly. No matter how hard you try, there will always be work to be completed. It will be easier to decide when you answer, ‘Why you exist and for whom ?’ .</li><li><strong>People are like seasons. </strong>Some may last long and some may vanish in the blink of an eye. Those who are short lived will come with a purpose. They are God sent. They will just clean the mess in your life and on some fine day, without any reason will tiptoe away from your life. You won’t be able to hold them in your life. Then, there will be some who will stay with you no matter what the circumstances are. They are your life lines. Take care of them. And, then there will be some who will be just like seasons. They will keep visiting you. You just need to be cautious about them. Some may come with good omen and some may jinx.</li><li><strong>You cannot pee when you sneeze. :D</strong></li><li><strong>Don’t take life too seriously.</strong> No one has escaped. Everything comes with an expiry date. A waiter panics if he spills the coffee on customer’s shirt. But do you really think will it matter five years down the line ? If , howsoever he remembers, he can only smile on that silliness. Just, apologize and move on. Remember, Everything you like will cease to exist. Everyone you love will die eventually before or after you. Help them live. Help them to pursue their definition of ‘happiness’. Help them create a better version of themselves.</li><li><strong>Final slumber is inevitable. </strong>Death is only truth . Accept it. It is coming and it won’t stop. It won’t wait — No matter how many dreams are yet to be ticked. No matter how many confessions you still want to convey. Live before you die. Live today ! Not in yesterday , not in tomorrow. You don’t know when you will meet your last breathe. Better stop waiting.</li></ol><p>That’s<strong> LIFE — “ Living as IF you are on Edge” or “Live beFore it Ends”</strong>. Everything will work out eventually. Just keep going. Chill. Best Wishes. Peace.</p><p><em>Let’s make this world a better place for the eggs yet to be hatched.<br>Clap if you liked.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f0701a2dd2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>