<?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: 'Seun Somefun</title>
    <description>The latest articles on DEV Community by 'Seun Somefun (@danoseun).</description>
    <link>https://dev.to/danoseun</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%2F362099%2Fcb936505-b804-4aca-b9e3-e9978ad68a72.png</url>
      <title>DEV Community: 'Seun Somefun</title>
      <link>https://dev.to/danoseun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/danoseun"/>
    <language>en</language>
    <item>
      <title>Fixing RabbitMQ Startup issues</title>
      <dc:creator>'Seun Somefun</dc:creator>
      <pubDate>Wed, 08 Nov 2023 14:57:57 +0000</pubDate>
      <link>https://dev.to/danoseun/fixing-rabbitmq-startup-issues-3ki8</link>
      <guid>https://dev.to/danoseun/fixing-rabbitmq-startup-issues-3ki8</guid>
      <description>&lt;p&gt;You installed RabbitMQ successfully via homebrew and later you needed to make use of it. Ran &lt;code&gt;brew services list&lt;/code&gt; and discovered that RabbitMQ was no longer running because it had &lt;code&gt;stopped&lt;/code&gt;. You run &lt;code&gt;brew services start RabbitMQ&lt;/code&gt; to bring it back up and you see a log saying:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt; Successfully started `rabbitmq` (label: homebrew.mxcl.rabbitmq)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But when you check &lt;code&gt;brew services list&lt;/code&gt; again you see that it didn't start at all or started and stopped almost immediately.&lt;/p&gt;

&lt;p&gt;Here is how I fixed it:&lt;/p&gt;

&lt;p&gt;1.) &lt;code&gt;brew services stop rabbitmq&lt;/code&gt; to stop RabbitMQ.&lt;/p&gt;

&lt;p&gt;2.) &lt;code&gt;brew uninstall rabbitmq&lt;/code&gt; to uninstall RabbitMQ but after running this there might be some leftover folders that were not deleted while uninstalling RabbitMQ. This will be fixed in step 3.&lt;/p&gt;

&lt;p&gt;3.) Run &lt;code&gt;find / -type d -name "rabbitmq" -print 2&amp;gt;/dev/null&lt;/code&gt;. This will show us paths that have stale RabbitMQ data. The result can look 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;/usr/local/etc/rabbitmq
/usr/local/var/lib/rabbitmq
/usr/local/var/log/rabbitmq
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is the first three lines of the command and the most important part we need from the command. Note that the command may take some time(like 10 minutes) to run to completion.&lt;/p&gt;

&lt;p&gt;4.) Remove the folders found in the paths above (etc, lib, log) by running the commands below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -rf /usr/local/etc/rabbitmq
rm -rf /usr/local/var/lib/rabbitmq
rm -rf /usr/local/var/log/rabbitmq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commands will remove those leftover folders from RabbitMQ as they may hold data from previously installed RabbitMQ which may not allow the RabbitMQ that will be installed in step 6 to work properly.&lt;/p&gt;

&lt;p&gt;5.) Next, update homebrew by running &lt;code&gt;brew update&lt;/code&gt; and if any error as &lt;code&gt;fatal: couldn't find remote ref refs/heads/master&lt;/code&gt; is encountered, running &lt;code&gt;brew tap --repair&lt;/code&gt; should fix the problem.&lt;/p&gt;

&lt;p&gt;6.) Install RabbitMQ by running &lt;code&gt;brew install rabbitmq&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;7.) Lastly, start RabbitMQ by running &lt;code&gt;brew services start rabbitmq&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;8.) Run &lt;code&gt;brew services list&lt;/code&gt; and RabbitMQ should be started now(green).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rabbitmq       started &amp;lt;user&amp;gt; ~/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may choose to run this command over and over again to be sure RabbitMQ is up like I did.&lt;/p&gt;

&lt;p&gt;In fact, another way to confirm it's working is you can (like I also did) visit &lt;a href="http://localhost:15672"&gt;RabbitMQ localhost&lt;/a&gt; and login using &lt;code&gt;guest&lt;/code&gt; as both email and password to interact with the RabbitMQ GUI.&lt;/p&gt;

&lt;p&gt;If step 7 throws an error, you can do &lt;code&gt;brew services restart rabbitmq&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note that these are the exact steps I took to fix the errors I had(on MacOS Intel Corei7 Ventura 13.5.1) and this might differ for others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@anjantalatatam/how-to-clean-install-rabbitmq-1ae214436b7d"&gt;Reference here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rabbitmq</category>
      <category>installation</category>
    </item>
    <item>
      <title>ORGANIZING STRUCTURES IN RUBY</title>
      <dc:creator>'Seun Somefun</dc:creator>
      <pubDate>Mon, 30 Oct 2023 01:02:48 +0000</pubDate>
      <link>https://dev.to/danoseun/organizing-structures-in-ruby-3ni7</link>
      <guid>https://dev.to/danoseun/organizing-structures-in-ruby-3ni7</guid>
      <description>&lt;p&gt;In ruby, there are two fundamental concepts for organizing methods: &lt;strong&gt;classes&lt;/strong&gt; and &lt;strong&gt;modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;class&lt;/strong&gt; is a blueprint or template for building objects. Classes have properties or attributes that are unique to the class while methods determine actions that can be carried out on the class, especially via manipulating the properties.&lt;/p&gt;

&lt;p&gt;For example, we can decide to model a human class. Humans normally have legs, hands, a name, and other properties and they can say their names. Let's quickly wire that up&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Human
    def initialize(no_of_hands, no_of_legs, name)
        @no_of_hands = no_of_hands
        @no_of_legs = no_of_legs
        @name = name
    end

    def name
        "Hi there, my name is #{@name}"
    end

    def name=(new_name)
        @name = new_name
    end
end

lm = Human.new(2, 4, 'lege miami')
puts lm.name  # Hi there, my name is lege miami
lm.name = 'bugs bunny'   
puts lm.name   # Hi there, my name is bugs bunny

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

&lt;/div&gt;



&lt;p&gt;From the above code block, we defined a class or blueprint as we mentioned earlier called &lt;code&gt;Human&lt;/code&gt; with three instance properties and two instance methods, one being a &lt;code&gt;getter&lt;/code&gt; and the other being a &lt;code&gt;setter&lt;/code&gt;. The class is further instantiated with the initialized properties and then an action is carried out on the next line which prints the instance name as "lege miami". We further set the instance name to a new name via the setter method and when we log it, we see that the new name changes to "bugs bunny"&lt;/p&gt;

&lt;p&gt;Imagine that we had about six instance properties, we would have to create a getter and setter method(if we intend to change them) for each and that will be twelve methods altogether. Thankfully Ruby has a shortcut called &lt;code&gt;attr_accessor&lt;/code&gt; which essentially helps you have a getter and setter in one piece. See the refactored code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Human
    attr_accessor :no_of_hands, :no_of_legs, :name
    def initialize(no_of_hands, no_of_legs, name)
        @no_of_hands = no_of_hands
        @no_of_legs = no_of_legs
        @name = "Hi there, my name is #{name}"
    end
end

lm = Human.new(2, 4, 'lege miami')
puts lm.name  # Hi there, my name is lege miami
lm.name = 'bugs bunny'   
puts "Hi there, my name #{lm.name}"   # Hi there, my name is bugs bunny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we don't have to define a specific getter and setter method as attr_accessor has taken care of that. There are also &lt;code&gt;attr_reader&lt;/code&gt; which creates only the reader and &lt;code&gt;attr_writer&lt;/code&gt; which creates only the writer. Methods are &lt;code&gt;public&lt;/code&gt; by default but they can also be made &lt;code&gt;private&lt;/code&gt; or &lt;code&gt;protected&lt;/code&gt; depending on the use case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modules&lt;/strong&gt; in Ruby provide a way to organize code that allows for more flexibility than through a standard class. Including a module in a class allows that class use of the code within the module. The effect of this is similar to a child-class inheriting code from a parent-class.&lt;/p&gt;

&lt;p&gt;Modules serve two purposes. First, they act as a namespace, letting you define methods whose names won’t clash with those defined elsewhere. Second, they allow you to share functionality among classes. If a class mixes in a module, that module’s methods become available as if they’d been defined in the class. Multiple classes can mix in the same module, sharing the module’s functionality without using inheritance. You can also mix multiple modules into a single class.&lt;/p&gt;

&lt;p&gt;Let's look at how to use a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module  RandomHelper
    def capitalize_words(string)
        string.split(' ').map {|word| word.capitalize}.join(' ')
    end
end


class Questioner
include RandomHelper
    def capitalize(string)
        RandomHelper::capitalize_words(string)
    end
end

question = Questioner.new
puts question.capitalize_words('is software engineering rewarding?')  # Is Software Engineering Rewarding?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have defined a module &lt;code&gt;RandomHelper&lt;/code&gt; because we are lazy with naming(you should not be in real life) and put in it a method &lt;code&gt;capitalize_words&lt;/code&gt; which turns the first letter of every word in the sentence passed into it into a capital letter and then we &lt;code&gt;include&lt;/code&gt; it in a class so it can be used. This class &lt;code&gt;Questioner&lt;/code&gt;(because naming is hard) is then instantiated before the instance calls the method in the module.&lt;/p&gt;

&lt;p&gt;These organizing structures are largely used in Ruby on Rails with different flavors.&lt;/p&gt;

&lt;p&gt;For further reading and possibilities;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@lucaspenzeymoog/uses-for-modules-in-ruby-mixins-and-namespaces-efab56575d84"&gt;medium article&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ruby-lang.org/en/documentation/faq/8/#:~:text=What%20is%20the%20difference%20between%20a%20class%20and%20a%20module,instance%20state%20(instance%20variables)."&gt;ruby lang docs&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HOW TO SOLVE THE NO VALID EXPORTS ERROR IN NODEJS.</title>
      <dc:creator>'Seun Somefun</dc:creator>
      <pubDate>Sat, 29 Aug 2020 13:17:11 +0000</pubDate>
      <link>https://dev.to/danoseun/how-to-solve-the-no-valid-exports-error-in-nodejs-31no</link>
      <guid>https://dev.to/danoseun/how-to-solve-the-no-valid-exports-error-in-nodejs-31no</guid>
      <description>&lt;p&gt;Recently while running the &lt;code&gt;sequelize-cli init&lt;/code&gt; command, I ran into an error. The error message was something like &lt;code&gt;export not found...&lt;/code&gt;. I began to debug and even started placing console.log statements in the .sequelizerc file(lol). I had to open up several other projects I had done with sequelize to see if I was missing something, then checked the sequelize-cli docs if something had changed and everywhere but I still couldn't solve the problem. Funny enough the app was running with(npm run start:dev) so it got me more confused.&lt;/p&gt;

&lt;p&gt;It happened again within the same week when I was trying to set up a nestjs project and this time around the same error was pointing to a file in the node_modules folder. The curiosity in me drove me to comment out some lines in the file it was pointing to but the error stayed the same and previous searches yielded nothing helpful till I stumbled upon something that talked about node versions. The problem according to &lt;a href="https://github.com/strongloop/loopback-next/issues/5381"&gt;this&lt;/a&gt; issue is that node odd versions seem to be broken so incase you stumble upon such a weird issue, here is how I solved it.&lt;/p&gt;

&lt;p&gt;Solution&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Download nvm(node version manager). It helps to manage node versions locally and you can switch between various node LTS(Long Term Support) versions using nvm.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then install a node version(&lt;code&gt;nvm install &amp;lt;version number&amp;gt;&lt;/code&gt;) with an even number(v13.14/v14). Most likely, you would currently have an odd number node version(v9.7/v11.15/v13.9) if you check with node -v.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch to the new version you just installed with &lt;code&gt;nvm use &amp;lt;version number&amp;gt;&lt;/code&gt; e.g nvm use 10. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the project on VSCode and reopen it again then run the command you were trying to run initially and it should work without errors now. If you check the node version now, you will see it's the newly installed version you are currently running on. If you still have any issues, you could delete the node_modules and package-lock.json then run npm install again.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This &lt;a href="https://itnext.io/nvm-the-easiest-way-to-switch-node-js-environments-on-your-machine-in-a-flash-17babb7d5f1b"&gt;article&lt;/a&gt; talks about nvm in more detail.&lt;/p&gt;

&lt;p&gt;Thanks for coming to my Ted Talk.&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>nestjs</category>
      <category>typescript</category>
    </item>
    <item>
      <title>HOW TO EDIT AN EXISTING MODEL IN SEQUELIZE ORM.</title>
      <dc:creator>'Seun Somefun</dc:creator>
      <pubDate>Thu, 09 Apr 2020 23:01:26 +0000</pubDate>
      <link>https://dev.to/danoseun/how-to-edit-existing-model-in-sequelize-orm-4jie</link>
      <guid>https://dev.to/danoseun/how-to-edit-existing-model-in-sequelize-orm-4jie</guid>
      <description>&lt;p&gt;Imagine you were working with Sequelize and after setting up the database and models you ran the command to migrate and everything worked well. You checked the database(local) via psql(or any other client of choice) and saw that everything was intact. You were happy with yourself but suddenly you realized that you forgot to add a column to that model, you quickly made some changes to the migration file, ran the migration command again but nothing happened. You became downcast and you were thinking of recreating the models and migrating them again but you decided to check google to see if there was a way to salvage the situation and suddenly you stumbled upon this article. You just struck gold!&lt;br&gt;
The technologies to be used are Javascript(ES6), expressjs and Sequelize ORM.&lt;/p&gt;

&lt;p&gt;I will assume you already created a database and you just want to make the necessary changes to the table(s). However, you can follow along for learning purposes.&lt;/p&gt;

&lt;p&gt;Now create a folder called sequelize-migrations or whatever you want to call it and go into it like so.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir sequelize-migrations &amp;amp;&amp;amp; cd sequelize-migrations&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Go &lt;a href="https://github.com/danoseun/sequelize-migrations"&gt;here&lt;/a&gt; and npm install the packages in package.json then do the following.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the following files &lt;strong&gt;.babelrc&lt;/strong&gt; and &lt;strong&gt;.sequelizerc&lt;/strong&gt; and add the contents of the respective files of the above repository into your code.&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;npx sequelize-cli init&lt;/strong&gt; command. It will create the folders specified in &lt;em&gt;.sequelizerc&lt;/em&gt; file.&lt;/li&gt;
&lt;li&gt;Replace the default content of &lt;em&gt;database/config/config.js&lt;/em&gt; with the version of what is in the above repository.&lt;/li&gt;
&lt;li&gt;Do same for &lt;em&gt;database/models/index.js&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Create a database(local) and put the database url in a &lt;em&gt;.env&lt;/em&gt; file.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Enter this command to create the model
&lt;/h5&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npx sequelize-cli model:generate --name User --attributes name:string,email:string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
  
  
  Enter this command to migrate the models into the created database
&lt;/h5&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npx sequelize-cli db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;According to the sequelize docs, it is only when you run the above command that you create the table specified in the models folder meaning that the database/table has been empty all along.&lt;/p&gt;

&lt;p&gt;Everything worked well and suddenly you remembered that you forgot to add &lt;em&gt;username&lt;/em&gt; and &lt;em&gt;date_of_birth&lt;/em&gt; columns and you would also like to remove &lt;em&gt;email&lt;/em&gt;. You made some changes to the migration/model file and ran the migration command again but you saw &lt;br&gt;
&lt;strong&gt;No migrations were executed, database schema was already up to date&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One thing worthy of note from the &lt;a href="https://sequelize.org/v5/manual/migrations.html"&gt;sequelize docs&lt;/a&gt; is that migrations help sequelize to keep track of changes to the database as it is written&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;...with migrations you can transfer your existing database into another state and vice versa...&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This means the previously generated migration file has done its job and now you have to create another.&lt;/p&gt;

&lt;h3&gt;
  
  
  SOLUTION
&lt;/h3&gt;

&lt;h6&gt;
  
  
  Enter the following command into your terminal
&lt;/h6&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npx sequelize-cli migration:create --name create-users-two
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I chose file name as &lt;em&gt;create-users-two&lt;/em&gt; so feel free to choose yours.&lt;/p&gt;

&lt;h6&gt;
  
  
  Open the new migration file generated and add the code below:
&lt;/h6&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   'use strict';

    module.exports = {
      up: (queryInterface, Sequelize) =&amp;gt; {
    /*
      Add altering commands here.
     Return a promise to correctly handle asynchronicity.

     Example:
      return queryInterface.createTable('users', { id: 
      Sequelize.INTEGER });
    */
     return Promise.all([queryInterface.addColumn(
     'Users',
     'username',
      Sequelize.STRING
      ),
     queryInterface.addColumn(
     'Users',
     'date_of_birth',
     Sequelize.DATE
     ),
     queryInterface.removeColumn(
     'Users',
     'email',
      Sequelize.STRING
       )
     ]);
   },

  down: (queryInterface, Sequelize) =&amp;gt; {
   /*
     Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

       Example:
        return queryInterface.dropTable('users');
    */
  return queryInterface.dropTable('Users');
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;em&gt;up&lt;/em&gt; function will run when we run the migration command.&lt;/li&gt;
&lt;li&gt;Inside the &lt;em&gt;addColumn&lt;/em&gt; function there are three arguments: tablename,
column to be added and datatype.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;removeColumn&lt;/em&gt; function also takes in same arguments to remove a column.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;down&lt;/em&gt; function signifies what should happen when you undo migration.&lt;/li&gt;
&lt;li&gt;Sequelize migrations by default expects a promise to be returned. In order to avoid unwanted behaviour and so as to achieve the default behaviour, we have wrapped everything in a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all"&gt;&lt;code&gt;Promise.all&lt;/code&gt;&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now re-run the migration command &lt;strong&gt;npx sequelize-cli db:migrate&lt;/strong&gt; and check your local database for confirmation. If all went well, you just solved the problem you had. If you want to make another change to the table, you will have to create another migration file and specify what you want in the &lt;em&gt;up&lt;/em&gt; and &lt;em&gt;down&lt;/em&gt; functions. You can also read more about &lt;a href="https://sequelize.org/master/class/lib/query-interface.js~QueryInterface.html"&gt;sequelize query interface&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I know you are happy. Thanks for coming to my Ted Talks! &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
