<?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 Vakas Akhtar on Medium]]></title>
        <description><![CDATA[Stories by Vakas Akhtar on Medium]]></description>
        <link>https://medium.com/@vakas0959?source=rss-7744fbef9ce0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*A5eq1ebi_LeQRcvSJJLNKw.jpeg</url>
            <title>Stories by Vakas Akhtar on Medium</title>
            <link>https://medium.com/@vakas0959?source=rss-7744fbef9ce0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:19:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vakas0959/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[Parsing a CSV File in Ruby]]></title>
            <link>https://medium.com/swlh/parsing-a-csv-file-in-ruby-6de8afd382c8?source=rss-7744fbef9ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6de8afd382c8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Vakas Akhtar]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 03:48:33 GMT</pubDate>
            <atom:updated>2021-02-04T23:51:55.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*QJIayPCQeHJnSMUt.jpg" /></figure><p>CSV stands for comma separated values which is commonly seen in excel spreadsheets. While on a program like excel the data will appear with columns and rows inside its own cells, once viewed as raw code the CSV file will look something like this.</p><pre>&quot;name, age, gender&quot;<br>&quot;Bill, 24, male&quot;<br>&quot;Ana, 20, female&quot;</pre><p>Ruby has a built in library that allows us to do many things with CSV files. To begin go ahead and create a new file and add</p><pre>require &#39;csv&#39; </pre><p>at the top. Now that you can use an entire set of methods to do what you’d like to interact with your csv file. To simply read your csv file you can go ahead and enter the following code.</p><pre>require &#39;csv&#39;<br>CSV.read(&quot;MY_FILE.csv&quot;)</pre><p>or you can parse it</p><pre>require &#39;csv&#39;<br>CSV.parse(&quot;MY_FILE.csv&quot;)</pre><p>These methods however do not account for the fact that our CSV file has headers. In order to include our headers we can go with another approach. These methods are also no good if our file was large, say greater than 10 MB. To bypass these issues the best approach would be to use a foreach method and with a block and read the file line by line. This way the program will be faster and use less memory. This approach would look something like this.</p><pre>require &#39;csv&#39;</pre><pre>CSV.foreach((&quot;MY_FILE.csv&quot;), headers: true, col_sep: &quot;,&quot;) do |row|<br>    puts row <br>end </pre><p>Inside the foreach method we include parameters such as the file path along with items such as the headers and column separators. By declaring headers true the program will recognize the first row as headers and you can reference them as you iterate through each row. The column separator is exactly what it sounds like. This is the character that separates each column. In our case the columns are separated by commas but it is possible that our file could be separated by something else like pipes in which case our col_sep would look like this</p><pre>col_sep: &quot;|&quot;</pre><p>Now you can go ahead and play around with this script and I suggest viewing each row by column name or index like so to see what your code will output to get a better idea of how things are working.</p><pre>require &#39;csv&#39;</pre><pre>CSV.foreach((&quot;MY_FILE.csv&quot;), headers: true, col_sep: &quot;,&quot;) do |row|<br>    puts <strong>row[0] <br>    </strong>puts<strong> row[&quot;age&quot;]<br></strong>end</pre><p>From here you can get creative and do whatever you’d like with your CSV file. Go head and try iterating through each row and adding some data into an array while the foreach method runs through your CSV file.</p><pre>require &#39;csv&#39;</pre><pre>array = []</pre><pre>CSV.foreach((&quot;MY_FILE.csv&quot;), headers: true, col_sep: &quot;,&quot;) do |row|<br>    array &lt;&lt; row[0]<strong><br></strong>end</pre><pre>puts array </pre><p>Now you have an array with all the data from your first column. With this array we could now go ahead and create a new CSV file.</p><pre>require &#39;csv&#39;</pre><pre>array = []</pre><pre>CSV.foreach((&quot;MY_FILE.csv&quot;), headers: true, col_sep: &quot;,&quot;) do |row|<br>    array &lt;&lt; row[0]<strong><br></strong>end</pre><pre>CSV.open(&#39;NEW.csv&#39;, &#39;wb&#39;) do |csv|<br>   csv &lt;&lt; [&quot;name&quot;]<br>   array.length.times do |i|<br>   csv &lt;&lt; [array[i]]<br>   end <br>end </pre><p>With the method CSV.open, the first argument is the name of the csv file that will be outputted and the second parameter ‘wb’ indicates that the program will write a new csv file. From here we create our first line which is a header called name. We shovel that in to the variable within our block called csv and add that to our table. Next we loop through the array of all the names we collected earlier and add them into the csv. We run the loop according to how large our array is. After this you can look at your project directory and you’ll see your new CSV file outputted.</p><p>To close, there are many ways you can manipulate your CSV files and how you’d like to output them. By using what was taught in this article you could now go ahead and maybe parse a CSV file and use that data to seed your database in your rails API. Or you could even convert your parsed data in JSON format. The possibilities are endless.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6de8afd382c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/parsing-a-csv-file-in-ruby-6de8afd382c8">Parsing a CSV File in Ruby</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL vs REST]]></title>
            <link>https://vakas0959.medium.com/graphql-vs-rest-e275adccefff?source=rss-7744fbef9ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e275adccefff</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Vakas Akhtar]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 04:45:24 GMT</pubDate>
            <atom:updated>2021-01-05T04:45:24.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-F-IhKof55tUc5wO.png" /></figure><p>The REST architectural style has been the standard for designing APIs for quite some time. One main critique of REST is that it can be inflexible at times. GraphQL enters the situation as an alternative to the mainstream and it even offers a more flexible and efficient solution than REST for fetching your data.</p><p>Let’s say for example we were attempting to fetch some data for a user. In some cases we’d find ourselves using multiple endpoints to gather the users information such as its posts and followers. Whereas with GraphQL you would simply send one Query and you’d get all the data you would need. Below is a sample GraphQL query:</p><pre>query {<br>    User(id: &quot;dkaljker3&quot;) {<br>       username:<br>       posts {<br>         caption<br>       }<br>       followers(last: 5) {<br>          username<br>       }<br>     }<br>   }</pre><p>With the above query we are able to fetch the exact data required. Notice that we only fetch the User’s last 5 followers and only the posts caption, this helps prevent what is called Overfetching. Generally when an app makes a call to a REST API endpoint we download an array of JSON data. In this case if we wanted to display a list of the last 5 followers we’d end up downloading the entire follower list and then write out the logic to filter out the rest after it’s been downloaded. Now with GraphQL we can efficiently and quickly gather just the right amount of data required for our app.</p><h3>Schema &amp; Types</h3><p>GraphQL has a strong type system. All the types that would be presented in the API are written out in the schema using the GraphQL Schema Definition Language (SDL). Now pair this with Typescript, on your next react project and you’ll have an extremely testable and efficient process during your development period. While the frontend team works to bring the UI to life they can easily test their components with mock data that is identical to what the completed API will provide. This allows for a seamless transition once the backend team completes their work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C2H0w1D_f2SZ50wk.png" /></figure><h3>AWS Amplify</h3><p>For those interested in building out their first project using GraphQL I highly recommend using <a href="https://aws.amazon.com/amplify/getting-started/">AWS Amplify </a>. Their documentation is well done and their services such as their authentication are a pleasure to use. Look back to the sample query I had written earlier to fetch a User’s data. With amplify’s CLI you’ll be able to simply write out a couple of lines and AWS will do the rest to help you write out your queries for full CRUD functionality. Their authentication service also comes with a prebuilt login/sign up components that allows you to build prototypes rapidly for testing. It’s also used by a large amount of startups and larger companies, so learning amplify could be beneficial to those looking for a job.</p><pre>type User @model {<br>  id: ID!<br>  name: String!<br>  imageUri: String<br>  status: String<br>} </pre><p>The above lines of code written in your schema.graphql file will allow AWS Amplify to automate over 100 lines of code for your Queries. Make sure to read their documentation and start building out your own API to see for yourself. AWS’s free tier is more than enough for a simple personal project. With that being said, welcome to the world of GraphQL!</p><blockquote>“Think in graphs, not endpoints.” — Lee Byron, Co-Creator of GraphQL</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e275adccefff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[USD Coin: AKA “The Digital Dollar”]]></title>
            <link>https://medium.datadriveninvestor.com/usd-coin-aka-the-digital-dollar-74a9fe84f412?source=rss-7744fbef9ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/74a9fe84f412</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Vakas Akhtar]]></dc:creator>
            <pubDate>Tue, 29 Dec 2020 04:27:47 GMT</pubDate>
            <atom:updated>2020-12-29T17:41:58.346Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*76YAWRsl7hoM7Gfc.jpg" /><figcaption>There’s been rumblings that the FED is looking to replace the dollar with a digital counterpart. In this article let’s talk about a stablecoin called the “USD Coin”.</figcaption></figure><p>Cryptocurrencies are leading the charge for a decentralized world. They’re known for being protected from inflation, secure, and unfortunately extremely volatile. However, with the introduction of stablecoins there are ways to mitigate this issue.</p><p><a href="https://www.investopedia.com/terms/s/stablecoin.asp">Investopedia’s</a> definition of stablecoins is that they’re a new class of cryptocurrencies that attempts to offer price stability and are backed by a reserve asset. Stablecoins have gained traction as they attempt to offer the best of both worlds — the instant processing and security or privacy of payments of cryptocurrencies, and the volatility-free stable valuations of fiat currencies. Tether is known as one of the most influential and controversial stablecoins which released in 2015 and currently has a market cap of $21.41B. It’s also facing a lawsuit that’s accusing them of deceptive, anti-competitive and market-manipulative behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/0*bNxEJE8mb8qBXszH.png" /></figure><p>At number two is the USD Coin (USDC) with a market cap of $3.59B. USDC was first announced in May 2018 by Circle, and launched in September 2018. It’s also managed by Coinbase. USDC is a Fiat-backed stablecoin. It can be traded on exchanges and are redeemable from the issuer. Its value is pegged to the US dollar and the tether is realized off-chain, through regulated financial institutions which serve as depositaries of the currency used to back the stablecoin. To put it simply, this means that you can <strong>always exchange 1 USD Coin for US$1.00</strong>. Recently, Forbes has reported that Visa is linking its 60 million-merchant-strong international payments network to the U.S. Dollar Coin (USDC). Circle is rapidly adding value for the entire blockchain ecosystem!</p><p><a href="https://www.datadriveninvestor.com/2020/12/17/unearthed-crypto-gem-poised-for-resurgence/">Unearthed Crypto Gem Poised for Resurgence | DataDrivenInvestor</a></p><h3><strong>ERC20</strong> Tokens</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n01TQQ4KGisX21jK.png" /></figure><p>USDC is available as Ethereum ERC-20. ERC20 tokens are used for all smart contracts on the Ethereum blockchain for token implementation and provides a list of rules that all Ethereum-based tokens must follow. Now all Dapps on the Ethereum blockchain can begin to use USDC. Currently the coin is being used in various marketplaces, such as Crypto Kitties, as a stablecoin to allow users to purchase items using credit and debit card systems. With the flow of credit and debit card payments along with the many ways that financial institutions can program USDC the future will truly be something to look forward to. In fact the current fractional reserve system where only 10% of your balance is backed by cash may be overthrown as USDC is 100% backed by cash.</p><h4>Gain Access to Expert View — <a href="https://datadriveninvestor.com/ddi-intel">Subscribe to DDI Intel</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74a9fe84f412" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/usd-coin-aka-the-digital-dollar-74a9fe84f412">USD Coin: AKA “The Digital Dollar”</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>
        <item>
            <title><![CDATA[Tutorial: Build a RESTful API With CRUD Functionality Using Node.js, Express.js & MongoDB]]></title>
            <link>https://medium.com/swlh/tutorial-build-a-restful-api-with-crud-functionality-using-node-js-express-js-mongodb-4a1aa6eb4de6?source=rss-7744fbef9ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a1aa6eb4de6</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Vakas Akhtar]]></dc:creator>
            <pubDate>Mon, 07 Dec 2020 09:02:38 GMT</pubDate>
            <atom:updated>2020-12-10T00:06:36.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C4kaVktJJkeWv8lT.jpg" /></figure><h3>Prerequisites</h3><p>Before building your API make sure you have Node.js and MongoDB installed and setup on your machine before starting this tutorial. The complete code can be found <a href="https://github.com/vakas-786/Blog-Node.js">here</a>.</p><h3>Initial Setup</h3><p>Let’s get started by first opening up our terminal and creating a folder for our API. I chose to name my folder node-practice but feel free to name it whatever you’d like.</p><pre>mkdir node-practice</pre><p>Then cd into your folder and open it in your text editor. I’ll be using VSCode for this tutorial. Next initialize the package.json file.</p><pre>npm init -y</pre><p>Your package.json file will now look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dSh5il4yFv_BF3gYvTLS7Q.png" /></figure><p>Next we’re going to install express mongoose to help us connect to MongoDB.</p><pre>npm install express mongoose</pre><p>If you look at your package.json you should now see express and mongo under your dependencies. Now install nodemon to ensure that we don’t have to restart the server every time we update our code.</p><pre>npm install nodemon -D</pre><p>After installing nodemon make sure you edit your scripts in your package.json file to include your nodemon dev dependencies. Your package.json file should look like this now.</p><pre>{</pre><pre> &quot;name&quot;: &quot;node-practice&quot;,</pre><pre> &quot;version&quot;: &quot;1.0.0&quot;,</pre><pre> &quot;description&quot;: &quot;&quot;,</pre><pre> &quot;main&quot;: &quot;index.js&quot;,</pre><pre> &quot;scripts&quot;: {</pre><pre> &quot;dev&quot;: &quot;nodemon server&quot;</pre><pre> },</pre><pre> &quot;keywords&quot;: [],</pre><pre> &quot;author&quot;: &quot;&quot;,</pre><pre> &quot;license&quot;: &quot;ISC&quot;,</pre><pre> &quot;dependencies&quot;: {</pre><pre> &quot;express&quot;: &quot;^4.17.1&quot;,</pre><pre> &quot;mongoose&quot;: &quot;^5.11.5&quot;</pre><pre> },</pre><pre> &quot;devDependencies&quot;: {</pre><pre> &quot;nodemon&quot;: &quot;^2.0.6&quot;</pre><pre>  }</pre><pre>}</pre><h3>Setting Up the Server</h3><p>First create a file and name it server.js</p><pre>touch server.js</pre><p>Inside this file we’ll require express, create a route, and set a variable for the PORT that our server will use.</p><pre>const express = require(&#39;express&#39;);</pre><pre>const app = express();</pre><pre>app.get(&#39;/&#39;, (req, res) =&gt; {<br>   res.send(&#39;Hello World&#39;);<br>});</pre><pre>const PORT = process.env.PORT || 5000;</pre><pre>app.listen(PORT, () =&gt; console.log(`Server running at port ${PORT}`));</pre><p>Now if you run the server by entering the following command in your terminal you should see the “Hello World” text show up at <a href="http://localhost:5000/">http://localhost:5000/</a> :</p><pre>npm run dev</pre><h3>MongoDB</h3><p>Now it’s time for us to create our database! Hop on your browser and make your way over to MongoDB Atlas and create a new project. Once you’ve created your project you’ll have the option to build a cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-J7uIOTKFLuugqsOvgX8A.png" /><figcaption>Select the button in the center to build a cluster</figcaption></figure><p>Once you’ve clicked the button you’ll be taken to this page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GF75t3coJ4ZDtmWQkQjmaA.png" /><figcaption>Select the free option.</figcaption></figure><p>From this menu select the free option and continue on to the next steps in building your cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0i5WXdFfH2NtYV0_dpL7Q.png" /></figure><p>Here in this menu you can select any location you’d like but for now, for the sake of simplicity do not change any of the other default options. For now I’ll choose N.Virginia and create my cluster after I complete my captcha questions and prove I’m not a robot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4R7EVu0eta2RxEMIAb7b-Q.png" /><figcaption>Wait 3 minutes for your cluster to be created.</figcaption></figure><p>Now we wait for our cluster to be created. In the meantime let’s adjust some more settings. Head over to the network access tab on the left and select allow access from anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9EG5DovyFKTCID-GwfJRew.png" /><figcaption>You can add a custom IP Address but for now we’ll allow access from anywhere</figcaption></figure><p>Once you’ve confirmed your network access it may take a minute or two to finalize this action. So let’s move on and click on the Database Access section. From here we’ll add a user that will be used when we connect to our Node backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JVQ3MckUfHlIy-EPLkUtEA.png" /><figcaption><strong>Remember to copy and paste your username and password since we’ll need it later on.</strong></figcaption></figure><p>From here you can create your own username and generate a secure password. Once you’ve generated your password make sure you copy it and keep it on the side since we’ll be using it very soon. Scroll down and you will see an option to create a user and you should be all set for the next step. <strong>Now is a good time to check that your cluster is created and that your Network Access status is active.</strong></p><p>Perfect! Now go back to the clusters tab and select the option to connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDZppBQHEppVrQ2JIwqtBw.png" /><figcaption>You should see this pop up after clicking connect.</figcaption></figure><p>From here select the option to connect to your application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4HalDDM0xpn8GTsYqoQfhg.png" /></figure><p>Make sure the driver is set to Node.js and select your desired version. Once your settings are good to go copy the url and return to your text editor.</p><p>From your terminal create a new file called config.js</p><pre>touch config.js</pre><p>Inside this file enter the following code and paste the url that you copied earlier into the code:</p><pre>module.exports = {<br>   MONGO_URI:`mongodb+srv://YOUR_USERNAME&lt;password&gt;<a href="http://twitter.com/cluster0">@cluster0</a>.qo3oa.mongodb.net/&lt;dbname&gt;?retryWrites=true&amp;w=majority`<br>}</pre><p>Inside the url where it says &lt;password&gt; paste in your password that you generated earlier. In the section &lt;dbname&gt; you can enter any name you would like.</p><p>Now let’s head back to the file server.js and make some changes to incorporate mongoDB. First we’ll add mongoose and import our MONGO_URI. Then we’ll remove the route that rendered “Hello World”. Your server.js file should now look like this.</p><pre>const express = require(&#39;express&#39;);</pre><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const { MONGO_URI } = require(&#39;./config&#39;);</pre><pre>const app = express();</pre><pre>mongoose.connect(MONGO_URI, {<br>  useNewUrlParser: true,<br>  useUnifiedTopology: true,</pre><pre>})<br>  .then(() =&gt; console.log(&#39;MongoDB connected!&#39;))<br>  .catch(err =&gt; console.log(err));</pre><pre>const PORT = process.env.PORT || 5000;</pre><pre>app.listen(PORT, () =&gt; console.log(`Server running at port ${PORT}`));</pre><h3>Models and Routes</h3><p>Now it’s time to build out our routes and models. We’ll start by making a folder for our models</p><pre>mkdir models</pre><p>now inside the models folder create a file called Posts.js. Inside this file we’ll make the schema for the model.</p><pre>//Filename: Posts.js</pre><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const Schema = mongoose.Schema;</pre><pre>const PostSchema = new Schema({</pre><pre> title: {<br>  type: String,<br>  required: true,<br> },<br> body: {<br>  type: String,<br>  required: true,<br> },<br> date: {<br>  type: Date,<br>  default: Date.now,<br> }</pre><pre>});</pre><pre>module.exports = mongoose.model(&#39;Posts&#39;, PostSchema)</pre><p>Nice, now that our schema is set up and we’ve exported it lets make some routes. First make a folder called routes and inside the folder make another folder called api. Now inside your api folder create a file called posts_controller.js. Inside this file enter the following code.</p><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();</pre><pre>const Posts = require(&#39;../../models/Posts&#39;);</pre><pre>module.exports = router;</pre><p>Now that we’ve brought over our server, router, and model we can start building out our CRUD functionality. Before we move on let’s go back to our server.js file. Here we are going to add in our routes. When the user reaches <a href="http://localhost:5000/">http://localhost:5000/</a> they will be able to access posts_controller.js file which has all the routes.</p><pre>const express = require(&#39;express&#39;);</pre><pre>const mongoose = require(&#39;mongoose&#39;);</pre><pre>const { MONGO_URI } = require(&#39;./config&#39;);</pre><pre><strong>const postsRoutes = require(&#39;./routes/api/posts_controller&#39;)</strong></pre><pre>const app = express();<br><strong>app.use(express.json());</strong></pre><pre>mongoose.connect(MONGO_URI, {<br>  useNewUrlParser: true,<br>  useUnifiedTopology: true,</pre><pre>})<br>  .then(() =&gt; console.log(&#39;MongoDB connected!&#39;))<br>  .catch(err =&gt; console.log(err));</pre><pre><strong>app.use(&#39;/api/posts&#39;, postsRoutes);</strong></pre><pre>const PORT = process.env.PORT || 5000;</pre><pre>app.listen(PORT, () =&gt; console.log(`Server running at port ${PORT}`));</pre><h3>CRUD</h3><p>Now we can start building out our CRUD functionality! Below I’ll insert the code snippets for each action inside our posts_controller.js file. Remember we’ll be starting from below the line where we declared our variable for the Posts model.</p><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();</pre><pre>const Posts = require(&#39;../../models/Posts&#39;);</pre><pre>//your CRUD actions code go here </pre><pre>module.exports = router;</pre><h4>Create:</h4><pre>router.post(&#39;/&#39;, async (req, res) =&gt; {</pre><pre>const newPost = new Posts(req.body);</pre><pre>try {</pre><pre>const post = await newPost.save();</pre><pre>if(!post) throw Error(&#39;Something went wrong with the post&#39;)</pre><pre>res.status(200).json(post);</pre><pre>} catch {</pre><pre>res.status(400).json({msg: error})</pre><pre>}</pre><pre>});</pre><h4>Read:</h4><p><em>Get all posts</em></p><pre>router.get(&#39;/&#39;, async (req, res) =&gt; {</pre><pre>try {</pre><pre>const posts = await Posts.find();</pre><pre>if(!posts) throw Error(&#39;No Items&#39;);</pre><pre>res.status(200).json(posts);</pre><pre>}catch(err) {</pre><pre>res.status(400).json({mesg: err})</pre><pre>}</pre><pre>});</pre><p><em>Show one post</em></p><pre>router.get(&#39;/:id&#39;, async (req, res) =&gt; {</pre><pre>try {</pre><pre>const post = await Posts.findById(req.params.id);</pre><pre>if(!post) throw Error(&#39;No Items&#39;);</pre><pre>res.status(200).json(post);</pre><pre>}catch(err) {</pre><pre>res.status(400).json({mesg: err})</pre><pre>}</pre><pre>});</pre><h4>Update:</h4><pre>router.patch(&#39;/:id&#39;, async (req, res) =&gt; {</pre><pre>try {</pre><pre>const post = await Posts.findByIdAndUpdate(req.params.id, req.body);</pre><pre>if(!post) throw Error(&#39;Something went wrong while updating the post&#39;);</pre><pre>res.status(200).json({success: true});</pre><pre>}catch(err) {</pre><pre>res.status(400).json({msg:err});</pre><pre>}</pre><pre>});</pre><h4>Delete:</h4><pre>router.delete(&#39;/:id&#39;, async (req, res) =&gt; {</pre><pre>try {</pre><pre>const post = await Posts.findByIdAndDelete(req.params.id);</pre><pre>if(!post) throw Error(&#39;No post found!&#39;);</pre><pre>res.status(200).json({success: true})</pre><pre>}catch(err) {</pre><pre>res.status(400).json({msg: error})</pre><pre>}</pre><pre>});</pre><h3>Final Thoughts:</h3><p>Now that your API is all ready to go you can test it out yourself using <a href="https://www.postman.com/">Postman</a> with the url <a href="http://localhost:5000/api/posts">http://localhost:5000/api/posts</a>. The complete code for this blog can be found <a href="https://github.com/vakas-786/Blog-Node.js">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a1aa6eb4de6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/tutorial-build-a-restful-api-with-crud-functionality-using-node-js-express-js-mongodb-4a1aa6eb4de6">Tutorial: Build a RESTful API With CRUD Functionality Using Node.js, Express.js &amp; MongoDB</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inductive Chain Learning With FizzBuzz]]></title>
            <link>https://medium.com/swlh/inductive-chain-learning-with-fizzbuzz-2b3c6af6ac5f?source=rss-7744fbef9ce0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3c6af6ac5f</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[project-euler]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <dc:creator><![CDATA[Vakas Akhtar]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 13:49:44 GMT</pubDate>
            <atom:updated>2020-07-16T02:54:56.200Z</atom:updated>
            <content:encoded><![CDATA[<p>Fizz buzz started out as an innocent game to help children learn how to divide numbers. Over time it’s evolved into a test to filter out prospective applicants for various software engineering jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*ve4Hw9WUXG3tJ8ncsBfM_Q.jpeg" /></figure><p>The Fizz-Buzz test was invented by Imran Ghory in 2007 to interview software developers and to find out if the candidate can actually write code. The test is designed to be quite simple. Many still fall victim to it ironically due to its overly simplistic nature. Another reason some may fail is that they became familiar with a certain language by <strong>memorizing certain patterns</strong>, rather than being aware of the <strong>logic</strong> used in their programs. With that being said, there’s no need to feel discouraged. Failure is good for programmers as long as they learn from it. Today I’ll be walking through a common Fizz-Buzz problem and hopefully what you take away is not what code I used, but the logic behind the problem. I will be using Ruby to solve this problem but any language can be used to do so and once again, its <strong>all about the logic</strong>!</p><p>The problem is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UJ3jPKK9c-3xkmx3GxFGQQ.png" /><figcaption>(<strong>Disclaimer</strong>: There are multiple ways to solve this problem. Take a moment to think about how you would approach it before looking at the solution.)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*-pQ4PWzD6qBIrrti.jpg" /></figure><p>Let’s list what this problem is asking us to do:</p><ol><li>Create a loop that counts up to 100 and ends if the number is over 100.</li><li>If the number is divisible by 3 it returns “Fizz”</li><li>If the number is divisible by 5 it returns “Buzz”</li><li>If the number is divisible by both 3 and 5 it returns “FizzBuzz”</li></ol><p>Ok let’s get started! Take a look at the code below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBNvRXyXVriDa0BpEy2_-Q.png" /></figure><p>Great! Now we have a loop set up that will count from 1 to 100. The upto method is a convenience method that does the same thing as a <strong>for</strong> <strong>loop.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a3f-WgTahlSD3Ck-qKpY6g.png" /></figure><p>Here, I set an empty string equal to the variable str to collect all the elements and puts str will output the final result. Remember, our goal is to output the strings “Fizz”, “Buzz”, and “FizzBuzz” when a number meets the requirements from the problem. The program will keep adding on to the empty string as it goes through the logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*cAiPXuRin0XFgKmFDqFG2A.png" /><figcaption><strong>Be sure to include .to_s since adding an integer to a string would result in an error</strong></figcaption></figure><p>Now we have our logic inserted to the loop. The variable str will receive either the “Fizz” or “Buzz” with the help of the += assignment operator. We wouldn’t use the shovel method &lt;&lt; in this case since it alters the original string rather than creating a new one. The modulo operator (%) is used to determine whether or not the number in question is divisible by 3 or 5. <strong>A modulo operation</strong> finds the remainder or signed remainder after division of one number by another. For example,</p><pre>21/7 = 3.0 <br>22/7 = 3.14285714286</pre><pre>21 % 7 = 0 <br>22 % 7 = 1</pre><p>It’s imperative that you understand how modulo operations work, without it you would lack the ability to solve similar problems in the future.</p><p>Now when you run the file and check the results you should get…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JaedCjKubOS12oGzk3sQig.png" /></figure><p>Congratulations! Now you’ll be more than ready when your interviewer asks you to solve their FizzBuzz problem.</p><h3>Project Euler</h3><p>Now that you’re comfortable with FizzBuzz let’s take a look at another problem that’s quite similar. We’ll be looking at the first problem from projecteuler.net.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*8UXBL8sVj8k45RDv" /><figcaption>Leonhard Euler was a Swiss mathematician, physicist, astronomer, geographer, logician, and engineer</figcaption></figure><p>Projecteuler.net states that it is designed to challenge one’s problem solving and mathematics skills. A mathematics background is not necessary to complete the problems however, there are over 700 problems that get more difficult as you progress. The interesting part is that it involves <strong>inductive chain learning</strong>, meaning that by solving one problem it will expose you to a new concept that allows you to solve a previously inaccessible problem. Now let’s take a look at the first problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUV5d-yqi1IpYe48CyUSkA.png" /></figure><p>Wow! Would you look at that, it looks pretty similar to the FizzBuzz problem we did before. It seems our <strong>inductive chain learning</strong> process already started before we even embarked on our project Euler Journey!</p><p><strong>Let’s begin</strong>:</p><p>Similar to the last problem, it’s asking us to print out a list of numbers and pull out the ones that are divisible by 3 or 5. This time instead of 1 to 100 it is asking for all numbers below 1000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSp6DFauTGYRKIIN4Pjh8g.png" /></figure><p>First we have to set the variable total = 0 to allow us to store all elements that are divisible by 3 or 5. Later on we will be able to call on the variable to add up the elements and return the sum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pdClHDZ74cz-moZmh989Kw.png" /></figure><p>Now we code in our if statement with the modulo operations that will collect all the necessary numbers. Then by using the assignment operator += we add the iterated numbers onto the total where it is then finally outputted.</p><p>Now lets run the code and see what our answer is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5DgkOianPVi99KNDNiCk6w.png" /></figure><p>Here’s the answer on projecteuler.net</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vet48VZj39ukHU130CgUAQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F9g8PH1MbwTy4o%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fgeorge-lucas-attack-of-the-clones-9g8PH1MbwTy4o&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2F9g8PH1MbwTy4o%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="284" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8df88ca4083c53160db91e0ac6acb41/href">https://medium.com/media/d8df88ca4083c53160db91e0ac6acb41/href</a></iframe><p>Well 1 problem down and over 700 more to go ¯\_(ツ)_/¯. Just kidding, to be quite honest completing all the problems would be an incredible feat but just completing around 50 Project Euler problems would be enough to build up your computational logic. Don’t forget to push up your solutions to GitHub as well!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3c6af6ac5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/inductive-chain-learning-with-fizzbuzz-2b3c6af6ac5f">Inductive Chain Learning With FizzBuzz</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>