<?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 Yash Shah on Medium]]></title>
        <description><![CDATA[Stories by Yash Shah on Medium]]></description>
        <link>https://medium.com/@shahyash?source=rss-8e98875dca4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FRTDo1nQKJvLyDWlPVA8AQ.png</url>
            <title>Stories by Yash Shah on Medium</title>
            <link>https://medium.com/@shahyash?source=rss-8e98875dca4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:52:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shahyash/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[Loading NYC 311 Open data in SQL]]></title>
            <link>https://medium.com/@shahyash/loading-nyc-311-open-data-in-sql-ff5e66320cdf?source=rss-8e98875dca4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff5e66320cdf</guid>
            <category><![CDATA[nyc-open-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Yash Shah]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 14:08:46 GMT</pubDate>
            <atom:updated>2019-09-18T16:04:56.553Z</atom:updated>
            <content:encoded><![CDATA[<h3>Downloading 311 data from the NYC Open Data Portal</h3><p>311 dataset is so massive ( 12GB at time of writing), and in my experience Socrata’s servers weren’t that fast. I was getting about 6Mbps download speed which is not that bad. You can see the data from <a href="https://nycopendata.socrata.com/Social-Services/311-Service-Requests-from-2010-to-Present/erm2-nwe9/data">here</a> and then Download CSV from the right block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9w_eyL-6WFGutv0RCmRU8Q.png" /></figure><h3>Importing 311 Data into PostgreSQL</h3><p>This has been most difficult step as I had to struggle a lot in getting the data into SQL database. I was particularly trying with Postgres using the tool Postico ( Mac app for Postgres ). In most of the tools, I was getting error integer out of index which means the automatic data import was not working correctly. After lot of trials, I was able to get it working correctly following the steps mentioned below:</p><p>If you are using any Postgres GUI tool then you can simply run the following query inside the database. For CLI, you will have to run sql -d name_of_your_database and then run the query.</p><pre>CREATE TABLE nyc_data(</pre><pre>Unique_Key                     BIGINT   PRIMARY KEY</pre><pre>,Created_Date                   DATE</pre><pre>,Closed_Date                    DATE</pre><pre>,Agency                         TEXT</pre><pre>,Agency_Name                    TEXT</pre><pre>,Complaint_Type                 TEXT</pre><pre>,Descriptor                     TEXT</pre><pre>,Location_Type                  TEXT</pre><pre>,Incident_Zip                   TEXT</pre><pre>,Incident_Address               TEXT</pre><pre>,Street_Name                    TEXT</pre><pre>,Cross_Street_1                 TEXT</pre><pre>,Cross_Street_2                 TEXT</pre><pre>,Intersection_Street_1          TEXT</pre><pre>,Intersection_Street_2          TEXT</pre><pre>,Address_Type                   TEXT</pre><pre>,City                           TEXT</pre><pre>,Landmark                       TEXT</pre><pre>,Facility_Type                  TEXT</pre><pre>,Status                         TEXT</pre><pre>,Due_Date                       DATE</pre><pre>,Resolution_Description         TEXT</pre><pre>,Resolution_Action_Updated_Date DATE</pre><pre>,Community_Board                TEXT</pre><pre>,BBL                            NUMERIC</pre><pre>,Borough                        TEXT</pre><pre>,X_Coordinate_State_Plane       BIGINT</pre><pre>,Y_Coordinate_State_Plane       BIGINT</pre><pre>,Open_Data_Channel_Type         TEXT</pre><pre>,Park_Facility_Name             TEXT</pre><pre>,Park_Borough                   TEXT</pre><pre>,Vehicle_Type                   TEXT</pre><pre>,Taxi_Company_Borough           TEXT</pre><pre>,Taxi_Pick_Up_Location          TEXT</pre><pre>,Bridge_Highway_Name            TEXT</pre><pre>,Bridge_Highway_Direction       TEXT</pre><pre>,Road_Ramp                      TEXT</pre><pre>,Bridge_Highway_Segment         TEXT</pre><pre>,Latitude                       NUMERIC</pre><pre>,Longitude                      NUMERIC</pre><pre>,Location                       TEXT</pre><pre>);</pre><p>Then you can go to your editor and click import CSV, it will match the field types there and you should be able to import.</p><h3>Importing 12GB of Data into Postgresql</h3><p>I tried importing using the Postico client on Mac, and it literally will take about 2hours to import on my 16GB RAM with i7 processor Macbook Pro as it processes row by row.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLbrxQdah2a15tUGtUOSjw.png" /></figure><p>As next step, I tried with PostgresCOPY command and it turned out I was able to get the data into the database in about 5 minutes. YESS 5 MINUTES! I went into the psql shell by psql -d name_of_your_database and then ran the following command:</p><pre>COPY nyc_data FROM &#39;/Downloads/name_of_your_file.csv&#39; DELIMITERS &#39;,&#39; CSV  HEADER;</pre><p>I have not tried myself but you can also look into <a href="https://github.com/dimitri/pgloader">PGloader</a> which is great data importing tool for Postgres.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff5e66320cdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you want to travel around the world? Read this first.]]></title>
            <link>https://medium.com/@shahyash/do-you-want-to-travel-around-the-world-read-this-first-4d71f7542f02?source=rss-8e98875dca4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d71f7542f02</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[backpacking]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[digital-nomads]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Yash Shah]]></dc:creator>
            <pubDate>Mon, 18 Jun 2018 07:34:59 GMT</pubDate>
            <atom:updated>2018-06-25T21:25:52.174Z</atom:updated>
            <content:encoded><![CDATA[<p>How many times did you not do something because you were afraid to do it alone? Some time ago, I was dreaming of traveling the world. But you know, friends seldom have money, time, and motivation all at once. What they do have in abundance though is excuses. But would I go alone? No way, it’s scary!</p><p>Finally after four drinks, one evening, without much thinking, I just bought my first flight ticket to Spain. For the next day, I was asking myself: “What the hell did I do?!”. But I went for the trip anyway. Just me, my backpack, and my shaking body. It appeared to be one of the best decisions I have ever made. Next year I did the same thing and same thing year after. And only this year I took 21 flights myself. This time I visited 7 countries while able to continuously deposit money in my savings account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyOoIJAWgxudj2DV9hy5Jg.png" /><figcaption>Backpacking in Bali</figcaption></figure><p><strong>So how did I make it happen?</strong></p><p>When I meet people and tell them about what I do or how long I have been traveling, their response is usually something like, <em>“Wow! That is so awesome! You’re so lucky! I wish I could do something like that!”</em> To most people, my job is the best job in the world.</p><p>The chances are that “How will I survive on the road?” have indeed crossed your mind (they pass through all of our minds at some point!) and there’s also a chance that you haven’t found any answers. As a result, you’ve still yet to take that first step and start traveling, and as time passes by, you begin to wonder if you’ll ever achieve your travel goals. I’ve been there and changing my lifestyle changed everything, everything that is now aligned with my travel goals.</p><blockquote>When I was planning my first trip ever, I remember filling the excel sheets budgeting for these 7 countries. My dad called me and said, Travel while you’re young and able. Don’t worry about the money, just make it work. Experience and network you will build through this journey are far more valuable than money will ever be. Create a Vision and live a life that makes you want to jump out of bed every morning!</blockquote><p>I’ve been working remotely with teams for about 2 years now, but this time I wanted to take it a step further to fulfil my dream of traveling the whole world. I tried Work and Travel — Yes, being a digital nomad. That’s the lifestyle I’m talking about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Jf6wdlplbg90kM3Yrsi3w.png" /><figcaption>Sometimes all you need is wifi and sand between your toes….</figcaption></figure><p>Just imagine, how much more pleasant would our vacations be if travel was a routine and not something precious that we micromanage the happiness out of? What if holidays could be something ample and not limited… simply by changing the way we think about it? What if we put fewer expectations on our trips and just enjoyed the experiences that fit while working on an innovative product as a digital nomad?</p><p>Without a guiding principle, we chase whatever we see — Imagine us on the expressway. There is a car ahead of us, and It doesn’t matter how quick it’s going. We just want to overtake it. Once we overtake, we relax, enjoy the lovely music and — soon enough — there’s another car, it’s overtaking us again!</p><p>This is how several people travel, too. It leads to an expensive vacation that leaves us exhausted, then bored, then dissatisfied once we’re home. But you know what doesn’t? <strong>Cruise control.</strong></p><p>When we set our car on cruise control, it doesn’t care how fast everyone around us is going or if people are playing <a href="https://en.wikipedia.org/wiki/Antakshari">Antakshari</a> in the back seat. It does what it’s programmed to do. And, as a result, we get to our destination at the same time as everyone else, while saving our energy along the way. The energy saved can be used to work on a kickass product and keep our survival money flowing.</p><p>I was earning every day while I was traveling and while still able to save a part of it in the bank. Many companies are now offering <a href="https://weworkremotely.com/">remote work </a>because they know the<a href="https://jell.com/blog/10-stats-that-will-change-the-way-you-think-about-remote-work/"> productivity increases by 20% </a>when we’re not kept inside 4 walls. Go and join them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HUXc6Yh7kW8U_QmIy1i6KA.png" /><figcaption>30 Mbps Internet, Palm trees, ocean breeze, salty air, sun-kissed hair, that clear blue water, I’m there!</figcaption></figure><h3>Can everyone work and travel?</h3><p>I love this question because it refines in on an undeniable truth: not every good worker is a good <em>remote</em> worker (yet). The decision to work remotely is a completely different lifestyle. Work and Travel is one step even further.</p><p>One can definitely work and travel but it requires us to gain some experience working remotely before we start mixing travel and work. People think it’s hip, cool and lots of fun being always on the road and have a location independent lifestyle but they do not realize that succeeding as a Digital Nomad requires lots of hard work, will power and focus.</p><blockquote>Remind yourself that you don’t have to do that everyone else is doing</blockquote><p>Working remotely successfully is a skill, just like programming, designing or writing. It takes time and commitment to develop that skill. We are habituated to work within a team and in particular environment of the office. Going from that environment to working remotely full time is not easy. Self-discipline becomes super important. We have to learn a whole new set of skills that ‘normal’ office workers don’t always need to have. We have more responsibility, it feels much more like running our own little company.</p><p>Being digital nomad, there are no weekends and every day is a vacation. Very often a weekend goes by where I don’t touch my laptop. I tend to think of weekend work as finishing up something that I wanted to get done during the week, fixing something urgent or just fun work that I haven’t gotten a chance to do.</p><blockquote>The sad truth is no one ever built an empire by just working from 9 am to 5 pm Monday to Friday.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TdQc26pG1SNhXm9SBzAj2A.png" /><figcaption>A digital nomad I will be for life, in love with distant and uncharted places. I love working from cafes like this where you have your headphones on while sipping on coffee with this spectacular bay view.</figcaption></figure><p><strong>Life as a Digital Nomad vs Vacationing</strong></p><p>From the outside it must look like I’m just traveling constantly, having a blast (and I am), but of course, there’s a lot more to it than that and then the question comes — Don’t you ever get tired of traveling?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldHJlV1CacOlZC5T2dwXLA.png" /><figcaption>An evening after the work hours!</figcaption></figure><p>Yes, you get tired. Really tired. Of traveling. Of everything. After a while, everything becomes just another “one of.” That 84th church, 127th flight, 245th hostel, 678th bus ride, 872nd bar… it’s not the same after a while. It loses its charm and glory. Travel becomes unexciting. Ask any traveler — at some point, they hit that point where they are sick of traveling. After becoming a digital nomad, I have not even felt exhausted once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xdw3V4nmX9TdN4mKHMI5w.png" /><figcaption>With this view from your work desk and critical bugs to solve, how can I ever get bored?</figcaption></figure><p>I’m in no hurry now. I move a lot slower than I used to. I’ve no fear of losing out on money while I’m traveling. If I want to spend a full day out sightseeing, I can, but I tend to be out for a few hours and working out of a cozy cafe rest of the time. After all, I’ll be wherever I am for a while. Work and travel is definitely better travel lifestyle, and it fights the “just another” syndrome.</p><blockquote>Traveling is a beautiful way of showing us what really matters</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w9_y7pt9pPZ5bhPDH2Vz4w.png" /><figcaption>Catching the sunset from my work desk in Thailand!</figcaption></figure><p>I save time too! We have to spend a lot of time getting ready for work. For many people, this means dressing up in a suit and/or putting on makeup — tasks you can skip if you’re a digital nomad.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLx8TP4kwhWlIGupryc2aQ.png" /></figure><p>So when I decided to take the leap, to free myself from the shackles of an office and commuting and to give working as digital nomad the chance it fully deserves, I knew that it had to be with just the right company.</p><p>These are some of the things I can do because I’m fortunate to work for <a href="http://www.stasislabs.com/">a company</a> that lets me work from anywhere:</p><ul><li>Learn a new sentence in a different language every day and make somebody smile when you say it to the local.</li><li>Hug my parents and eat together all the meals for a month. <a href="https://medium.com/@shahyash/do-you-travel-often-you-should-try-this-86f72e2fc4d9">Read more on how.</a></li><li>Date somebody from an entirely different culture.</li><li>Make friends from 30+ countries.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TQErEEy7dVMRl4PUY4R8UQ.png" /><figcaption>Sometimes the most excellent adventure is merely a conversation.</figcaption></figure><ul><li>Work with a total stranger for the whole day.</li><li>Care for a sick child without taking a sick day myself.</li><li>Swim at 10+ untouched beaches or sometimes in the middle of nowhere.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jHQLpZlYxvTGqGl4D7NdUw.png" /><figcaption>Cat ba island is one of my favorite places. They have full day party boats — there is great music, unlimited booze and you can even jump off the boat</figcaption></figure><ul><li>Fly almost every week</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxmnKq3ipNKvzwV6g0nyYA.png" /><figcaption>Landing at the Bali airport on the New years eve</figcaption></figure><ul><li>Work from a different coffee shop every day.</li><li>Spend a week on an isolated island.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIkLsh6a03_Rcuyh3LEi7Q.png" /><figcaption>My work desk by the beach under the perfect shadow</figcaption></figure><p><strong>Isn’t it scary to travel all alone with your gadgets?</strong></p><p>Yes, it definitely is! I got robbed in Bali, needed to escape from a house in the middle of nowhere in Vietnam, and almost drowned in the ocean. But I also experienced big generosity from people who opened their house for me to live with their family. I worked out of best cafes in the world, camped in the haunted island, was about to miss my flight because Vietnam is so wonderful, got several really good job offers and was living in a beautiful bamboo house in an Asian island. You will face a lot of difficulties while traveling alone but it will make you stronger. You will have life-changing experiences from which you will learn and grow.</p><blockquote>I’d rather look back at my life and say I can’t believe I did that instead of saying I wish I had done that</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlNyYZfs5eoncKEAqMhJqg.png" /><figcaption>Yoga day in Gili island near Bali</figcaption></figure><p><strong>They Say live like a local..</strong></p><p>To understand the local culture and people, we have to integrate. Integrating with local people and their culture is what brings the real value while traveling and makes the world a better place. I like to understand their needs, learn from other people, and share your knowledge with them. Give something back!</p><p>Being digital nomad, when you’re working out of a cafe or co-working spaces — they are full of expats and you hardly get to network with the locals. So how you get into the local scene? How do you meet locals?</p><p>I frequently visit universities or local technical community events, where I connect with hundreds of locals. I love to talk about my experience as an entrepreneur and I also often take hands-on sessions on open source technologies.</p><blockquote>You could do various things to get connected: What always works is a smile!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TF6U2A-eZbdGZxNF74Dhw.png" /><figcaption>With locals, you get to explore what tourists can’t find on trip advisor!</figcaption></figure><h3><strong>I would just say…</strong></h3><blockquote>Do what you have to as quick as you can so you can do what you want as long as you can!</blockquote><p>Travel the world as a digital nomad. Surf a new beach every morning. Work out of different cafe every day. Hike on a different hill to see the beautiful sunset every evening. Eat a varied local cuisine each night.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ImvNhR2-de50gDFM3JLGRw.png" /><figcaption>This is my Gym! Hiking is how I lose my calories.</figcaption></figure><p>Or just stay home all day in your pajamas.</p><p>It doesn’t really matter. You can get your work done either way. The choice is yours.</p><blockquote>Happiness is a choice. Your choice.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8tnG_ddXTMDyqbUvHG09yg.png" /><figcaption>I’m in heaven. It was all beyond worth it. Pictures don’t do enough justice. We could buy so many things in life but it’s experiences like this that I truly wish I could experience over and over again — I’d have to live here for it. Leave town, go far away, and go see things you’ll NEVER be able to buy off <a href="http://amazon.com/">amazon.com.</a></figcaption></figure><p>Thank you for reading this far, Hope you’re inspired to take a step ahead towards being a Digital nomad. If you have any questions, please comment below and I will try my best to reply.</p><p>If you’ve enjoyed this article, hit the clap button and follow me to get the next articles in this series.</p><blockquote><a href="https://medium.com/@shahyash/do-you-travel-often-you-should-try-this-86f72e2fc4d9">Do you travel often? Try this.</a></blockquote><p><em>I’m incredibly grateful to get an opportunity to travel and work with </em><a href="https://stasislabs.com/"><em>Stasis</em></a><em> where we are a</em>ccelerating Indian Healthcare towards Proactive Patient Care. <a href="https://angel.co/stasis-labs"><em>We’re Hiring</em></a></p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more stories featured by the <a href="https://usejournal.com/?/utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d71f7542f02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you travel often? Try this!]]></title>
            <link>https://medium.com/@shahyash/do-you-travel-often-try-this-86f72e2fc4d9?source=rss-8e98875dca4------2</link>
            <guid isPermaLink="false">https://medium.com/p/86f72e2fc4d9</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[parents]]></category>
            <category><![CDATA[digital-nomads]]></category>
            <category><![CDATA[tecnology]]></category>
            <dc:creator><![CDATA[Yash Shah]]></dc:creator>
            <pubDate>Mon, 18 Jun 2018 07:34:29 GMT</pubDate>
            <atom:updated>2018-06-18T07:34:29.254Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*E2NwddbL4qqoS2MMtodObA.png" /></figure><p>When I saw low-cost tickets from India to Vietnam, I immediately thought about my parents. It was their big dream to go there. I called my dad, and within 5 minutes we bought the tickets.</p><p>Not much thinking, not much planning. That too for one month long trip.</p><p>I must admit I didn’t know what to expect. I have never traveled so far and for so long with my parents (Yes, one month straight). I only knew it was going to be much different from traveling solo or with a good friend.</p><p>I knew that we could not stay in a low-budget dormitory room and I should book something cozy and quiet just for all of us. And instead of walking everywhere, I knew we would need to take a taxi sometimes. Also, there would be much less room for spontaneity because everything should be organised correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wS7kgDP0sOAcj8ckW2NIqQ.png" /><figcaption>View from my work desk in the Airbnb at the 43rd floor</figcaption></figure><p>In fact, it was much more fun with my parents than any other countries I have ever visited alone. You will get to experience places you have never thought about before. You will learn more about your parents and strengthen your relationship with each other. You will come back with many beautiful pictures for your family album. And most importantly, you will get a delicious meal prepared by mom every day. Yum!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vFlHblbipeB3SKAUwEjx2A.png" /><figcaption>After a small trek in Phuket</figcaption></figure><p>The feeling you get out of traveling with parents and the smile you see on their face is worth billions of dollars earned. We all should do it once in our lifetime, no matter how busy our life gets. As my <a href="https://medium.com/@pareshmayani">good friend</a> puts it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*lqcf1c3Tkzuf9tRb-DEiHg.png" /></figure><p>The only tricky thing that happened while traveling with my family was in the end. It’s really challenging to say good bye to them at the airport after such a fantastic time we had! I’m still very emotional about this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*AgHQH_Qzwqx7-FpmCOqsUw.png" /><figcaption>Text from my uncle after my parents reached home!</figcaption></figure><p>Are you a serial traveler and workaholic? If yes, then you probably don’t see your parents frequently like me. This is our opportunity to help them understand the passion for travel and why we’re often so far from home. The work will be done. The people you love aren’t interruptions. They’re the reason you work at all. Give them a hug and allow them to share more with the person you’ve grown up to become.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g5HFg-djU3eWu4qMXezsvw.jpeg" /><figcaption>I’m so fortunate to have parents who have sacrificed everything for my better education. This is the least I can do for them.</figcaption></figure><p>Thank you for reading! If you’ve enjoyed this article, hit the clap button and follow me to get the next articles in this series.</p><blockquote><a href="https://medium.com/@shahyash/do-you-want-to-travel-around-the-world-read-this-first-4d71f7542f02">Do you want to travel around the world? Read this first.</a></blockquote><p><em>I’m incredibly grateful to get an opportunity to travel and work with </em><a href="https://stasislabs.com/"><em>Stasis</em></a><em> where we are a</em>ccelerating Indian Healthcare towards Proactive Patient Care. <a href="https://angel.co/stasis-labs"><em>We’re Hiring</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86f72e2fc4d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stuck On: Building a Realtime Feed with React and appbase.io]]></title>
            <link>https://medium.com/all-things-data-streams/stuck-on-building-a-realtime-feed-with-react-and-appbase-io-5c627232714f?source=rss-8e98875dca4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c627232714f</guid>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[appbase]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yash Shah]]></dc:creator>
            <pubDate>Wed, 10 Feb 2016 16:39:54 GMT</pubDate>
            <atom:updated>2016-06-21T18:20:09.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*2Ix27p5Ef4wrlL6nt7IAsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*Xl-HxsBkIVNFb9LeGyPgCg.png" /></figure><p>I can’t possibly be the only one who hates stopping work to go into a meeting that talks about work so that I can eventually get more work done.</p><p>Today, we will show how to build “Stuck On” — a <em>tongue-in-cheek</em> named realtime status reporting app built using ReactJS and appbase.io.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53nsp-nKSfHrqfWpxsWnRA.png" /><figcaption>“Stuck On” — Status feed for teams</figcaption></figure><p><strong>Stuck On</strong> is a simple work status feed. It asks you for your work status and displays it in a feed along with your colleagues’ statuses.</p><p>For building “Stuck On”, we will be using ReactJS and appbase.io.</p><ol><li>ReactJS is a great library choice for building UI views, especially for a project like Stuck On that is simple by design. I encourage you to check out the <a href="https://facebook.github.io/react/docs/why-react.html">why react</a> page for good reasons to pick the library.</li><li>appbase.io is a hosted database API with native support for continuous queries, a good choice for building realtime feeds.</li></ol><h4>Setup and Code Structure</h4><pre>stuckon-clone/<br>|_ _ _ _ js/<br>|        |_ _ _ _ StuckOnInput.jsx<br>|        |_ _ _ _ StuckOnFeed.jsx<br>|_ _ _ _ css/<br>|        |_ _ _ _ style.css<br>|_ _ _ _ index.html<br>|_ _ _ _ config.json</pre><p>The above shows how our final directory structure would look. Let’s initialize all these files for later ease of access.</p><pre>touch index.html<br>touch config.json<br>mkdir -p js &amp;&amp; touch js/StuckOnInput.jsx<br>touch js/StuckOnFeed.jsx<br>mkdir -p css &amp;&amp; touch css/style.css</pre><p>If you are wondering about the .jsx files in the js/ folder, they are an extension of javascript used by React. A <strong>.jsx</strong> file allows adding HTML markup for DOM rendering but without altering any of the existing javascript semantics.</p><p>Next, we will install react and appbase.io’s js lib via bower.</p><pre>bower install react<br>bower install appbase-js</pre><p>We are all set to write some React now. For keeping the tutorial dead simple, we will break the whole app into two separate pieces — One for posting new status updates and, and the other for viewing the realtime status feed.</p><h3>Posting New Status Updates</h3><p>Let’s start by creating a basic HTML skeleton for the app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab18e6797d6440e3e84c10391d22bd50/href">https://medium.com/media/ab18e6797d6440e3e84c10391d22bd50/href</a></iframe><p>Next, we will include the stylesheets (materialize) and javascript files in the HTML. It’s generally a good practice to load the stylesheets first, so we will put them in the &lt;head&gt; element after L3 in the above snippet. All the JS scripts should below the L7. Below are the files to add.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1646a6591a0805a9a0a3ea8b067b1bf/href">https://medium.com/media/d1646a6591a0805a9a0a3ea8b067b1bf/href</a></iframe><p>Notice L13,14 above refer to type of .jsx files as “text/babel”. This is because we use the babel transpiler (see L8) to transform <strong>.jsx</strong> syntax into <strong>.js</strong> because browser’s javascript runtime can’t understand <strong>.jsx </strong>(at least, not yet :-)).</p><h4>Building the component to post a status</h4><p>Now we will add a div for rendering the status update text inside the container div we created above as shown in the snippet here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51cf2a8f18acf625703da1a907968a9b/href">https://medium.com/media/51cf2a8f18acf625703da1a907968a9b/href</a></iframe><p>If you are following so far, we’re all set with the <strong>html</strong>. The snippets above have been numbered as index#{1,2,3}.html to show that we are editing the <strong>index.html</strong> in a continuing sequence. We will use this notation later for our .jsx files as well.</p><h4><strong>config.json</strong></h4><p>Next, we will populate our config.json file with appbase.io app credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0f7AkZzuwI6Hu0poF1TKQ.gif" /><figcaption>You need to get the <strong>username</strong> and <strong>password</strong> fields for your app as highlighted above.</figcaption></figure><p>We will add the <strong>appname</strong> along with it’s <strong>username</strong> and <strong>password</strong> credentials in the config.json file as shown below. We will additionally set the <strong>type</strong> field to a string value (say “feed”), and use this for indexing all the status updates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d874cf29011fcd2981b5af80dac2840/href">https://medium.com/media/4d874cf29011fcd2981b5af80dac2840/href</a></iframe><p>We’re all set with the config.json. If you are using a .git like version control tool, it’s a good idea to add this file to .gitignore, we don’t want other people prying into our app’s credentials.</p><p>Now let’s write some .jsx, one method at a time. We will start with the StuckOnInput.jsx file. <strong>StuckOnInput</strong> contains the <strong>StuckOnInput</strong> component, which contains two child components — <em>TwitterHandle</em> and <em>StatusInput</em>.</p><pre><strong>StuckOnInput </strong>component (the main UI widget)<br><strong>|<br>|_ _ _ _TwitterHandle</strong> component (sets user&#39;s twitter handle)<br><strong>|<br>|_ _ _ _StatusInput</strong> component (set&#39;s user&#39;s work status)</pre><p>If you aren’t familiar with React components, they are the fundamental units of organizing a React code and are roughly analogous to UI widgets. Components can be inherited, <a href="http://react-components.com/">remixed</a>, or contain other components.</p><p>We will start with defining the StuckOnInput component, followed by TwitterHandle and StatusInput components. A component in React is always invoked with a React.createClass({specObj}), where the specification object should contain a mandatory render() method. It can contain other methods for initialization and specifying state changes when the user interacts with the DOM. You can read in depth about a <a href="https://facebook.github.io/react/docs/component-specs.html">component’s spec and lifecycle here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88de74700efc61ec51a71beadb013213/href">https://medium.com/media/88de74700efc61ec51a71beadb013213/href</a></iframe><p>We will be using the following methods for our StuckOnInput component.</p><p><strong>getInitialState</strong> is invoked once before the component is mounted. Here, we set up an initial environment for the app.</p><ul><li>L11–20 reads the config.json and creates an appbaseRef object, we will use this object later to update the user status to the DB.</li><li>L24–32 checks for existing status value from localstorage or sets a default status of “Mining Bitcoin”.</li><li>L33–36 returns <strong>status</strong> and <strong>twitterHandle</strong> variables, they are set as the initial values for our component’s state.</li></ul><p>Next, we will add the <strong>componentDidUpdate</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed3e093d2421dafa3bce2969bc755630/href">https://medium.com/media/ed3e093d2421dafa3bce2969bc755630/href</a></iframe><p>Similar to how we suffixed the html continuation for the index file, we will suffix each component function as StuckOnInput#method_name.jsx.</p><p><strong>componentDidUpdate </strong>is invoked every time the component’s updates are rendered on the DOM. We use this method to mirror the state change onto localStorage so we can populate changes in placeholders in the next cycle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1776924074e4b204e5ec316e20205e26/href">https://medium.com/media/1776924074e4b204e5ec316e20205e26/href</a></iframe><p>In <strong>addInputToAppbase </strong>method, we index the status details in Appbase. It is invoked by the StatusInput component when user updates her status. We first call the <strong>setState</strong> to set the status and then use Appbase to index the status and twitterHandle along with a timestamp field as a JSON object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80d1e0dcafad93e959fe3c6a1396518b/href">https://medium.com/media/80d1e0dcafad93e959fe3c6a1396518b/href</a></iframe><p><strong>setTwitterHandle</strong> method is invoked by the TwitterInput component when user enters her twitter handle.</p><p>Finally, we render both the status and twitter handle in the render() method of the StuckOnInput component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ed23c10ad69e4c98990909522d9be52/href">https://medium.com/media/8ed23c10ad69e4c98990909522d9be52/href</a></iframe><p>Inside <strong>render()</strong>, we render the status input on the DOM if the user’s twitter handle is set, else we render the twitter input (asking the user to enter their twitter handle) on the DOM. The <strong>onSubmit</strong> prop in the return condition for both the <strong>TwitterInput</strong> and <strong>StatusInput</strong> components is called from these components to invoke the <em>addInputToAppbase</em> and <em>setTwitterHandle</em> methods we declared above.</p><p>So far so good. We will complete the status posting functionality by defining the <strong>TwitterInput</strong> and <strong>StatusInput</strong> components in the same file (StuckOnInput.jsx).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3083e6448445ecaf81f753e17c6b2b4b/href">https://medium.com/media/3083e6448445ecaf81f753e17c6b2b4b/href</a></iframe><p><strong>TwitterInput component</strong> takes the twitter handle as an input which <em>onSubmit </em>calls the parent component, the <em>StuckOnInput</em> method, to add the twitter handle. Some important things to note:</p><ul><li>Unlike StuckOnInput, we won’t define a <strong>getInitialState()</strong> method for TwitterInput as it doesn’t have any state.</li><li>We access the &lt;input&gt; tag’s value in L10 using <strong>this.refs.nameInput.value</strong>. Any DOM element can be accessed in React by adding a ref attribute, we did this for input in L17 as ref=“nameInput”.</li><li>Calling <strong>this.props.onSubmit</strong>(value) invokes the setTwitterHandle method in the StuckOnInput component.</li></ul><p>Next, we will add the <strong>StatusInput</strong> component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a2f15c41393e75002756e6f21d86439/href">https://medium.com/media/9a2f15c41393e75002756e6f21d86439/href</a></iframe><p><strong>StatusInput component </strong>takes status as input from the user (L17) calls the StuckOnInput’s <strong>addInputToAppbase</strong>() method via <strong>props.onSubmit</strong> in L9. Setting props is a standard way to communicate between components in React.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0368e6529e7847df21e7df961c07bd85/href">https://medium.com/media/0368e6529e7847df21e7df961c07bd85/href</a></iframe><p>Last, we will call the global ReactDOM.render() method adding the <strong>StuckOnInput</strong> component we created above inside the <strong>stuckOnInput</strong> div defined in the HTML.</p><p>We’re ready to render all this on the browser. It looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Uv71iVkAMMjKQNwLwNyEA.png" /><figcaption>First Screen of “stuck on” app</figcaption></figure><p>If you are wondering why it looks so bland, let’s add some styles to our style.css file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21bf70207faf8979beebab549ee89cce/href">https://medium.com/media/21bf70207faf8979beebab549ee89cce/href</a></iframe><p>After the styles, our page should look something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*19a6dRZPgGwd_1ByrSmVbw.gif" /></figure><h4>Building a realtime feed with infinite scroll</h4><p>We’ve already won half the battle and in the process learnt about React component fundamentals. We will now build a realtime feed around status updates, and along the way learn more about React. Hang on tight!</p><p>Let’s start by modifying the index.html to add a feed div where React will add the posts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3ef64f2cee47baeda937cd1c2544e56/href">https://medium.com/media/f3ef64f2cee47baeda937cd1c2544e56/href</a></iframe><p>Next, we will jump back to javascript and implement the realtime feed. To simplify things and use React effectively, we will think about the feed display experience into three modular components:</p><pre><strong>StuckOnFeed </strong>component (fetches feed from appbase.io)<br><strong>|<br>|_ _ _ _FeedContainer</strong> component (displays feed on the page)<br>        |<br>        |_ _ _ _<strong>FeedItem</strong> component (child element of FeedContainer)</pre><p>In StuckOnFeed component, we fetch the feed data from appbase.io.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a4677c384092b174b53f786fe65486a/href">https://medium.com/media/3a4677c384092b174b53f786fe65486a/href</a></iframe><p>In our <strong>getInitialState</strong> method, we initialize an appbase.io reference and create a feedQuery object that will match all the documents and return them in a descending order. We use this query object to:</p><ol><li>get the historical feed, where we increase our paginate count every time we call the feed query.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55fc42f8b77877b4f7c69bf57c20a4fe/href">https://medium.com/media/55fc42f8b77877b4f7c69bf57c20a4fe/href</a></iframe><p>2. subscribe to realtime updates, where we add the newly arriving feed data to the top of the items[] array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ec70805d121848fc3660899ead0c9e/href">https://medium.com/media/e2ec70805d121848fc3660899ead0c9e/href</a></iframe><p>The methods used above are <strong>search()</strong> -&gt; for fetching historical results and <strong>searchStream()</strong> -&gt; for subscribing to realtime updates. Both methods take the same feedQuery object that we created previously in the getInitialState method.</p><p>This ability to subscribe to new changes using the same query request makes appbase.io uniquely suited for building serious realtime streams. Imagine being able to create streaming search, price surge, complex scenario alerting with the familiarity of a NoSQL query syntax. The alternative in this case would have been to poll the database every few seconds for new updates, which is messy to begin with and starts breaking apart as you scale.</p><p><strong>Pagination and Infinite Scrolling</strong></p><p>So far so good, we have a top level idea of building a realtime feed. Next, we will add an infinite scrolling capability for easy navigation to old status updates.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74badeeda22b0a57126ae7fa39f04e0f/href">https://medium.com/media/74badeeda22b0a57126ae7fa39f04e0f/href</a></iframe><p>React’s <strong>componentWillMount</strong> makes it real easy to connect lifecycle javascript initializations with a component. We will set up a ‘scroll’ event listener that invokes the <strong>handleScroll</strong> method every time there is a scroll movement.</p><p>In <strong>handleScroll</strong>, we call the getHistoricalFeed() method on detecting a scroll to the bottom of the page. Remember, we already use a pagination counter in feedQuery object’s <strong>from</strong> field to change the starting point of the results on each getHistoricalFeed() request.</p><p>Now that we are all set with implementing feed and pagination mechanics, it’s time to render the <strong>items[]</strong> inside the FeedContainer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f16f1ad51391664858c2af2994a4035c/href">https://medium.com/media/f16f1ad51391664858c2af2994a4035c/href</a></iframe><p>The <strong>FeedContainer</strong> component is a collection of feed items.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b2e8a3c2f1aa2ac0186d0164026b99/href">https://medium.com/media/00b2e8a3c2f1aa2ac0186d0164026b99/href</a></iframe><p>As FeedContainer doesn’t contain any state — we only define the <strong>render</strong> method, where we loop through all the items in the current state and then render them as a <strong>FeedItem</strong> component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc3824eb02b08581c2a30b96ec083547/href">https://medium.com/media/cc3824eb02b08581c2a30b96ec083547/href</a></iframe><p><strong>FeedItem </strong>component simply returns the actual markup for rendering each status item. It displays the user’s profile pic (which we grabbed in the status update part) along side their work status message.</p><p>Lastly, we will call the global ReactDOM.render() method to add the <strong>StuckOnFeed</strong> component we created above inside the <strong>stuckOnFeed</strong> div defined in index.html file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/084f749465d8b2968b47025dcf318f69/href">https://medium.com/media/084f749465d8b2968b47025dcf318f69/href</a></iframe><p>Last but not least, we will add some style to the <strong>.profile-picture</strong>, <strong>.twitter-handle</strong> and <strong>.stuck-on-feed</strong> classes to make everything look pretty.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90b31e70fc8b7bc34b5dd214d6b36323/href">https://medium.com/media/90b31e70fc8b7bc34b5dd214d6b36323/href</a></iframe><p>If you have been faithfully following so far, you should see your browser screen look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53nsp-nKSfHrqfWpxsWnRA.png" /><figcaption>Final UI: “stuck on” app</figcaption></figure><h4>Deploying StuckOn to Github pages</h4><p>Don’t fret if you aren’t seeing this yet. We have made Stuck On to be directly deployable using Github. One big advantage of using Github to host is that you can sleep easy without worrying about uptime and reliability.</p><p>All you have to do is clone the following repository:</p><pre>git clone <a href="https://github.com/yashshah/stuck-on">https://github.com/yashshah/stuck-on</a></pre><p>Edit the config file with an appbase.io app’s credentials and enter them here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d874cf29011fcd2981b5af80dac2840/href">https://medium.com/media/4d874cf29011fcd2981b5af80dac2840/href</a></iframe><p>That’s it, you should be able to browse this by running a static http server. Python comes with a built-in one that you can use:</p><pre>python -m SimpleHTTPServer 8001</pre><p>Run the above command in the cloned git folder.</p><pre><a href="http://localhost:8001/">http://localhost:8001</a> (just go here and see stuck on live, booyah!)</pre><p>You can now host this project for free on Github pages. If you haven’t hosted one before, <a href="http://blog.teamtreehouse.com/using-github-pages-to-host-your-website">this link</a> will help you understand how to host one for free.</p><h4>Summary</h4><p>We build “Stuck On” literally from scratch (including installing vendor libraries) and in the process show how to think in React. We use appbase.io to show how to build a realtime feed and then go on to implement an infinite scroll functionality.</p><p>Finally, we host everything on github pages.</p><p>If you like reading this, give us a shout on twitter and leave your thoughts on this blog.</p><h3>appbase.io on Twitter</h3><p>Building a realtime feed with ReactJS and appbase.io https://medium.appbase.io/stuck-on-building-a-realtime-feed-with-react-and-appbase-io-5c627232714f#.pe1dlxr88 ... #react #datastreams #javascript #tutorial</p><p>Thanks for reading, happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c627232714f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/all-things-data-streams/stuck-on-building-a-realtime-feed-with-react-and-appbase-io-5c627232714f">Stuck On: Building a Realtime Feed with React and appbase.io</a> was originally published in <a href="https://medium.com/all-things-data-streams">All things #search</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>