<?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: cbolanos79</title>
    <description>The latest articles on DEV Community by cbolanos79 (@cbolanos79).</description>
    <link>https://dev.to/cbolanos79</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%2F1207212%2F92cd852d-41a4-42b7-912e-8a548ff59c86.png</url>
      <title>DEV Community: cbolanos79</title>
      <link>https://dev.to/cbolanos79</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cbolanos79"/>
    <language>en</language>
    <item>
      <title>Building an android app using AI</title>
      <dc:creator>cbolanos79</dc:creator>
      <pubDate>Mon, 12 Aug 2024 19:06:17 +0000</pubDate>
      <link>https://dev.to/cbolanos79/building-an-android-app-using-ai-5d58</link>
      <guid>https://dev.to/cbolanos79/building-an-android-app-using-ai-5d58</guid>
      <description>&lt;p&gt;In the last times, AI has become more and more present in our daily lifes, may be acting as an assistan to summarize content, creating content for social media, or as a teacher which help in the process of learning a new language. However, technology suffers limitations, therefore, it is not possible to do evertything just using available tools, despiste there is a wide range of possibilites. &lt;br&gt;
Nowadays, nearly everybody has tried any AI tool like ChatGPT or Dalee, tools which are really useful and interesting, althought there is to take into account all them are privative, which means, they are owned by companies with power to decide when and how to share those tools (subscriptions, free usage limits, etc)&lt;br&gt;
So you may asking yourself why am I talking about AI? Because as an old school software developer, I am curious on how can AI improve my performance and save time, specially when learning a new language or framework. Take into account I have nearly no experience developing modern android apps, nevertheless, I took a look into android development some years ago. You know, there has been a big gap since then!&lt;br&gt;
Here we go: the purpose of this post is to share my impressions about creating an android app using the free tier of ChatGPT, requiring the least possible human intervention. I can advance that the results are good enough, at least for building a simple app from scratch in a short period of time.&lt;br&gt;
So, what is the purpose? I need to log the activity of my dog as the vet needs extended information about her walks (it is not an serious illness), hence, it is a good idea to use an app for this purpose, even though I looked for existing apps and most of them looked too complex, or missed the capability of sharing the information, not to talk about using a simple and straight format.&lt;br&gt;
My requirements are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A very simple and straight UI to register activity.&lt;/li&gt;
&lt;li&gt;There are three kinds of activities: piss, poop and walk.&lt;/li&gt;
&lt;li&gt;For the piss I need to register the amount, it is valid to store low, medium and high as values.&lt;/li&gt;
&lt;li&gt;A way to share information with the vet in a straight way, ideally using XLS or CSV format.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Given I would need days or weeks to learn Kotlin and Android development, the time constraint would become a problem, as the information gathered would not be useful, not to talk about spending a lot of resources just to build an unique app, regardless the joy of learning something new.&lt;br&gt;
As a consequence, I tried a different way: what about asking ChatGPT to build an android app feeding the basic requirements? As you may know, using the right prompt is the key for success using LLM AI tools. Let give it a try.&lt;br&gt;
My first prompt was something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create an android app with four buttons that can store information in a database
One button records that the dog has gone for a walk
Another button records that the dog has peed
Another that the dog has pooped
Each action is recorded in the database with the time of creation
The last button shows a list of the activity, with the name of the action and the time
The last button shows a list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I saw the result... I was amazed: ChatGPT created the source code for a working app which displayed four fully functional buttons which worked as expected. Just impressive! Obviously, there was room for improvement, specially in UI, as the structure was very simple, but it worked out of the box.&lt;br&gt;
The more I tried the app, the more improvements I found. As you imagine, I requered ChatGPT to include those improvements. Once more, I was amazed with the results: I got not just a way to do anything new, like adding a view to show the activity log, but the updates to codebase to support them. Furthermore, when I requested a new feature or modification, it took into account the existing changes.&lt;br&gt;
You may be thinking I am really excited about using ChatGPT, but this is not the case: I saved a lot of time, I installed a working app in my mobile phone in less than one hour (it took me sometime to download and setup Android Studio), althought, there were some caveats: there were some aspects which I had not information about, like the new way to request permissions on execution time, or how to create a file. Yes, it would be riskfull if I was developing a production ready application, or working for a customer, however, as this a personal project, I have enough room to experiment and dig in some topics.&lt;/p&gt;

&lt;p&gt;Here are some screenshoots of the last app version:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjp76rlv8tx0xagp1diui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjp76rlv8tx0xagp1diui.png" alt="Image description" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1s44guyden84j7secg92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1s44guyden84j7secg92.png" alt="Image description" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk8kmgq2gumxzqxdkaxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgk8kmgq2gumxzqxdkaxa.png" alt="Image description" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll10xrcn20d5120wr4wt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll10xrcn20d5120wr4wt.png" alt="Image description" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In overall, I consider the AI coverage of app is around 90%, as I just had to modify the initial buttons to use icons, and replace the pee activity suggested by ChatGPT to use a dialog, which I considered more friendly.&lt;br&gt;
Talking about being friendly, under my point of view, this will always be one of the AI caveats: it lacks the capability of interacting with technology like a human. It can not feel the pain of using a bad UI or reject an app because the workflow is complicated, or just because another one is aesthetically pleasant. I firmly belive AI is just a tool, a great tool plenty of knowledge, however, lead by an human.&lt;br&gt;
I would like you all to share your opinnion and experience in comments, specially if you have tried tools like Copilot, and how does it eases your work on daily basis.&lt;/p&gt;

&lt;p&gt;If you are curious, here is the source code of the app:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cbolanos79/dog_activity" rel="noopener noreferrer"&gt;https://github.com/cbolanos79/dog_activity&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Generating a million of different codes</title>
      <dc:creator>cbolanos79</dc:creator>
      <pubDate>Thu, 16 Nov 2023 11:54:02 +0000</pubDate>
      <link>https://dev.to/cbolanos79/generating-a-million-of-different-codes-52fi</link>
      <guid>https://dev.to/cbolanos79/generating-a-million-of-different-codes-52fi</guid>
      <description>&lt;p&gt;Some years ago, a customer requested in my job to generate a million unique codes for a promotion. Each code had to be a sixteen digits alphanumeric value following somes rules like having a number of digits and so on.&lt;br&gt;
It was not a difficult task, but I was impressed when the customer told another company would need 24 hours of processing to generate the codes. 24 hours??? really?&lt;br&gt;
May be the codes were being generated using this algorithm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while count &amp;lt; 1000000
  create a code
  check if code exists by check one by one on a database
  if not exists, store in the data base
  count++
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In that time I could not know how was it done, but seemed  an O^2 algorithm.&lt;br&gt;
While contemplating how to improve the algorithm, an idea occurred to me: what about using a hash? Each code could be stored as a key, and accessing a key in a hash is an O(1) operation (really it depends on handling collisions, which data structure is used, etc).&lt;br&gt;
This idea seemed promising, so I decided to give it a try and  try by writing and implementing this algorithm in python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;values = {}
while count &amp;lt; 1000000
  create a code
  if values[code] not exists
    values[code] = true
  count++
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It took around one minute to generate the million codes, and taking into account it was executed in an old Dell XPS laptop, was not bad at all.&lt;br&gt;
Once codes were generated, a coworker did a test to ensure unicity: he loaded the codes into a database and executed a query like &lt;code&gt;SELECT DISTINCT(code) FROM values&lt;/code&gt;&lt;br&gt;
It just worked: there were a million of different codes.&lt;br&gt;
He looked amazed by the results.&lt;br&gt;
Obviously, there are more details to take into consideration: how to generate an unique code (generate random string libraries), code format, etc, but worked really nice.&lt;br&gt;
As mentioned earlier, I did it some years ago, but my curiosity lead me to try again using different languajes, like Ruby and Rust, and check the execution time for them.&lt;/p&gt;

&lt;p&gt;These are the results using a Ryzen 5 3600 CPU running in Debian:&lt;/p&gt;

&lt;h2&gt;
  
  
  Ruby
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'securerandom'&lt;/span&gt;                                                                                                                                        

&lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;                                                                                                                                                        
&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;                                                                                                                                                     

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1000000&lt;/span&gt;                                                                                                                                         
  &lt;span class="n"&gt;random_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SecureRandom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hex&lt;/span&gt;                                                                                                                            
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;random_string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;                                                                                                                                        
    &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;random_string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;                                                                                                                                      
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;                                                                                                                                                
  &lt;span class="k"&gt;end&lt;/span&gt;                                                                                                                                                         
&lt;span class="k"&gt;end&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;doc@Mimzy:~/tmp/keys &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;time &lt;/span&gt;ruby keys.rb                                                                                                                    

real    0m1,526s                                                                                                                                              
user    0m1,188s                                                                                                                                              
sys     0m0,336s   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rust
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                                                                                                
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;distributions&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;Alphanumeric&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;DistString&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;                                                                                                          

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                                                                                                                                   
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;                                                                                                                             

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                                                                                                                        

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                                                                                                                 
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Alphanumeric&lt;/span&gt;&lt;span class="nf"&gt;.sample_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="nn"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;thread_rng&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                                                                                      
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="nf"&gt;.contains_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                                                                                                    
            &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&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;count&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="p"&gt;}&lt;/span&gt;                                                                                                                                                     
    &lt;span class="p"&gt;}&lt;/span&gt;                                                                                                                                                         
&lt;span class="p"&gt;}&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;doc@Mimzy:~/tmp/keys &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;time&lt;/span&gt; ./target/release/keys                                                                                                           

real    0m0,461s                                                                                                                                              
user    0m0,449s                                                                                                                                              
sys     0m0,012s 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, there is a great improvement, but take into consideration that Rust code is compiled and optimized, while Ruby code is interpreted.&lt;br&gt;
In conclusion: explore new and different ways to solve problems, employing creative thinking in the process.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
