<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vlad Nedelcu</title>
    <description>The latest articles on DEV Community by Vlad Nedelcu (@vladned).</description>
    <link>https://dev.to/vladned</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F259751%2F67dd091b-af15-436c-bcab-31672076e662.jpeg</url>
      <title>DEV Community: Vlad Nedelcu</title>
      <link>https://dev.to/vladned</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vladned"/>
    <language>en</language>
    <item>
      <title>Calculating the number of seconds until midnight</title>
      <dc:creator>Vlad Nedelcu</dc:creator>
      <pubDate>Wed, 20 Jan 2021 13:03:25 +0000</pubDate>
      <link>https://dev.to/vladned/calculating-the-number-of-seconds-until-midnight-383d</link>
      <guid>https://dev.to/vladned/calculating-the-number-of-seconds-until-midnight-383d</guid>
      <description>&lt;p&gt;I know this might be very straight forward for some developers but I found this a pretty intriguing and fun quick problem to solve, it also might help some beginners furthermore. &lt;/p&gt;

&lt;p&gt;How can you find the number of seconds until midnight ?....with python...in an elegant way.&lt;/p&gt;

&lt;p&gt;My first approach to this was to subtract from the 24 hours the number of hours that passed today, and so multiply with 60 to get the number of seconds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;

&lt;span class="n"&gt;number_of_seconds_until_midnight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The pros of this formula is that is fast, but it lack the readability of python coding. By using &lt;code&gt;datetime&lt;/code&gt; package from python you can increase the readability and the code follows as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;midnight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;combine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;seconds_until_midnight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;midnight&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;midnight&lt;/code&gt; is calculated by combining tomorrow date with time, which will strip the time to 00:00.&lt;br&gt;
&lt;code&gt;seconds_until_midnight&lt;/code&gt; subtract from midnight &lt;code&gt;datetime&lt;/code&gt; the now &lt;code&gt;datetime&lt;/code&gt; to get the time-frame between these two.&lt;/p&gt;

&lt;p&gt;You can also add all this to a method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seconds_until_midnight&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="s"&gt;'''Calculate seconds until midnight'''&lt;/span&gt;
   &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
   &lt;span class="n"&gt;midnight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;combine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;midnight&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Where to store users number of tries ?</title>
      <dc:creator>Vlad Nedelcu</dc:creator>
      <pubDate>Mon, 11 Jan 2021 08:37:22 +0000</pubDate>
      <link>https://dev.to/vladned/where-to-store-users-number-of-tries-4nf</link>
      <guid>https://dev.to/vladned/where-to-store-users-number-of-tries-4nf</guid>
      <description>&lt;p&gt;Hi guys, I am looking on some alternatives on were to store apps users consumable actions. For example, number of tries of doing something in the app per day.&lt;/p&gt;

&lt;p&gt;Should I go ahead an store everything in a db table ? &lt;br&gt;
How will this affect the performance if the number of users rise ?&lt;/p&gt;

&lt;p&gt;And last but not least, this has to reset at the end of the day.&lt;/p&gt;

&lt;p&gt;[UPDATE] I found an easy way to handle this by storing the dynamic data in the cache ..can be redis.. with a TTL set to it. The max or min for the counter is stored in the DB.&lt;/p&gt;

&lt;p&gt;This way you can store counters/values that are consumable by the user and have it reset without a background job.&lt;/p&gt;

</description>
      <category>python</category>
      <category>django</category>
      <category>database</category>
      <category>programming</category>
    </item>
    <item>
      <title>Do you feel like time is going faster ?</title>
      <dc:creator>Vlad Nedelcu</dc:creator>
      <pubDate>Wed, 02 Dec 2020 12:52:51 +0000</pubDate>
      <link>https://dev.to/vladned/do-you-feel-like-time-is-going-faster-361a</link>
      <guid>https://dev.to/vladned/do-you-feel-like-time-is-going-faster-361a</guid>
      <description>&lt;p&gt;Lately I found myself working at my job during the day and leave my personal projects, learning and other coding stuff in the early morning or in the evening.&lt;/p&gt;

&lt;p&gt;One thing that happened is that I feel like the amount of work that I do while learning, customizing my career plan and doing side projects is less during this lockdown period. During my early years in software development career I would finish up work much faster and find interesting ideas.&lt;/p&gt;

&lt;p&gt;Do you feel the same ? &lt;/p&gt;

&lt;p&gt;If you do I would like to see some opinions about this or some good reads about this phenomenon as I want to tackle this problem.&lt;/p&gt;

</description>
      <category>mentalhealth</category>
      <category>productivity</category>
      <category>career</category>
    </item>
  </channel>
</rss>
