<?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 Mendy Wolosow on Medium]]></title>
        <description><![CDATA[Stories by Mendy Wolosow on Medium]]></description>
        <link>https://medium.com/@mendywoly?source=rss-6b01c192f62c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ETNtYS0P61Zm1CRR.</url>
            <title>Stories by Mendy Wolosow on Medium</title>
            <link>https://medium.com/@mendywoly?source=rss-6b01c192f62c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:10:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mendywoly/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[Shabbat times widget]]></title>
            <link>https://mendywoly.medium.com/shabbat-times-widget-937fb4b750ba?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/937fb4b750ba</guid>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 18:21:08 GMT</pubDate>
            <atom:updated>2021-02-19T14:39:03.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-eyf-yxF1aWiXL1QeGI1w.jpeg" /></figure><ol><li>Download scriptable app <a href="https://apps.apple.com/us/app/scriptable/id1405459188">from app store here</a></li><li>Copy the code from below and paste it into the scriptable app.</li></ol><p>The only thing that needs to be changed is the first line.<br>Replace the contents of the zipString on the first line with a list of zip codes separated by a comma.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/868a382546c5609d7f3a354f6baa3cfc/href">https://medium.com/media/868a382546c5609d7f3a354f6baa3cfc/href</a></iframe><p>Shabbat shalom</p><p>Powered by <a href="https://www.hebcal.com/">hebcal</a>.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=937fb4b750ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pause Spotify in background on mac]]></title>
            <link>https://mendywoly.medium.com/pause-spotify-in-background-on-mac-b39f283d390a?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b39f283d390a</guid>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Wed, 10 Feb 2021 19:56:40 GMT</pubDate>
            <atom:updated>2021-02-10T19:56:40.561Z</atom:updated>
            <content:encoded><![CDATA[<p>Mac has a great play / pause button which will pause your music in the background. The issue becomes when you have multiple applications playing sound, the incorrect app may pause. To overcome this we can create an automation that can be be run in the background from spotlight search</p><p>Step 1: Open the script editor — Search for script editor from spotlight search.<br>Step 2: Paste the following code into body of the script editor</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50986fd24916a18550935bc2b5a2dcbc/href">https://medium.com/media/50986fd24916a18550935bc2b5a2dcbc/href</a></iframe><p>Step 3: Click File &gt; Save<br>Step 3: Type “Pause Spotify in the “Save as” box<br>Step 4: Choose “Application” under the “File Format” dropdown</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BQmWiT9sPx-DjINJSveww.png" /></figure><p>Enter Pause Spotify in spotlight search</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qgppvMJ9X8zU_KS9z1Q0Q.png" /></figure><p>The first time it runs it will ask you to allow. Click “OK”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*MenB-oFrfnLxd0WJDGdYLQ.png" /></figure><p>Now you can always run this in the background and it will toggle between play / pause on Spotify.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b39f283d390a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stripe Subscription with Default Trial]]></title>
            <link>https://mendywoly.medium.com/stripe-subscription-with-default-trial-dd2e5fca8545?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd2e5fca8545</guid>
            <category><![CDATA[stripe]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 16:46:43 GMT</pubDate>
            <atom:updated>2019-06-16T16:46:43.939Z</atom:updated>
            <content:encoded><![CDATA[<p>Trying to create a stripe subscription with a default free trial in the beginning? Seems simple enough, Right? Just create a pricing plan with a trial period.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*7iIYp2g099ISF15a-g_jUA.png" /></figure><p>Then create the subscription in your controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c52cf962d53a47f3a6122b7c2f43634/href">https://medium.com/media/3c52cf962d53a47f3a6122b7c2f43634/href</a></iframe><p>This will not work.</p><p>By default stripe will not use the trial from the subscription plan. You need to set the “trial_from_plan” to “true”</p><p>:trial_from_plan =&gt; true,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1e7a9e66c88402cc535563a418ae615/href">https://medium.com/media/b1e7a9e66c88402cc535563a418ae615/href</a></iframe><p>You can see this option from the official docs.</p><p><a href="https://stripe.com/docs/api/subscriptions/create#create_subscription-trial_from_plan">Stripe API Reference - Create a subscription</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd2e5fca8545" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uploading a file with react frontend and rails api backend.]]></title>
            <link>https://mendywoly.medium.com/uploading-a-file-with-react-frontend-and-rails-api-backend-eb61939eedbc?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb61939eedbc</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Sun, 02 Sep 2018 22:38:40 GMT</pubDate>
            <atom:updated>2018-09-02T22:38:40.000Z</atom:updated>
            <content:encoded><![CDATA[<p>So I recently graduated from Flatiron School and was working on an app where i had to temporarily upload a Tsv file to parse.</p><p>A tsv file is very similar to a Csv file but the separator is not commas but rather tabs (Tab Separated Values). You can still use the ruby csv library with just defining what the separator method is. In this case you can define the column separator as follows:</p><pre>col_sep: &quot;\t&quot;</pre><p><strong>Uploading the file</strong></p><p>To temporarily upload a file to parse you do not need to use paperclip or any special gem to help upload and store the file as it is only temporarily being uploaded to parse, after that you do not need the file at all.</p><p>On you front end you need to make an input with the type file. I am using a controlled form so it looks like this:</p><pre>&lt;form onSubmit={this.handleUpload}&gt;</pre><pre>&lt;input type=&quot;file&quot;</pre><pre>name=&#39;file&#39;</pre><pre>onChange={this.handleChange}</pre><pre>value={this.state.file}</pre><pre>/&gt;</pre><pre>&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;</pre><p>And here my on submit function.</p><pre>handleUpload = (event) =&gt; {</pre><pre>event.preventDefault()</pre><pre>const formData = new FormData();</pre><pre>const upload_file = this.state.file;</pre><pre>formData.append(&#39;file&#39;, upload_file);</pre><pre>Adapter.uploadFile(this.state.type, formData).then(r =&gt; r.json() )<br>.then(console.log)</pre><pre>}</pre><p>You need to attach the file to a new formData.</p><p>On you rails controller you now have access to the file and you can get the path which you can then pass to the csv parse method.</p><pre>file_path = params[:file].path<br>parser_method(file_path)</pre><p>To help with memory on a large file i use the csv.foreach instead of loading the entire file into memory.</p><pre>def parser_method(file_path)<br>CSV.foreach(file_path, encoding: &quot;iso-8859-1:UTF-8&quot;, col_sep: &quot;\t&quot;, quote_char: &quot;\x00&quot;, headers: true) do |row|<br>   // Do stuff here with the data<br>end<br>end</pre><p>So all of this worked perfectly until i uploaded my app to heroku. <br>Heroku by default times out if no response is sent back within a short period of time.</p><p>When parsing a large file directly from your controller and it will take a while, the process will still run on your backend but the frontent will receive an error code.</p><p>The proper way to do this would be through a background worker.</p><p>I found this great article <a href="https://itnext.io/sidekiq-overview-and-how-to-deploy-it-to-heroku-b8811fea9347">here</a> which explains really well how to set that up.</p><p>The issue with passing this work to the background worker is that the background worker which is running on a separate dyno does not have access to the file anymore. So you would need to upload and store the file and then pass the uploaded file to the background worker, and have that do the parsing.</p><p>After spending a few hours getting all this set up i realized the file issue.</p><p>Since the app i was working on was for in house use only and the file was still uploading we reverted back to directly parsing in the controller and although it still times out we manually keep an eye on the backend process through heroku logs — tail and then we know exactly when it is finished.</p><p>This isnt the ideal situation but for now this works for us.</p><p>My main take aways that were difficult for me to figure out was that to upload a file for temporary parsing you do NOT NEED to store it, just passing the file path is enough. <br>As well as sidekiq and redis for background jobs were not difficult to set up at all but they have the limitation here that the separate dyno does not have access to the file anymore.</p><p>Here is another great <a href="https://tylertringas.com/very-large-csv-import-in-rails-on-heroku/">article</a> going which goes in depth on this topic explaining the advantages and disadvantages on the methods mentioned above.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb61939eedbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React-table]]></title>
            <link>https://mendywoly.medium.com/react-table-cd807bb509b3?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd807bb509b3</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 18:35:53 GMT</pubDate>
            <atom:updated>2018-07-19T18:35:53.148Z</atom:updated>
            <content:encoded><![CDATA[<p>Get ready to be amazed!!</p><p><a href="https://react-table.js.org/#/story/readme">React Table - A lightweight, fast and extendable datagrid built for React</a></p><p>Install</p><pre>npm install react-table --save</pre><p>Component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*LgJR1uO3LF21rum0aHtvoA.png" /></figure><p>The two basic requirements of react-table are data and columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*aZCc8EPjpC98XujmvGAB5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*FolffwCZEibt5vuH5doEpw.png" /></figure><p>But there is a lot of functionality you can add with very very very little work.</p><p>Built in sorting</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*BFRJdPPP2NRbIUveNns7_g.png" /></figure><p>Hold down shift and you will get sorting by multiple columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*IsWPB-Us_ch8NaqV3ZgLaw.png" /></figure><p>Adding one line of code….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*Q-6PYdFprxKd2rkeYhX9Uw.png" /></figure><p>Gives you this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*C5kcnI2Vaef36oU3TQ2gVw.png" /></figure><p>If you want you can map over the data you received and change it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*C6OAcnb66VxooeKD3C7jCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*nA6Ka5CBu_Gbtm1RwYSVbg.png" /></figure><p>I wanted to add a simple button to my table but I couldn&#39;t figure out the HOC that I needed to use to get it to work.</p><p>So here was my hack at it ….</p><p>I added a column with an action accessor, and added a button to the cell value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*KzrMHQXcApdpva8QQV914Q.png" /></figure><p>Created this function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*gT8wMuARYZXH1BSrf6jq1g.png" /></figure><p>and then it worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*71BcQ7dE1KQFqDn3yZKXhQ.png" /></figure><p>That took me a really long time to figure out.</p><p>I hope you learned some of the advantages of react-table, now you will never have to iterate again to create a table.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd807bb509b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mod 3 Blog]]></title>
            <link>https://mendywoly.medium.com/mod-3-blog-9b262924378?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b262924378</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 15:29:30 GMT</pubDate>
            <atom:updated>2018-06-20T19:11:14.433Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>.catch</strong></h3><p>A regular fetch would look something like this.</p><pre>API_URL = &#39;<a href="http://localhost:3000/api/v1/log">http://localhost:3000/api/v1/</a>events&#39;</pre><pre>fetch(API_URL).then(r =&gt; r.json()).then(console.log)</pre><p>If all goes right, this will print out all the results to your console. But what happens when in doesn’t work properly.</p><p>There wont be any error displayed on the screen for the user to see. This is where .catch comes in. Lets change our fetch a little but to include a .catch.</p><p>If we turn our server off and make this fetch.</p><pre>API_URL = &#39;<a href="http://localhost:3000/api/v1/log">http://localhost:3000/api/v1/</a>events&#39;<br>fetch(API_URL).then(response =&gt; response.json()).catch( err =&gt; alert(err)).then(console.log)</pre><p>We will get this alert</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*nh2jEJxs_chKRcvQerYfKQ.png" /></figure><h3><strong>Pessimistic Rendering</strong></h3><p>We thought we were doing pessimistic rendering here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*BYotK1F-4pnC7tN3O8govA.png" /></figure><p>The truth was though that our response was coming back ok, but it wasn&#39;t getting added to the database. As you can see here the object is getting returned but without an Id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*LVQXzqTwIBODZ51rNfUIwg.png" /></figure><p>Here we can add some custom logic to our controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*Bloafk6UfkKtUj3mDixS-w.png" /></figure><p>So now the response will come back with a 500 error, and we can update our code to include a catch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*lROF9uKXLQoZgi-xXXmWnA.png" /></figure><p>But this still does NOT work!!!! We wont hit our debugger.</p><p>So what is .catch looking for.</p><p>A catch is only looking if the promise is resolved or not. Not if the response is a good response.</p><p>So when we turn our server off and make the fetch the promise will get rejected and therefore we will hit our catch.</p><p>However if the server is on and the response status is 500, that promise is still getting resolved and we would need to write some custom error handling to have it hit a .catch.</p><p>In this case we can write a method that can check if the id is null and based off that we can break the promise chain.</p><p>Thank you for listening!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b262924378" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mod 2 Blog]]></title>
            <link>https://mendywoly.medium.com/blog-mod-2-ad65fbd6bac3?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad65fbd6bac3</guid>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Wed, 30 May 2018 20:06:28 GMT</pubDate>
            <atom:updated>2018-06-19T17:32:09.604Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How to add a comment in an .Erb file.</strong></p><p>If you a write a Ruby comment or a html comment</p><pre>Ruby Comment ##<br>Html comment &lt;!––  ––&gt;</pre><p>Neither of these options will work if that content is invalid. The file wont load at all and will throw an error.</p><p><strong>Here is how to get around that!</strong></p><pre>&lt;% if 1 == 0 %&gt;</pre><pre>Code to be ignored here</pre><pre>&lt;% end %&gt;</pre><p>We write a statement that will always be invalid and that code will never run.<br>Problem solved!!!</p><h3><strong>Hashes and Salts</strong></h3><p>We were all recently introduced to password encryption, which intrigued me so i decided to take a quick look.</p><p>Table with password stored in plain text.</p><pre>users_table</pre><pre>user_id - username - password<br>1      -   user1  - hello<br>2      -   user2  - goodbye<br>3      -   user3  - password<br>4      -   user4  - strongpassword<br>5      -   user5  - Strongest_Password1234!@#</pre><p>This is obviously not good. If someone gets their hands on this database they will have all the passwords.</p><p>Passwords stored with SHA-1 Encryption</p><pre>users_table</pre><pre>user_id - username - password<br>1      -   user1  - <strong>aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d</strong><br>2      -   user2  - <strong>3c8ec4874488f6090a157b014ce3397ca8e06d4f</strong><br>3      -   user3  - <strong>5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</strong><br>4      -   user4  - <strong>2ae868079d293e0a185c671c7bcdac51df36e385</strong><br>5      -   user5  - <strong>6910376821bb6ed57d0f6ebb9f9e5b2bb0c7590c</strong></pre><p>Rainbow tables are quite complicated, but here is something that these hashes wont do well with.</p><p>Every time you put in hello in the SHA-1 generator you will get the same result.</p><p>We can start creating a master table of random strings and their hashes.</p><pre>random string example - SHA-1 Result</pre><pre>letsdoit - <strong>1b7c1538bbbe5f1a00df97caa1e16c6fd672c497</strong><br>hello - <strong>aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d<br></strong>goodbye <strong>- 3c8ec4874488f6090a157b014ce3397ca8e06d4f</strong><br>password  - <strong>5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</strong><br>strongpassword  - <strong>2ae868079d293e0a185c671c7bcdac51df36e385</strong><br>Strongest_Password1234!@# - 6<strong>910376821bb6ed57d0f6ebb9f9e5b2bb0c7590c<br></strong>random - <strong>a415ab5cc17c8c093c015ccdb7e552aee7911aa4</strong></pre><p>If we get our hands on this database of hashes we can see if we have any hashes that match a hash in the database. We can then see the corresponding string and well have the password!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*osI6jPlvH1EaX3MpjGLFOQ.png" /></figure><h3><strong>Salts</strong></h3><p>Salts are not a secret and can even be stored in plain text.</p><p>Lets say the user chooses hello as his password. <br>The hash that will be returned with SHA-1 is “<strong>aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d”</strong></p><p>Now if we added a salt to that password for this user, lets say we user “rspect”.<br>The hash that will be returned is “<strong>d7409195c9d1130767b6a199ed4e0943d70b9fb4”, </strong>and this is what we will store in out database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*KgfslXwWaT0WLkOueUJnnQ.png" /></figure><p>Now even if a hacker gets our salt “rspec”, then he would have to recreate his hashed database and rerun every random string with “rspect” at the beginning, and this only works for one user being that the salt is unique for every user!!!</p><p>Even this wouldn’t be sufficient. If a hacker gets the salts database he can then combine the salt with the most common passwords “Which are apparently more common then you think”, and begin brute forcing that way.</p><p>Therefore bcrypt and similar encryption methods and really slow and an attack like this would take way too long!</p><p>Problem Solved!!</p><p>Why I skipped over Rainbow Tables</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*HUtLwivyuZp5CScg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/0*TtJPx7r6vfwgQvGW.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad65fbd6bac3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importing Csv file]]></title>
            <link>https://mendywoly.medium.com/importing-csv-file-ddab50d9d90b?source=rss-6b01c192f62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddab50d9d90b</guid>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Mendy Wolosow]]></dc:creator>
            <pubDate>Thu, 10 May 2018 17:02:00 GMT</pubDate>
            <atom:updated>2018-05-10T17:02:27.541Z</atom:updated>
            <content:encoded><![CDATA[<p>Ive been working with excel sheets for the past year, so the use of active record and the ability to manipulate databases is very interesting for me.</p><p>Import a csv file.</p><p>I needed to require ‘cvs’ in the top of my ruby file.</p><p>So typically in order to require a gem you need to have that gem in the Gemfile, then run bundle install. Only after that you can require that gem.</p><p>Your gem file would have:</p><pre>gem &#39;csv&#39;</pre><p>and your main file would have</p><pre>require &#39;csv&#39;</pre><p>in this scenario the csv gem is built into the ruby version that i have installed, so i didn’t need to include it in my gemfile, but normally you would need to.</p><p>Requiring gems in IRB</p><p>If you would like to test out a gem in IRB you can just require that gem in IRB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*88055olP4tF4muGgEGMCDw.png" /></figure><p>This is how my csv looks</p><pre>sku,reason,quantity<br>Sku1,Order,1<br>Sku1,Order,1<br>Sku1,Return,1<br>Sku2,Order,1<br>Sku2,Order,1<br>Sku2,Return,1</pre><p>Csv Syntax</p><pre>csv_text = File.read(&quot;file_name&quot;)</pre><pre>csv = CSV.parse(csv_text, :headers =&gt; true, :encoding =&gt; &#39;ISO-8859-1&#39;)</pre><pre>csv.each do |row|<br>    puts row.to_hash<br>end</pre><pre>#output</pre><pre>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Return&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Return&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}</pre><p>This will become and hash!</p><pre>#output</pre><pre>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku1&quot;, &quot;reason&quot;=&gt;&quot;Return&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Order&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}<br>{&quot;sku&quot;=&gt;&quot;Sku2&quot;, &quot;reason&quot;=&gt;&quot;Return&quot;, &quot;quantity&quot;=&gt;&quot;1&quot;}</pre><pre>#Original Csv data</pre><pre>sku,reason,quantity<br>Sku1,Order,1<br>Sku1,Order,1<br>Sku1,Return,1<br>Sku2,Order,1<br>Sku2,Order,1<br>Sku2,Return,1</pre><p>Now we can easily manipulate the csv data</p><pre>csv.each do |row|<br>  if row[&#39;reason&#39;] == &#39;Order&#39;<br>    t = Order.new<br>    t.sku = row[&#39;sku&#39;]<br>    t.quantity = row[&#39;quantity&#39;]<br>    t.save<br>elsif row[&#39;reason&#39;] == &#39;Return&#39;<br>    t = Return.new<br>    t.sku = row[&#39;sku&#39;]<br>    t.quantity = row[&#39;quantity&#39;]<br>    t.save<br>  end<br>end</pre><p>We check the csv to see if its an order or a return, based on that we either create an order object or a return object.</p><p>Lets break down that code</p><pre><br>csv.each do |row|</pre><pre>### if its an order<br>  if row[&#39;reason&#39;] == &#39;Order&#39;</pre><pre>#then create the order instance, with the order data<br>    t = Order.new</pre><pre>#add the data</pre><pre>    t.sku = row[&#39;sku&#39;]<br>    t.quantity = row[&#39;quantity&#39;]</pre><pre>#then save it    </pre><pre>     t.save</pre><p>Hope you enjoyed. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddab50d9d90b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>