<?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 Pavel Beletsky on Medium]]></title>
        <description><![CDATA[Stories by Pavel Beletsky on Medium]]></description>
        <link>https://medium.com/@pavel.beletsky?source=rss-cb37cf701f64------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*zVWj0gm5kcRNn3Y2Rhs9oQ.jpeg</url>
            <title>Stories by Pavel Beletsky on Medium</title>
            <link>https://medium.com/@pavel.beletsky?source=rss-cb37cf701f64------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:42:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pavel.beletsky/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[What is Heroku and how to deploy your App in five minutes (Rails+JS)]]></title>
            <link>https://medium.com/@pavel.beletsky/what-is-heroku-and-how-to-deploy-your-app-in-five-minutes-rails-js-dd6e2a047240?source=rss-cb37cf701f64------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd6e2a047240</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Pavel Beletsky]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 10:36:46 GMT</pubDate>
            <atom:updated>2020-01-09T10:36:46.499Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_x-pLE35KCvm6kHd7MyXg.png" /></figure><h3>What is Heroku and how does it work?</h3><p><strong>Heroku</strong> is a cloud platform as a service (PaaS) supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go. For this reason, Heroku is said to be a polyglot platform as it has features for a developer to build, run and scale applications in a similar manner across most languages. Heroku was acquired by Salesforce.com in 2010 for $212 million.</p><p>Heroku is known for running apps in dynos — which are really just virtual computers that can be powered up or down based on how big your application is. If you want to process more data or run more complex tasks, you are going to need to add more blocks(what is called scaling horizontally) or increase the size of the blocks (what is called scaling vertically). Heroku then charges you a monthly fee based on the number of dynos that you have and the size of each dyno.</p><p>Although Heroku charges you by the dyno, they aren’t actually hosting your app. In fact, the entire Heroku platform, as well as every app built on Heroku is deployed to Amazon Web Services(AWS).</p><p>So, why use Heroku when AWS is present?</p><p>AWS is an Infrastructure as a Service(IaaS) provider, meaning they are responsible for managing large, shared data centers. These data centers are what we call “the cloud”. Companies like AWS, Azure, and Google have all created IaaS so that developers can pay to host their applications in these data centers instead of building servers themselves.</p><p>This is a great trade-off but due to the nature of their business, IaaS providers are more concerned with running the data centers than the developer’s experience working with them. This means there is a high level of knowledge of AWS is required to keep your apps running, especially at scale. If it’s any measure of how much there is to know, AWS offers 8 different certifications for people to validate their knowledge.</p><p>Heroku, on the other hand, is a Platform as a Service that sits on top of AWS to provide an experience that is specifically designed to make developers lives easier. For example, in order to keep an application running at scale on Heroku, it only takes knowledge of a few commands on the Heroku CLI and Dashboard.</p><h3>How to deploy your App in five minutes.</h3><ul><li>Create Heroku account.</li><li>Install Heroku (for MacOS):</li></ul><p>$ brew tap heroku/brew &amp;&amp; brew install heroku</p><ul><li>After you install the CLI, run the heroku login command. You’ll be prompted to enter any key to go to your web browser to complete login. The CLI will then log you in automatically.</li></ul><pre>$ heroku login<br>// =&gt; </pre><pre>heroku: Press any key to open up the browser to login or q to exit<br> ›   Warning: If browser does not open, visit<br> ›   https://cli-auth.heroku.com/auth/browser/***<br>heroku: Waiting for login...<br>Logging in... done<br>Logged in as me@example.com</pre><h4><strong>Rails backend</strong></h4><ul><li>Add the <strong>pg gem</strong></li></ul><p>If you’re using an existing app that was created without specifying --database=postgresql, you need to add the pg gem to your Rails project. Edit your Gemfile and change this line:</p><pre>gem &#39;sqlite3&#39;</pre><p>To this:</p><pre>gem &#39;pg&#39;</pre><p>Now re-install your dependencies (to generate a new Gemfile.lock):</p><pre>$ bundle install</pre><ul><li>Create a <strong>Procfile</strong></li></ul><p>Change the command used to launch your web process by creating a file called <strong>Procfile</strong> in your App root directory</p><p>In file Procfile write:</p><pre>web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}</pre><ul><li>Store your app in Git</li></ul><p>Heroku relies on <a href="http://git-scm.com/">Git</a> for deploying your project. If your project is not already in Git, run these commands in your Rails app directory to initialize and commit your code to Git:</p><pre>$ git init<br>$ git add .<br>$ git commit -m &quot;init&quot;</pre><ul><li>Deploy your application to Heroku</li></ul><p>Make sure you are in the directory that contains your Rails app, then create an app on Heroku:</p><pre>$ heroku create my-app-backend<br>// =&gt;</pre><pre>Creating app... done, my-app-backend<br>https://my-app-backend.herokuapp.com/ | https://git.heroku.com/my-app-backend.git</pre><p>Deploy your code:</p><pre>$ git push heroku master<br>// =&gt;</pre><pre>remote: Compressing source files... done.<br>remote: Building source:<br>...</pre><pre>...<br>remote: Verifying deploy... done.<br>To https://git.heroku.com/my-app-backend.git<br> * [new branch]      master -&gt; master</pre><p>It is always a good idea to check to see if there are any warnings or errors in the output. If everything went well you can migrate your database.</p><ul><li>Migrate your database</li></ul><p>If you are using the database in your application, you need to manually migrate the database by running:</p><pre>$ heroku run rake db:migrate</pre><p>If needed:</p><pre>$ heroku run rake db:seed</pre><p>And this is it. Let’s deploy our frontend.</p><h4><strong>JavaScript frontend</strong></h4><p>Heroku allows web-hosting, but they do not host static websites with HTML, CSS, and JS.</p><p>Initial attempt of trying to do so, I was hit with the following Build Log error:</p><pre>!     No default language could be detected for this app.HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.See <a href="https://devcenter.heroku.com/articles/buildpacks!">https://devcenter.heroku.com/articles/buildpacks!</a>     Push failed</pre><p>What is a buildpack?</p><p>Buildpacks are composed of a set of scripts depending on the <em>programming language</em> used. These scripts are responsible for transforming the deployed code before being executed on the dyno manager. (The scripts gather the dependencies, which then outputs generated code. When pushing to Heroku, the code is received by the slug compiler which transforms the repo into a slug and off to a dyno for execution).</p><p>Listed on the Heroku reference page, the supported buildpacks offered are: Ruby, Node.js, Clojure, Python, Java, Gradle, Grails, Scala, Play, PHP, Go. These buildpacks are searched within the deployed repo based on the specified language used. However, the buildpacks are not offered for the typical HTML, CSS, Javascript languages. This explains the error you received: “no default language could be detected for this app”.</p><p>Don’t worry, it’s an easy fix for your portfolio or personal blog. A small little trick to get Heroku to recognize the files of your static website is to trick it into being a Node.js app.</p><ul><li>First of all don’t forget to change <strong>url</strong> in your <strong>Fetch</strong></li></ul><p>If you were developing on your local environment, you probably were fetching your API data from <a href="http://localhost:3000/">y</a>our localhost. Change all your fetch urls from your localhost (http://localhost:3000/songs) to new Heroku address (https://my-app-backend.herokuapp.com/songs)</p><ul><li>Add package.json file in the root directory.</li></ul><p>Add this code in your package.json file:</p><pre>{<br>  &quot;name&quot;: &quot;project_name&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Project Description&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;serve&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;serve&quot;: &quot;^10.0.1&quot;<br>  },<br>  &quot;author&quot;: &quot;Your Name&quot;<br>}</pre><ul><li><strong>!!! </strong>If you already tried to deploy your project before adding package.json file, you need to create new folder and copy-paste the project there.</li><li>Commit your code to Git:</li></ul><pre>$ git init<br>$ git add .<br>$ git commit -m &quot;heroku workaround&quot;</pre><ul><li>Deploy your frontend to Heroku</li></ul><pre>$ heroku create my-app<br>// =&gt;</pre><pre>Creating app... done, my-app<br>https://my-app.herokuapp.com/ | https://git.heroku.com/my-app.git</pre><p>Deploy your code:</p><pre>$ git push heroku master<br>// =&gt;</pre><pre>remote: Compressing source files... done.<br>remote: Building source:<br>...</pre><pre>...<br>remote: Verifying deploy... done.<br>To https://git.heroku.com/my-app.git<br> * [new branch]      master -&gt; master</pre><p>Boom! Done! Congratulations, you deployed your app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*7V9mm319pYvrluy8av7O5A.gif" /></figure><ul><li><a href="https://www.heroku.com/">Cloud Application Platform | Heroku</a></li><li><a href="https://medium.com/@winnieliang/how-to-run-a-simple-html-css-javascript-application-on-heroku-4e664c541b0b">How to Run a Simple HTML/CSS/Javascript Application on Heroku</a></li><li><a href="https://medium.com/simplejs/deploy-static-files-on-heroku-7e55e01a5df9">Deploy static files (HTML/CSS/JS) on Heroku</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd6e2a047240" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails and Time Zones]]></title>
            <link>https://medium.com/@pavel.beletsky/rails-and-time-zones-3628958ba340?source=rss-cb37cf701f64------2</link>
            <guid isPermaLink="false">https://medium.com/p/3628958ba340</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Pavel Beletsky]]></dc:creator>
            <pubDate>Tue, 03 Dec 2019 17:17:15 GMT</pubDate>
            <atom:updated>2019-12-03T17:17:15.543Z</atom:updated>
            <content:encoded><![CDATA[<p>Rails has embedded tools for working with time zones but there’s a lot of things that can go wrong. Let’s try to figure out how to work with time and time zones.</p><p><strong>Configure Rails App</strong></p><p>Let’s imagine you store your application on some server, but you need your application time zone to be different from a server local time zone. In this case we need to set a config.time_zone configuration in a config/application.rb file. ActiveRecord will help you convert from and to UTC and the time zone of your choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5rcTr0rdDRAHsQ-wlEYhA.png" /></figure><p><strong>Processing Time Information</strong></p><p>What we need to do with the time information before persisting it? Parse it. When parsing time information it’s important to never do it without specifying the time zone. The best way to do this is to use Time.zone.parse (which will use the time zone specified in config.time_zone) instead of just Time.parse (which will use the computer’s/server’s time zone).</p><p>When you retrieve time ActiveRecord fetches the UTC time from the database and converts it to the time zone in config.time_zone for you. Just be sure to never construct the query string by hand and always use Time.current as the base and you should be safe.</p><p><strong>Date vs Time</strong></p><p>Time has date information but Date does NOT have time information. Even if you don’t think you care you might realize that you do sooner then later. Be safe and use Time (or DateTime if you need support for times very far from the present).</p><p>But let’s say you’re stuck with a Date that you need to treat as a Time, at least make sure to convert it to your configured time zone:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jFJffYwdzAhbM4ADXDeGAw.png" /></figure><p>Do not use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*LhIXSGc5u8uPW4AhLZfwCQ.png" /></figure><p><strong>Working With APIs</strong></p><p>When you work with an external API time information can be in different formats and has different time zones. Because Time.zone.parse might not work with the format you receive you might need to use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FQ10hmbJbYJnFp6mxrI7Rg.png" /></figure><p>In this example time_string is a iso8601 formated string. strptime will throw a very unintuitive error complaining on the format argument when in reality the problem is that the time string’s format mismatches the format template argument. in_time_zone defaults to use the Rails configured time zone.</p><p><strong>Examples</strong></p><p>Good</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1mtaGGN0ygltoP5tR_eRww.png" /></figure><p>Bad</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w28nbVMTA7ZAyfaWJGEOww.png" /></figure><p>I hope this information was helpful. Enjoy coding!</p><ul><li><a href="https://www.varvet.com/blog/working-with-time-zones-in-ruby-on-rails/">Working with time zones in Ruby on Rails</a></li><li><a href="http://www.virtuouscode.com/2009/10/25/iso8601-dates-in-ruby/">ISO8601 Dates in Ruby</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3628958ba340" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some hints for the use of TTY::Prompt, TTY::Pie, Catpix in CLI applications.]]></title>
            <link>https://medium.com/@pavel.beletsky/some-hints-for-the-use-of-tty-prompt-tty-pie-catpix-in-cli-applications-fc995dd9510d?source=rss-cb37cf701f64------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc995dd9510d</guid>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[tty]]></category>
            <category><![CDATA[catpix]]></category>
            <dc:creator><![CDATA[Pavel Beletsky]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 17:02:30 GMT</pubDate>
            <atom:updated>2019-11-19T17:02:30.248Z</atom:updated>
            <content:encoded><![CDATA[<p>You are probably not gonna impress experienced developers with your ‘unique, brilliant, outstanding and so on..’ command line application nowadays. But when you just have dived in in this wonderful world of programming three weeks ago, your first CLI application is a first great solid checkpoint on your way. So, let’s add even more shine on ‘your precious’.</p><p>Most likely you used TTY::Prompt gem for menus and user inputs. I would like to share some use case examples on TTY::Prompt, TTY:Pie and Catpix gems.</p><h3><strong>1. Catpix</strong></h3><p><a href="https://github.com/pazdera/catpix?source=post_page-----30769d6912d5----------------------">This gem</a> renders images in the terminal and supports most image formats. Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*QRfz96ai7p3-igQOjF_1IA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*Pg0N46zIqwtxfJVjYvsIjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*BzEwVPksvGnGr1xrRZm-Xg.png" /></figure><p>There is no much to say, everything is pretty easy except installation. If <strong><em>‘gem install catpix’</em></strong> didn’t work out do this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FAi73adiAVpJIqDtXglpPQ.png" /></figure><p>And don’t forget <strong><em>require ‘catpix’</em></strong></p><h3><strong>2. TTY::Prompt</strong></h3><p><strong>2.1 .select</strong></p><p>We’re gonna talk about <a href="https://github.com/piotrmurach/tty-prompt#262-select"><strong><em>‘.select’</em></strong></a> method. For instance, you are building a game and would like to have a menu to select a character and then render its picture. We can do it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fVJWA_1-ctsBNFhv9ykovg.png" /></figure><p>Here is a <em>‘selection’</em> method where we’re creating menu with three choices (Chewbacca, Darth Vader, Yoda). Each choice calls method <em>‘render’</em> and sends file path as an argument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tiq3v40hKcxVw-8js7eAmA.gif" /></figure><p>Great! But what if we are going to add more characters later and we want our app to be flexible? We can grab characters right from a directory (in this case <em>“./pics/”</em>) using <em>‘class Dir’</em> and create menu choices from file names:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWP8tF-_CMU0vHD2EN2GtQ.png" /></figure><p>We are iterating through <em>‘./pics/*’</em>. Variable ‘character’ here is a path to a file, for example <em>‘./pics/Chewbacca.png’</em>, so, for pretty menu choice names we need to ‘<em>delete_prefix’</em> and ‘<em>delete_suffix’</em>. Boom, done!</p><p><strong>2.2 Dynamic menu</strong></p><p>In some cases we’re might gonna need to change one or more menu choices. For example, we would like to be able to buy and sell a character. But we don’t want to define two different menus because <strong>DRY</strong> (Don’t Repeat Yourself!). Then we can implement if..else logic for our menu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vIX9HQUlh8taJrtwX9e43Q.png" /></figure><p>We’re setting <em>‘@own_character’</em> variable to <em>‘false’</em> by default. If it <em>‘false’</em> we’re gonna show menu.choice <em>‘Buy’</em>. When <em>‘Buy’</em> is selected, <em>‘@own_character’ </em>becomes <em>‘true’</em> and we show menu.choice <em>‘Sell’</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtbFsulPo0Fc5-4Q1C9_jg.gif" /></figure><h3><strong>3. TTY::Pie</strong></h3><p>Another useful tool is <a href="https://github.com/piotrmurach/tty-pie"><strong><em>TTY::Pie</em></strong></a>. Let’s add some statistics to our characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eK14CLWfZH3gYkmVMojSrA.png" /></figure><p>Here we’re creating a pie chart and setting dark side/light side balance for each character. Method ‘info’ receives a character argument and renders corresponding pie chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkEcRfESPITHY3lEiwhpvA.gif" /></figure><p>Good luck!</p><ul><li><a href="https://github.com/pazdera/catpix?source=post_page-----30769d6912d5----------------------">pazdera/catpix</a></li><li><a href="https://github.com/piotrmurach/tty-prompt#271-auto_hint">piotrmurach/tty-prompt</a></li><li><a href="https://github.com/piotrmurach/tty-pie">piotrmurach/tty-pie</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc995dd9510d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>