<?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 Mohamed Aziz Laouiti on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Aziz Laouiti on Medium]]></description>
        <link>https://medium.com/@mohamed-aziz-laouiti?source=rss-4ec967c40841------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w2knCQ8G0voFJQVzuAe3YA.png</url>
            <title>Stories by Mohamed Aziz Laouiti on Medium</title>
            <link>https://medium.com/@mohamed-aziz-laouiti?source=rss-4ec967c40841------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:55:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohamed-aziz-laouiti/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[Learn TypeScript the easy way ♛ part 1]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/learn-typescript-the-easy-way-part-1-483da8cb485d?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/483da8cb485d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 23:42:43 GMT</pubDate>
            <atom:updated>2022-01-06T22:28:19.406Z</atom:updated>
            <content:encoded><![CDATA[<h3>Amazing TypeScript introductory ♛ part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4uecqZ0viu-aC6VL2YWEmg.png" /></figure><blockquote>if you’ve been using javascript for a while there is a good chance that you saw something similar to this error . I’m sure you’ve encountered this frustrating runtime TypeError (<em>or what i like to call it the </em><em>undefined dilemma</em>) → this is a result of trying to call a property from a variable that has been declared but has not yet been assigned a value. or trying to access something that doesn’t exit in the first place.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TRspiZzhB6ALfaL-5MOFQ.png" /></figure><p>This first part will serve as an introduction to typeScript to get you familiar with different defintion and terms .This is crucial for you to understand before we dive into coding …</p><h4>Why TypeScript ?</h4><p>TypeScript is a superset of javascript → meaning it is built on top of javascript The goal of TypeScript is to help catch mistakes early through a type system and to make JavaScript development more efficient.</p><p>“TypScript is just JavaScript with typeChecking ”</p><h4>1.Typescript vs Javascript comparison :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*yk22yKM5qIoVlrcJ-T0P4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*t1Oyupcg_TkQA-iWgL-iTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*M-MjFCulRww5M-0vHizJow.png" /></figure><ul><li>The idea behind <strong>type-safety</strong> is to make sure that your code can be statically analyzed and built, before running it. That way your can detect potential bugs before they happen in runtime.</li><li>This is where <strong>TypeScript</strong> comes to the rescue by providing <strong>Type Check</strong> for your code which will prevents us from introducing unwanted behavior in our code, like that infamous TypeError</li></ul><blockquote>If you are trying to integrate TypeScript in your code , you probably aim to get the most out of the TypeScript type-system, that means, that your preference should be to have typed variables all across your application.</blockquote><blockquote>It starts with the code you write — UI components, services and business logic. You can also have type safety for your third-party libraries</blockquote><p>→If this seems like something to consider having in your code than learning Typescript is the way to go …</p><h4>2.TypeScript types :</h4><p>similar to javaScript , TypeScript also has its own types :</p><h4>2.1 basic Types :</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*O7tzmtqLdLbR7pK7UUl2Zg.png" /></figure><h4>2.2 Any type :</h4><p>The any type is useful when you don’t want to write out a long type just to convince TypeScript that a particular line of code is okay.<br>❌ “by using the any Type you’re telling typeScript to skip type checking and let you handle the variable yourself, this may come with a lot of flexibilty but at the cost of being more error-prone”<br>❌ In TypeScript, any type can be classified with the anyType.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*zLX0mJy7pIrjrjPnaecVSg.png" /></figure><p>anyType is essentially an escape capsule of the type system. As a developer, this gives us a lot of freedom: TypeScript allows us to anyvalue types do anything, without first performing any form of censorship. for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*35kVHDnCg0sbDDOSjgYofw.png" /></figure><p>In many scenarios, this is <strong>too loose</strong> .If you use anytype, you’re waiving away a lot of protection mechanisms that TypeScript provided. In order to solve this anyproblems , <strong>TypeScript 3.0</strong> introduced the <strong>unknown</strong>types.</p><h4>2.3 Unknown type :</h4><p>Just as all types can be assigned to any, so can all types be assigned unknown. This makes unknown another type that’s a top type system (same as any).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*EExulKqfh4w91sR13s4dfg.png" /></figure><p>For valueall variable assignments are considered to be valid. But when we Try to assign value type to other variables with different types we get some errors …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*JtyjEHTp1JNttiXoWoTBZA.png" /></figure><p>unknownType can only be assigned to anytype or to unknowntype itself. Intuitively, this makes sense: you’re only able to save any type of container value to unknownvalue types and vise-versa since we do not know the variables valueare stored in what type of value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*qMKj4Z8CCr9bt2vXCpnpiA.png" /></figure><p>as you can see The difference between unknown and any is that unknown is much less permissive than any: we have to do some form of checking before performing most operations on values of type unknown, whereas we don&#39;t have to do any checks before performing operations on values of type any.</p><h4>conculsion :</h4><p>this is still a work in progress // if you like this so far please feel free to leave a comment or leave a clap! 👏👏👏.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=483da8cb485d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating your work using Github web scraper]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/automating-your-work-using-github-web-scraper-56685bbb2f37?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/56685bbb2f37</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[scraping]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 22:04:59 GMT</pubDate>
            <atom:updated>2021-12-15T14:44:19.314Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWFkh5z8oa6dZfn5_gkKKQ.jpeg" /></figure><h3>The Development Process</h3><p>before you dive into reading ask yourself this question →</p><blockquote>“After you finish your portfolio, do you keep it updated even though you have a fulltime job? Or do you forget about it and only update when job searching again? , how often do you update it ”</blockquote><p>Based on my own experience , it seems obvious why it’s important to keep your portfolio updated. But at the same time, I know how easy it is to put off when you have the security and comfort of a full-time job. Here is why it’s worth spending the time to keep your portfolio fresh, even if you don’t plan on job hunting anytime soon.</p><ul><li><strong>it shows that you care about your work<em> </em></strong>: A portfolio gives you an identity outside of your team at work. It says that you care enough to refine your skills .</li><li><strong>Keeping your portfolio current with your latest work:</strong> this is an easy passive way to keep your options and opportunities open.</li><li><strong>A recruiter or a client may land on your page</strong>, see it’s outdated and move on. All without you ever knowing you were on their radar.</li></ul><h4><strong>solutions you may consider?</strong></h4><ul><li>Set a Schedule for Updating Your Work Portfolio</li><li>Searching for an eloquent solutions to manualy update your portfolio → this is where presenting some form of automation come in handy</li><li>Coding a scraper to update your portfolio for you</li></ul><h3>How Do Web Scrapers Work?</h3><p>Quite often, scraping refers to a web client that parses the HTML pages of targeted website to extract formatted data. This is done when a website does not offer an API end-point for accessing the data in a programmatic way.</p><p>Web scraping is an automated process of extracting data from targeted websites</p><blockquote>“You have an HTML page that contains some data you want. What you do is you write a program that will fetch that web page and attempt to extract that data.”</blockquote><h4><strong>Building a javascrpit scraper</strong></h4><p>JavaScript is a fexible language to use for a web scraper all thanks to Node.js you’ll likely end up using a lot of the same methods you’re used to from querying the DOM with vanilla JavaScript.</p><p>In this article, I’ll try and walk you through a powerful way to use JavaScript to build a web scraper. We’ll also explore other web scraping concepts and various alternatives to build a performant scraping tool , so for the sake of this post we will build a <strong>web scraper for Github</strong> .</p><p>you don’t have to follow every step i mention but i advice you to understand the concept that way you can build something of your own .</p><h4><strong>Choosing an html parser / scraping library :</strong></h4><p>for this article i’m using <a href="https://www.npmjs.com/package/cheerio">cheerio</a> but feel free to use other libraries that you’re most comfortable with .</p><p>→ Cheerio parses markup and provides an API for traversing/manipulating the resulting data structure this makes our job a lot more easier to deal with, cheerio uses <strong>jQuery</strong> dependency if you’re not familiar with it don’t worry i’m going to walk you throught everything that needs to be explained .</p><h4>fetching data :</h4><p>fetching data is a core concept that clients(in our case browser) use →we’re just calling the server using a specific url →the server then sends the data back in a form of a Promise which when resolved will generate a data in some desired format . “<em>this is really what happens when you open a web page , so keep this in mind .”</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efa06a56ba7a7c7e645f65eced79743c/href">https://medium.com/media/efa06a56ba7a7c7e645f65eced79743c/href</a></iframe><p>we’re using <a href="https://www.npmjs.com/package/axios">axios</a> to make a request to the github page → this will return a promise which when resolved will give us some data along with a key of {data} → this will be our desired html that we’re going to anaylse using cheerio</p><p>// this post is still under production…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56685bbb2f37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hiding your environment dev Key for Rails/react in less than 2 minutes]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/hiding-your-environment-dev-key-for-rails-react-in-less-than-2-minutes-145e5901d09a?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/145e5901d09a</guid>
            <category><![CDATA[rails-6]]></category>
            <category><![CDATA[jwt-auth]]></category>
            <category><![CDATA[api-key]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Thu, 04 Nov 2021 18:45:45 GMT</pubDate>
            <atom:updated>2021-11-04T21:50:41.881Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e4fgQD293ccW023s1QVRRg.jpeg" /></figure><p>I was recently working on a project that required user authentication(<a href="https://jwt.io/">JWT</a> token) , if you’re curious about that , i went over the details <a href="https://medium.com/@mohamed-aziz-laouiti/action-cable-with-react-and-rails-api-c47ac2772eea"><strong>here</strong></a> , after a bit of research i found out about <a href="https://en.wikipedia.org/wiki/Environment_variable">environment variables</a> (<strong><em>ENV </em></strong><em>Variables</em>).</p><h4>what are environment variables?</h4><blockquote>The primary use case for environment variables is to limit the need to modify and re-release an application due to changes in configuration data meaning that →by using the <strong><em>environment variables</em></strong> you set some global values at build time, that way you can access these values in your application at runtime…Cool right?</blockquote><p>The project that i worked on is a <a href="https://api.rubyonrails.org/"><strong>rails API</strong></a> with a <a href="https://reactjs.org/"><strong>react</strong></a> frontEnd , so call yourself lucky since we’re going to be “<strong>Feeding two birds with one scone”</strong> as i will go over how to set up your <strong>ENV variables</strong> in both frameWorks.</p><h4>setting ENV variables in rails →</h4><p>for rails side we’re going to be using a gem called <a href="https://github.com/bkeepers/dotenv">dotenv</a> → (super simple to implement and use) , so in your command console run :</p><blockquote>bundle add dotenv-railsthen bundle install</blockquote><p>this will create a .env file in the root directory , if this wasn’t the case , add a .env file in your root manualy .</p><p>now head over to →your_root_directory/config/application.rb</p><p>in your application.rb add Dotenv::Railtie.load , your file should be somewhat similar to the code below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/767192bee6970af048a2c8c53a862f09/href">https://medium.com/media/767192bee6970af048a2c8c53a862f09/href</a></iframe><p>now go back to your .env file and add your keys like for example</p><blockquote>export JWT_KEY = eyJhbGciOiJIUzI1NiIsIn</blockquote><p>now just to make sure open your rails console rails c → type in ENV[&quot;JWT_KEY&quot;] and voila !! you now can access your env variables .</p><blockquote>one other thing to note , you should add your .env to .gitignore file , that way git won’t track and it won’t get uploaded to GitHub .</blockquote><h4>setting ENV variables in react →</h4><p>The process of setting our environment variables in react is somewhat similar → run yarn add react-dotenv you can find more about dotenv <a href="https://www.npmjs.com/package/react-dotenv"><strong>here</strong></a></p><p>Now we need to create a file .env file in the root folder of our react app , then we can define our environment variables inside it , like for example: REACT_APP_BASE_URL = &quot;http://localhost:3001&quot;</p><p>→Accessing Environment Variables : what i like to do is create a file named (root or globals if you want )that way i can import those keys without the need to call process.env.YOUR_VAR_KEY everytime .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a26f8074ef8dc3bc055df5f95d6eec9/href">https://medium.com/media/1a26f8074ef8dc3bc055df5f95d6eec9/href</a></iframe><p>And voila!! don’t forget to refresh you server…</p><p>you now have access to your env variables. you can thank me later …</p><blockquote>again , you should add your <em>.env</em> to <em>.gitignore</em> file , that way git won’t track and it won’t get uploaded to GitHub .</blockquote><h4>environment variables UNDER the Hood →</h4><p>At runtime the code loads the .env it needs (using<em> dotenv</em>) from the appropriate directory. env variables are often used to avoid storing secret credentials in a potentially public codebase. for more info consider checking the resources i listed:</p><ul><li><a href="https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used">What other </a><a href="https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used">.env files can be used?</a></li><li><a href="https://stackoverflow.com/questions/48699820/how-do-i-hide-api-key-in-create-react-app">when to use </a><a href="https://stackoverflow.com/questions/48699820/how-do-i-hide-api-key-in-create-react-app">.env variables</a></li></ul><h4>conclusion</h4><p>hopefully you’ve learned enough to be able to use ENV variables . if there is any questions you have , please feel free to leave a comment or leave a clap! 👏👏👏.</p><p>As always, thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=145e5901d09a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Action Cable With React and Rails API]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/action-cable-with-react-and-rails-api-c47ac2772eea?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/c47ac2772eea</guid>
            <category><![CDATA[rails-api]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[actioncable]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 17:49:35 GMT</pubDate>
            <atom:updated>2021-11-04T19:01:55.770Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*HaoczSW1nMneRR3PnAzzgg.png" /></figure><p>This post is meant to showcase a project that I recently wrapped up. A multiplayer drawing and guessing game with a React front-end and a Rails API back-end using <strong>WebSockets</strong> : a transfer protocol for making real-time exchange of data between different users,The finished code for this tutorial is available <a href="https://github.com/AZIZXlaouiti/action_cable_api"><strong>here</strong></a> and <a href="https://github.com/AZIZXlaouiti/actioncable-app-frontend"><strong>here</strong></a></p><h3>The Development Process</h3><p>When I sought out to create this project, I immediately went to google to look for answers and shortly enough i found out about ActionCable (rails’ way of implementing WebSockets) that’s when i fell into a rabbit hole so to speak…</p><p>The documentation for <a href="https://guides.rubyonrails.org/action_cable_overview.html"><strong>Action Cable</strong></a>, like most Rails documentation, is pretty thorough. assuming that you’re using Rails as a full-stack framework. If you plan on combining a Rails backend <strong>API</strong> with a separate frontend framework(in our case react ), the resources on how to incorporate ActionCable are scarce or pretty outdated , but don’t panic Yet …You’ve come to the right place!</p><p>Before we dive in even further , i should note that i’m using→ Rails<strong><em> 6.1.4</em></strong> and React <strong><em>17.0.2</em></strong></p><p>I hope that, in writing this, I might be able to make the learning curve easier for those who felt stuck.</p><h3>Why WebSockets?</h3><p>WebSockets are a communications protocol just like <strong>HTTP</strong> which you may be most familiar with …WebSockets, unlike HTTP, are <strong><em>stateful → meaning that the connection is persistent over time between the client/server .</em></strong></p><p>there are a couple of<strong> </strong>terminologies that i need you to be familiar with before getting anything set up :</p><ul><li><em>→</em><strong><em>Half-duplex</em></strong><em> : when a connection is established between a client (reciever) and a server(transmitter) or vice-versa…</em> the data can not be sent in both directions at the <strong><em>same time →(</em></strong><em>one writing data and one reading data</em>) if you haven’t figure it out yet , that’s how<em> </em>HTTP<em> </em>works .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zd4vixBxTbxZsDwiTfWdOQ.png" /></figure><ul><li>→<strong><em>Full-Duplex</em></strong><em> : or (two-way communication /bi-directional) both the client and the server can send messages at the </em><strong><em>same time ,</em></strong><em>This means that unlike a request and a response, the connection stays open for as long as the application is running (i.e. it’s</em><strong><em> persistent</em></strong><em>)</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5R6Cr5o_sWhViKzIGKLAQ.png" /></figure><p>but why webSockets you ask ? … well they are everywhere, almost every modern technologie nowadays uses some kind of webSockets under the hood , there are handful of examples like Push Notifications, Stock market prices updating in real-time, chat, multiplayer games, live online collaboration tools..etc , Another benefit is that the server can push updates without the client requesting it .</p><h3><strong>Introducing Action Cable</strong></h3><p>ActionCable was introduced with Rails 5, which is somewhat considered a bit late to the world of webSockets . Simplifing the process of implementing pub/sub connections within Rails itself and bringing live update while still being performant and scalable.</p><p>With that being said, there are a couple of<strong> </strong>terminologies that you need to be familiar with before we move on to the code :</p><ul><li><strong>→<em>Cable</em></strong> <em>:</em> WebSocket connection used to communicate all data for all channels.</li><li><strong>→<em>Channel</em></strong><em> : </em>Channel is a named, organized way to define behavior with both server and client methods, by which a client browser can subscribe and then communicate both ways via custom data handling code. Server-side implementation logic is kept here for subscriptions.You can think of a channel as a single communication stream, in which information flows both back and forth.</li><li><strong>→<em>Connection</em></strong><em> : </em>Server-side logic for subscription actions taken from clients browser.</li><li><strong>→<em>Subscription</em></strong><em> : </em>When a client initiates a “create subscription” event, the server keeps them grouped in a list of channel’s subscribers to publish to when data is sent via the given channel. Client-side implementation logic is kept here per named channel subscription.</li></ul><h4>Setting Up Your Rails API</h4><blockquote>→Create a new Rails app <strong>API</strong> with PostgresQl database (or any database that you prefer) :</blockquote><pre>rails new my-app --database=postgresql --api </pre><blockquote>→make sure to have the following dependencies installed in your gemfile ( if not run this command )</blockquote><p>bundle add rack-cors add dotenv add bcrypt add jwt add rails add active_model_serializers</p><p><em>then make sure to run </em>bundle install</p><blockquote>rails db:create → create the database</blockquote><p>first thing first , we need to configure our CORS settings for allowing requests from our front-end</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b699c2ba5025ff4af41c609aa6114ee5/href">https://medium.com/media/b699c2ba5025ff4af41c609aa6114ee5/href</a></iframe><p>keep in mind that if you deploy your code to production you’ll want to change this value to match your front-end’s URI</p><p>→creating models association</p><blockquote>rails g model user username:string password_digest:string</blockquote><blockquote>rails g model room name:string</blockquote><blockquote>rails g model chat_message content:string user:belongs_to room:belongs_to</blockquote><p>→ after you’ve done that run rails db:migrate</p><p>Now we’ll start incorporating Action Cable. Action Cable uses <a href="https://redis.io/">redis</a> , so uncomment you redis gem from your Gemfile or install it with add redis and then bundle install and finally, add an Action Cable routes at routes.rb The server must have a Cable endpoint in the router by which all data can be communicated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98c1e9edd069ee288c4495d0018c69ac/href">https://medium.com/media/98c1e9edd069ee288c4495d0018c69ac/href</a></iframe><p>Next, let’s create a chat channel by creating a file chat_channel.rb in app/channels by runnig rails g channel chats</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/199ae4115dbc46de1ad4c0ae89c5aa98/href">https://medium.com/media/199ae4115dbc46de1ad4c0ae89c5aa98/href</a></iframe><p>if we take a look at the newly generated file in app/channels, you’ll see subscribed and unsubscribed methods generated by default</p><blockquote>→<strong><em>subscribed: </em></strong>serves for creating subscription and boradcasting data back from a specific channel →each user that wants to chat can subscribe to the chat_channel, and can send information as well as receive information from other users that subscribed to the same channel</blockquote><blockquote>→<strong><em>unsbscribed</em></strong>: serves for handling any cleanup when a connection is terminated</blockquote><blockquote>→<strong><em>create: </em></strong><em>custom method that we created which we will use to create our messages (</em>more on that later<em>)</em></blockquote><p>We also need to create a chat_message_job class chat_message_job.rb inside folder app/jobs/ by using rails g job chat_message</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/713047208801a4a7baf1314f5fe01beb/href">https://medium.com/media/713047208801a4a7baf1314f5fe01beb/href</a></iframe><p>→this will generate a built -in method called “<em>perform” , before we go over what this method does we need to understand the </em><strong><em>Activejob</em></strong><em> role . basically </em><strong><em>ActiveJob</em></strong><em> role is to execute a series of actions stored in a form of queue (</em><a href="https://www.geeksforgeeks.org/queue-data-structure/"><em>linear structure which follows a particular order in which the operations are performed</em></a><em>) </em><strong><em>in an orderly manner</em></strong><em> </em>which can<strong><em> </em></strong>run in parallel with other processes. that may sound intimidating but don’t worry , <em>ActiveJobs</em> are here to make your life easier .</p><p>→now that you understand how <em>ActiveJob works ,we can now call our “perform” which will get executed after we create our message and boradcast that message to every subscriber of </em><em>chat_channel</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec26733d0519109cdc32352093252d42/href">https://medium.com/media/ec26733d0519109cdc32352093252d42/href</a></iframe><p>Now with that beign said, our back-end should be ready to go. Now let’s head over to the front-end!</p><h4>Setting Up React to Work With Action Cable</h4><p>→Let’s start by creating the react app by running :</p><blockquote>npx create-react-app my-app</blockquote><p>In order to incorporate the Action Cable functionality into our front-end , we need to add a <a href="https://www.npmjs.com/package/actioncable">module</a> to our react app , to do that , run npm install actioncable --save or yarn add actioncable if you’re a <em>yarn</em> fan .</p><p>one thing to note , i’m going to be using<strong><em> redux </em></strong>as a state mangement , if you’re not using redux , don’t worry i’m going to be explaining everything .</p><p>now go ahead and run → yarn add redux react-redux redux-thunk</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a6b358ec316d606512fcec236670f53/href">https://medium.com/media/8a6b358ec316d606512fcec236670f53/href</a></iframe><p>→i should note that there are different ways of interacting with WebSockets from your frontEnd in terms of code structure, this is only one way out of many</p><h4>interacting with ActionCable</h4><p>→<strong><em>creating a consumer : </em></strong>if you looked at Cable.createConsumer(“ws://localhost:3001/cable”) →this is where we’re establishing our connection with the websocket (<em>this only have to be created once</em> )with /cable endpoint (<em>we have that previously set up in our rails </em><strong><em>API</em></strong> ) →our user(browser) is Now called a “<strong><em>consumer</em></strong>” (just a naming convention)</p><p>→<strong><em>creating subscription:</em></strong> after we’ve done that, we need to create our <em>subscription which is as simple as calling </em>cable.subscriptions.create({nameof channel , *params},{}) this is where we deal with everything WebSocket related by following certain design patterns → The first object has a keys of channel (<em>required) →</em> which specifies the channel that we are creating a subscription for (<em>in our case</em> chat_channel),you can also pass some params (optional )as a key/value to send it back when the subscription is established →i should also mention that our user(browser) is now called a “<strong><em>subscriber</em></strong><em>”</em></p><p>→<strong><em>connected: </em></strong><em>this will get called when the user(subscriber) establish a “successful” connection so you may want to do some stuff like sending a notification ..etc</em></p><p>→<strong><em>recieved:</em></strong><em>this is where the user(subscriber) usually receives data back from a specific channel → when the channel boradcast data to its subscribers</em></p><h4><strong>calling custom methods</strong></h4><p>Our <a href="https://www.npmjs.com/package/actioncable">ActionCable node package</a> (that we previously installed )provide us with a handful of methods , the most common one is “<em>perform</em>” → this is where we can call our Rails’ custom methods → perform (name_of_method,{params})</p><p>→now whenever we want to send data , we wil call our custom methods (in my case “create/start”) →then we can receive data back thanks to our <strong><em>received</em></strong> method</p><h4><strong><em>conclusion</em></strong></h4><p>This blog post is getting pretty long, so I’m going to end it here , with that being said , hopefully you’ve learned enough to be able to start incorporating Action Cable into your own React app . if there is any questions you have , please feel free to leave a comment or leave a clap! 👏👏👏.</p><p>As always, thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c47ac2772eea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rails : Pets social media]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/rails-pets-social-media-36fc99df29fa?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/36fc99df29fa</guid>
            <category><![CDATA[sessions]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Mon, 11 Oct 2021 22:00:44 GMT</pubDate>
            <atom:updated>2021-10-18T19:18:57.046Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rails : Pets social media</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WtiJF3uRGO444YhczOxhKQ.jpeg" /></figure><p>this is a small project i’ve been working on called the pet’s social media where the users can view each other’s pets and leave reviews or add sign up other pets and let them connect</p><h3>Before to start</h3><p>this project consist of tow major ends :</p><ul><li><em>the back-end</em> : <strong>ruby on rails </strong>framework</li><li><em>the front end </em>:<strong>react js</strong></li></ul><p><strong>project requirement :</strong></p><ul><li>Use a <strong>Rails API</strong> backend with a React frontend.</li><li>Have at least two resources (two DB tables) on the backend; your application must have full <strong>CRUD</strong> actions for at least one resource.</li><li>Have at least<strong> two different client-side</strong> routes using React Router.</li><li>Implement<strong> authentication/authorization</strong>. At a minimum, a user should be able to log into the site and stay logged in via user ID in the session hash. Password protection is optional.</li></ul><h3><strong>rails in depth:</strong></h3><p>You need to be familiar with 4 parts of the framework in order to write production code. In the following order:</p><ul><li><strong>Routing: </strong>when a Rails app receives an HTTP request, the router will redirect it to the right controller action</li><li><strong>Controllers and Actions: </strong>orchestrating the procedure to handle the HTTP request</li><li><strong>Models: </strong>manipulating the data needed to properly respond to the HTTP request</li><li><strong>Views: rendering the HTTP response</strong></li></ul><blockquote>Models :</blockquote><p>user &lt;- pets</p><ul><li>user has_many pets</li><li>pets belongs_touser</li></ul><p>below is how our association should look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49af8e99496521c675396fa1b0d6a2a1/href">https://medium.com/media/49af8e99496521c675396fa1b0d6a2a1/href</a></iframe><blockquote>controllers / routes :</blockquote><p>the next thing to do is to add-in the routes and controllers for the correct http requests :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/546c238860383d49ecfe8f461adbc17a/href">https://medium.com/media/546c238860383d49ecfe8f461adbc17a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5c3f3e987c433e1b38cecf00ed63e85/href">https://medium.com/media/f5c3f3e987c433e1b38cecf00ed63e85/href</a></iframe><ul><li>Implement<strong> authentication/authorization:</strong></li></ul><p>for this part i used sessions as a way to secure connections and authenticate the client : below is the sessions_controller this will handle all the mind nubing following the separation of concerns principle</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b1debce02901684cf80e3e4cf63fd97/href">https://medium.com/media/8b1debce02901684cf80e3e4cf63fd97/href</a></iframe><p>and voila !! that was it for the backend rails api …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36fc99df29fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Project]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/phase2-react-project-a3c1cf9fe569?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3c1cf9fe569</guid>
            <category><![CDATA[react-project]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Mon, 02 Aug 2021 15:31:04 GMT</pubDate>
            <atom:updated>2021-11-03T17:50:09.116Z</atom:updated>
            <content:encoded><![CDATA[<p>Today i will be sharing with you my project for phase 2 and walk you through all the details. so if you’re interested follow along and continue reading this :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yd8_X2KlsYYOvMf1oWlW2w.png" /></figure><h3>Project Requirements</h3><ul><li>We were instructed to build a Single Page Application <strong>(SPA)</strong></li><li>Your app should use multiple components in a way that keeps your code well organized</li><li>There should be multiple client-side routes using <a href="https://reactrouter.com/web/guides/quick-start">react-router</a></li></ul><p>the app must accesses data from a public<strong> API</strong> or<strong> JSON server</strong></p><ul><li>You can use json-server to create a RESTful API for your backend, or incorporate data from an external API</li></ul><h4><strong>adding react-routes:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*5YKoodlgnN3xPD1hbnmsEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*L61vh-ruiN-36K8HZMTGVA.png" /></figure><p>react enables the navigation among views of various components in a React Application which allows changing the browser URL +keeping the UI in sync with the URL without refreshing the whole page</p><p>as you can see the user have 4 router each rendering different components</p><h3>route : store component</h3><p>as you can guess from the name it’s a store of books that users can interact with by adding it to there cart of just by simply reading<strong> about the book</strong> if they chose to . the user also need to have a <strong>wallet</strong> so that he can’t buy more than he can’t afford</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*0OM3PZK9jMC7ZORkQ48umg.png" /></figure><p>the wallet is set to<em> </em><strong><em>$200</em></strong> by default. In order for all of this to happen the store will need access to some data either from the database (in our case it’s a <strong>db.json</strong>)or from other component so this feature is devided into two sub-feature</p><h4><strong>* interacting with the database:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*N_HYZ44Afcpm3qyZToIqQg.png" /></figure><p><strong>The database</strong> is dvided into two main objects :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/181/1*O34aPcH7hOHBuWP2m9aFmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*XapIml9lJ4ZUDdVnCf94JQ.png" /></figure><ul><li><strong>store : </strong>this is where we store all the information about our books each book have : “id/name/number of likes /price/amount available in stock /src “</li><li><strong>users :</strong> this where all the information about the user interaction get stored ,once selected each user have:</li><li><strong><em>+userName</em></strong></li><li><strong><em>+wallet</em></strong></li><li><strong><em>+cart</em></strong> :listing all the items bought and the total</li></ul><h4><strong>fetch request /stateUpdate</strong></h4><ul><li>using react custom hooks like <strong>useEffect</strong> will allow React to access data from the database when first rendering then using the reponse to <strong>update the state</strong></li></ul><h4>* viewing book’s content:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*TQ_5e6F2JbUVsmQvpyJFEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*YbgjifzaIAiWINDW9n3heg.png" /></figure><p><strong>users</strong> need to view the books before they can decide if they want to add it to their cart or not so to do that i added a simple boolean property<em>{isOn=</em><strong><em>false</em></strong><em>}</em>to every book component to keep track of which book to render</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*kb165MwlcQojRUUmapKowQ.png" /></figure><p>this information is passed down to<strong> ItemCard component </strong>along with a callback function “<strong>handleContent</strong>” this will keep track of the user’s clicks and render the related book content</p><h4><strong>* adding /updating wallet :</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*-OvxoPWQkhgxLyJhN6BUSA.png" /></figure><p>this feature is devided into two sub-features:</p><ul><li><strong>adding the book to the checkout section</strong>:</li><li>using the <strong>handleWallet</strong> function by keeping track of books added {<br> — if the <strong>book exit</strong> just <strong>update</strong> the <strong>price</strong> using <strong>setCart(priceChange)</strong></li></ul><p>— if the book was’nt added before add it to the cart</p><p>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*PzcbV31JNY5SXHN9cl4gWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*es_5cRt55nzP0w98gSh80Q.png" /></figure><ul><li><strong>update the user wallet :</strong></li></ul><p>updating the userwallet by setting the state of <strong>User</strong> to the amount left after <strong>purchase</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*ZfYy8LNSwnxnZnoMW1fSSg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3c1cf9fe569" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Phase1:-JavaScript Project]]]></title>
            <link>https://mohamed-aziz-laouiti.medium.com/phase1-javascript-project-d8566e9c338f?source=rss-4ec967c40841------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8566e9c338f</guid>
            <category><![CDATA[javascript-idea]]></category>
            <category><![CDATA[javscript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-projects]]></category>
            <dc:creator><![CDATA[Mohamed Aziz Laouiti]]></dc:creator>
            <pubDate>Sat, 03 Jul 2021 02:16:35 GMT</pubDate>
            <atom:updated>2021-11-03T17:50:39.618Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Project</h3><p>So we meet again…today i will be sharing with you my project for phase 1 and walk you through all the ifs and whys . so if you’re interested follow along and continue reading this :)</p><figure><img alt="chatapp for sending /recieve message create/delete/login accounts" src="https://cdn-images-1.medium.com/max/1024/1*0NFW4ROGYAmPzsdhW7polg.png" /><figcaption>Not so simple chatapp</figcaption></figure><p>so as you can see from the image above its most likely a chatapp some of you may knew how chatapp works (send/recieve message) meaning that you get the idea as to how to use it and that’s what i think in my <strong>opinion</strong> what you first need to think about when making your project. it should <strong>be self descriptive</strong> that’s what i think in programming is all about, its simply puting the <strong>complexity</strong> back into the code in exchange for the <strong>ease of use .</strong></p><h4><strong>Project Requirements</strong></h4><ul><li>We were instructed to build a Single Page Application <strong>(SPA)</strong></li><li>Your app needs to incorporate at least 3 separate <strong>event listeners</strong></li><li>Some interactivity is required. as simple as adding a “like” button or adding comments. they do not need to persist after <strong>reloading the page</strong></li><li>must be a <strong>HTML/CSS/JS </strong>using frontend</li><li>the app must accesses data from a public <strong>API</strong> or<strong> JSON server</strong></li><li>interactions between the client and backend should be handled asynchronously + using<strong> JSON</strong> as the communication format</li></ul><p>first of all is structuring your project aka making files (html-css-js)and directories also adding <strong>db.json</strong> as database by using npm i db-json +setting the server using json-server — — watch db.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*1OkRTXKsXScWjj7LAy_JWA.png" /></figure><h4><strong>Add account feature</strong></h4><ul><li>This feature is divided in tow sub-features:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*gQTZtt_gKwBMzLawklQVZA.png" /></figure><p><strong>+ toogle</strong> button that prompt the user with a form for <strong>creating an account</strong> the user will set the <strong><em>username </em></strong>/<strong><em>password</em></strong> of his chose</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*AOpE-J_rjkpASm4SIy1ZrA.png" /></figure><p><strong>+ API</strong> request /<strong>DOM</strong> render=&gt;Behind the scene with the form now being submited the program will make a<strong> POST</strong> request to <strong>JSON server</strong> adding the new info to the data base(db.json) which will afterwards send back that info and use it to update the <strong>DOM </strong>showing the<strong> new account</strong></p><h4>delete feature</h4><ul><li>this feature is activated by clicking on the (x) icon which will trigger two actions :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*zcO-6aDZ4Tp73Fy7zfjdDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*WgsSC5lmJvqnp-Nd-vNIpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*Keyup23y97RIGUvtF6dLwQ.png" /></figure><p>+<strong>Click</strong> <strong>event</strong> triggering an <strong>asynchronous</strong> function</p><ul><li><strong>API </strong>delete request : the program will make a<strong> DELETE </strong>request to <strong>JSON server removing the element</strong> using their id from the database(db.json) which will afterwards update the <strong>DOM</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*eAdYiP9vLAfrT26s-NcEPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*6dwIsaES02xmmdPuROqqXg.png" /></figure><h4>adding /deleting comment</h4><ul><li>this feature allow the user to make comments by typing in the input field than send by hitting the Enter key which will add that to the comment file +adding the user icon</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8566e9c338f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>