<?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: Pike Msonda</title>
    <description>The latest articles on DEV Community by Pike Msonda (@bloodrave_n).</description>
    <link>https://dev.to/bloodrave_n</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%2F103414%2F455399ae-95d8-4918-a587-3a2c7bc3cce2.jpg</url>
      <title>DEV Community: Pike Msonda</title>
      <link>https://dev.to/bloodrave_n</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bloodrave_n"/>
    <language>en</language>
    <item>
      <title>JS float rounding bug</title>
      <dc:creator>Pike Msonda</dc:creator>
      <pubDate>Fri, 17 Dec 2021 11:32:34 +0000</pubDate>
      <link>https://dev.to/bloodrave_n/js-float-rounding-bug-2631</link>
      <guid>https://dev.to/bloodrave_n/js-float-rounding-bug-2631</guid>
      <description>&lt;p&gt;I have been familiarizing myself with Stripe API. So far so good but today I run into this interesting bug. Stripe gives currency amounts using cents (if you are in the US). Obviously when displaying to the end user you need to convert to proper readable USDs.&lt;/p&gt;

&lt;p&gt;And when you want to updated or make purchases you have to reconvert to cents for the API to accept the request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3380 * 0.01 // converts to $33.8  nothing special here.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When completing a payment or charge in my setup. I convert &lt;strong&gt;$33.8&lt;/strong&gt; dollars back to cents. However when I do so, the resulting amount was not exactly 3338.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;33.8 * 100 = 3379.9999999999995
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because of this Stripe retuned an error. &lt;/p&gt;

&lt;p&gt;My first solution was to use parseInt but that  returned &lt;strong&gt;3379&lt;/strong&gt;. This is unsatisfactory since 1 cent has been lost. &lt;/p&gt;

&lt;p&gt;A more satisfactory solution was to do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;33.8.toString().split('.').reduce((a, b) =&amp;gt; a * 100 + b * 10) // 3380
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another solution would be to round off the float using toFixed like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parseInt(33.8 * 100).toFixed()) // 3380
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Simple python string replace without using in-built function</title>
      <dc:creator>Pike Msonda</dc:creator>
      <pubDate>Fri, 27 Nov 2020 18:14:14 +0000</pubDate>
      <link>https://dev.to/bloodrave_n/python-simple-string-replace-without-using-in-built-function-1jlj</link>
      <guid>https://dev.to/bloodrave_n/python-simple-string-replace-without-using-in-built-function-1jlj</guid>
      <description>&lt;p&gt;A friend asked if I could replicate the python in-built string replace function. &lt;/p&gt;

&lt;p&gt;Not as robust of course but I thought I should give it a try. &lt;/p&gt;

&lt;p&gt;Below is my take. &lt;/p&gt;

&lt;p&gt;Any ideas to improve this are welcome.&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strng&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rplstr&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; 
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;substr&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;strng&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;strng&lt;/span&gt;

    &lt;span class="n"&gt;low_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# get lowest index of substring
&lt;/span&gt;    &lt;span class="n"&gt;high_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;low_index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# evaluate the highest index of substring
&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strng&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="n"&gt;low_index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;rplstr&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;strng&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;high_index&lt;/span&gt;&lt;span class="p"&gt;:],&lt;/span&gt; &lt;span class="n"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rplstr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World Hello World"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"llo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"@@"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;He&lt;/span&gt;&lt;span class="o"&gt;@@&lt;/span&gt; &lt;span class="n"&gt;World&lt;/span&gt; &lt;span class="n"&gt;He&lt;/span&gt;&lt;span class="o"&gt;@@&lt;/span&gt; &lt;span class="n"&gt;World&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>replace</category>
      <category>string</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Extract 20BN-Jester dataset on Windows</title>
      <dc:creator>Pike Msonda</dc:creator>
      <pubDate>Mon, 09 Nov 2020 09:58:38 +0000</pubDate>
      <link>https://dev.to/bloodrave_n/extract-20bn-jester-dataset-on-windows-54kf</link>
      <guid>https://dev.to/bloodrave_n/extract-20bn-jester-dataset-on-windows-54kf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;For those that do not know 20BN-Jester dataset. It is human interaction dataset, it contains humans perfoming a list of &lt;strong&gt;pre-defined gestures&lt;/strong&gt;. Recently has been used for as a benchmark set for different types of Convolutional Neural Networks (CNNs).  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download&lt;br&gt;
You can download the dataset from the official &lt;a href="https://20bn.com/datasets/jester"&gt;website&lt;/a&gt;. Fortunately it is free for academic research. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract&lt;br&gt;
It is fairly easy to extract on unix based operating systems. However, it is not the same when it comes to windows based systems. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After you download you are given a command to use to extract as given below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;cat 20bn-jester-v1-?? tar xf -
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usually this extracts to a point. For some reason it doesn't completely extract the entire dataset. For this, you can exectute this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;cat 20bn-jester-v1-??|gzip -dc|tar xf -
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This solution was posted on &lt;a href="https://stackoverflow.com/questions/55421341/how-to-extract-jester-dataset-files"&gt;Stackoverflow&lt;/a&gt;, check it out.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Note:&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Use a unix based shell like &lt;a href="https://git-scm.com/downloads"&gt;git bash&lt;/a&gt; to be able to run gzip as it is not available by default on Windows. &lt;/p&gt;

</description>
      <category>jester</category>
      <category>tar</category>
      <category>windows</category>
      <category>gzip</category>
    </item>
    <item>
      <title>How to retrieve tokenID from acess_token (Personal Access Token) </title>
      <dc:creator>Pike Msonda</dc:creator>
      <pubDate>Wed, 15 Jan 2020 15:25:19 +0000</pubDate>
      <link>https://dev.to/bloodrave_n/how-to-retrieve-tokenid-from-acesstoken-personal-access-token-hmh</link>
      <guid>https://dev.to/bloodrave_n/how-to-retrieve-tokenid-from-acesstoken-personal-access-token-hmh</guid>
      <description>&lt;h2&gt;
  
  
  The gist
&lt;/h2&gt;

&lt;p&gt;I am assuming you are already aware of how &lt;strong&gt;Laravel/Passport&lt;/strong&gt; works.&lt;/p&gt;

&lt;p&gt;Let's say you have generated a lot of personal access tokens that are associated to a specific user and you would like to delete a specific token without having to delete all the other tokens. &lt;/p&gt;

&lt;p&gt;I am sure you are thinking, I will just get the token associated with the user using the relationship already defined if you use the &lt;strong&gt;HasAPiKeys&lt;/strong&gt; from &lt;strong&gt;Laravel/Passport&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;That is well and good if the user is also serving as a client in your api. But if it is just a Personal Access Token you can't retrieve the access token of created for that user (unless you get it from the header, but that won't really help solve your problem since you still have to know which token matches a particular ID) because of how &lt;strong&gt;Laravel/Passport&lt;/strong&gt; is designed. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/mBjulVQHWumozyk6O2/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/mBjulVQHWumozyk6O2/giphy.gif" alt="What to do? "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To bypass this scenario you can use the following code below.&lt;/p&gt;

&lt;p&gt;Forgive me for using an image instead of embedded code 😅. Let me know below if this helps. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AOZ6WkOz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ow960v83s9zjui89k8yj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AOZ6WkOz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ow960v83s9zjui89k8yj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to  &lt;/p&gt;
&lt;div class="ltag__user ltag__user__id__318088"&gt;
  
    .ltag__user__id__318088 .follow-action-button {
      background-color: #2e0338 !important;
      color: #ffffff !important;
      border-color: #2e0338 !important;
    }
  
    &lt;a href="/mstfakdgn" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IPXD-giT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--9LuSBaSq--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/318088/e58b3435-01c7-40cd-8364-4753cb3caf66.png" alt="mstfakdgn image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/mstfakdgn"&gt;mstfakdgn&lt;/a&gt;
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/mstfakdgn"&gt;Php, Laravel, Docker, Docker-compose, Angular, Ionic mobile, Android, Vue.js, &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I was able to figure it out.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>passport</category>
      <category>oauth2</category>
      <category>php</category>
    </item>
  </channel>
</rss>
