<?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 Mazen Alswar on Medium]]></title>
        <description><![CDATA[Stories by Mazen Alswar on Medium]]></description>
        <link>https://medium.com/@mazenswar?source=rss-b72ac0bfd7b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5YCKH4FT2K-keuE5fpfiRQ.png</url>
            <title>Stories by Mazen Alswar on Medium</title>
            <link>https://medium.com/@mazenswar?source=rss-b72ac0bfd7b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:52:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mazenswar/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[Setting up auth with a Rails JSON API and a React Frontend]]></title>
            <link>https://medium.com/@mazenswar/setting-up-auth-with-a-rails-json-api-and-a-react-frontend-dbed79a0814f?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbed79a0814f</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 14:01:49 GMT</pubDate>
            <atom:updated>2019-10-22T14:01:49.104Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the main set backs I have encountered in my coding journey (so far) was trying to wrap my head around authorization and authentication and how to implement them in my web application since there are a number of moving pieces and different technologies at play. In this blog, I will walk through creating a Ruby on Rails JSON API with a React frontend using React hooks and Redux for state management.</p><p>I broke down the blog into two parts:</p><p>1. <a href="https://medium.com/@mazenswar/part-1-creating-a-rails-json-api-using-bcrypt-and-jwt-for-auth-23bfc2217d7b">Creating a Rails JSON API using BCrypt and JWT for auth.</a></p><p>2. <a href="https://medium.com/@mazenswar/part-2-creating-a-react-frontend-using-react-hooks-react-router-redux-40d195357f66">Creating a React frontend using React Hooks, React Router &amp; Redux for state managment</a>.</p><p>Hopefully this will help some people get a better sense of authorization and authentication.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbed79a0814f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: Creating a React frontend using React Hooks, React Router & Redux]]></title>
            <link>https://medium.com/@mazenswar/part-2-creating-a-react-frontend-using-react-hooks-react-router-redux-40d195357f66?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/40d195357f66</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 14:00:48 GMT</pubDate>
            <atom:updated>2019-10-22T14:00:48.817Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, I will be setting up a React project from scratch using npx create-react-app and will use React hooks and Redux for state management.</p><h3>What we will use for this part:</h3><p>1. react</p><p>2. redux</p><p>3. react-redux</p><p>4. redux-thunk</p><p>5. react-router-dom</p><h3>Workflow:</h3><p>1. Creating the React project and installing packages/libraries we need for the app.</p><p>2. Creating blank components we will use for this app.</p><p>3. Setting up react-router to navigate between pages.</p><p>4. Setting up redux.</p><p>5. Adding code to our components</p><p>6. Testing our app.</p><h4>Creating the React project and installing packages/libraries we need for the app</h4><p>run npx create-react-app rr-auth-frontend</p><p>run cd rr-auth-frontend to navigate to the project folder</p><p>run npm install to install all the packages and dependencies for the React project</p><p>To install the rest of the packages/libraries mentioned above we will run:</p><p>npm install redux react-redux redux-thunk react-router-dom</p><h4>Creating blank components we will use for this app.</h4><p>In this app, we are only concerned with logging in the user and persisting their session. So we will create three components(pages): &lt;Login /&gt; &lt;Signup /&gt; &lt;Home /&gt;</p><p>in our src folder lets create a folder called Pages and create FOUR files in it:</p><p>1. Login.js</p><p>2. Signup.js</p><p>3. Home.js</p><p>4. index.js</p><p>If you use <a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets">react-snippets</a> you can type rafc and generate an empty component in each of the files we created except index.js</p><p>We will use index.js as our focal point for components so we will import all our components there and `export default` a single object with values that point to those components.</p><p>Your index.js file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcde3bc6f0dd55be3944bbce8c42f4ae/href">https://medium.com/media/fcde3bc6f0dd55be3944bbce8c42f4ae/href</a></iframe><h4>Setting up react-router</h4><p>1. To start, in /src I will create a file name Routes.js which will handle all our routing. In the file, I will use the rafc shorthand to get an empty template of a React functional component.</p><p>2. We need to import a couple of components from react-router-dom at the top of our file under the react import statment. So we will add the following line: import {Switch, Route} from ‘react-router-dom’</p><p>3. Next, we will import our components which we can do in a single line. Since we used an index.js in our Pages folder we can import the object that was exported as default from the that file with the following code import Pages from ‘./Pages’</p><ul><li>Note: since the object was exported using export default, we can name it anything while importing it.</li></ul><p>4. Next, we will add the &lt;Switch&gt;&lt;/Switch&gt; component which will wrap our routes.</p><blockquote>NOTE: The &lt;Switch&gt; is not required for grouping &lt;Route&gt;`s, but it can be quite useful. A &lt;Switch&gt; will iterate over all of its children &lt;Route&gt; elements and only render the first one that matches the current location. (https://reacttraining.com/react-router/web/guides/basic-components)</blockquote><p>5. After that we will add three &lt;Route /&gt; components that point to our pages giving them two props: path and component.</p><p>6. Your Routes.js should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09b30f2c890e5608c5f6370ddcde935/href">https://medium.com/media/b09b30f2c890e5608c5f6370ddcde935/href</a></iframe><p>7. We will create a &lt;Nav /&gt; component that will serve as our nav-bar and that will help us navigate between pages without having to type out the url. Let’s make a new folder Components and add a Nav.js file to it. We can use rafc shortcut for now to get an empty skeleton of the component.</p><p>8. Open src/App.js and let’s first import our &lt;Routes /&gt; and &lt;Nav /&gt; components by adding import Routes from ‘./Routes’ and import Nav from ‘./Components/Nav’.</p><p>9. Next, we will delete the boilerplate code and replace it with the &lt;Routes /&gt; and &lt;Nav /&gt; components.</p><p>10. Finally, we will import {BrowserRouter as Router} from `react-router-dom` and wrap our existing components with it. Your App.js should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/676ed5946e5d76d18adffd1e3500efd5/href">https://medium.com/media/676ed5946e5d76d18adffd1e3500efd5/href</a></iframe><h4>Setting up Redux</h4><p>Let’s start by creating a redux folder src/redux. Within the folder lets create two new files src/redux/actions.js and src/redux/rootReducer.js.</p><h4>Reducer</h4><p>in rootReducer.js let’s add our code for the reducer</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27b6a55975149448a5cc27a7842f2dca/href">https://medium.com/media/27b6a55975149448a5cc27a7842f2dca/href</a></iframe><p>Navigate to src/index.js and in that file:</p><p>1. We need to import a couple of things before we start coding lets start by adding the following lines to the top of the file under the React imports:</p><pre>import thunk from ‘redux-thunk’<br>import { Provider } from ‘react-redux’<br>import { createStore, applyMiddleware} from ‘redux’ <br>import rootReducer from ‘./redux/rootReducer.js’</pre><p>2. We need to initialize our store using the two functions we imported from redux. We will add the following:</p><p>const store = createStore(rootReducer, applyMiddleware(thunk))</p><p>for more information about what the thunk middleware does, check out this <a href="https://github.com/reduxjs/redux-thunk">link</a>.</p><p>3. To make the store accessible across our app, we will wrap our &lt;App /&gt; component with &lt;Provider /&gt; which we imported from react-redux. We will then give &lt;Provider /&gt; a store props that points to our store variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3e5a4857d48b77b089c56a12f529ca4/href">https://medium.com/media/f3e5a4857d48b77b089c56a12f529ca4/href</a></iframe><h4>Actions</h4><p>1. In actions.js, we will define our functions that will handle sending requests to the API and dispatching actions to our redux store.</p><p>2. We will define five functions:</p><ul><li>newUserToDB() =&gt; POST to <a href="http://localhost:3000/users%60">http://localhost:3000/users</a></li><li>deleteUserFromDB() =&gt; DELETE to <a href="http://localhost:3000/users/:id%60">http://localhost:3000/users/:id</a></li><li>loginUserToDB() =&gt; POST to <a href="http://localhost:3000/login%60">http://localhost:3000/login</a></li><li>persistUser() =&gt; GET to <a href="http://localhost:3000/auth%60">http://localhost:3000/auth</a></li><li>logoutUser() =&gt; We will clear our token from the browser and reset the user object in our redux store</li></ul><p>Your actions.js should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bb2712c89293baed53de46fd04b3b4b/href">https://medium.com/media/1bb2712c89293baed53de46fd04b3b4b/href</a></iframe><h4>Adding code to our components</h4><p>src/Pages/Login.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efa35cf7302d5a4b19198963c2d5dbe3/href">https://medium.com/media/efa35cf7302d5a4b19198963c2d5dbe3/href</a></iframe><p>src/Pages/Signup.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bec7e1fef206750ffe38dff1d1fe967e/href">https://medium.com/media/bec7e1fef206750ffe38dff1d1fe967e/href</a></iframe><p>src/Pages/Home.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba4c39e81bcffd96d99bd60862472b49/href">https://medium.com/media/ba4c39e81bcffd96d99bd60862472b49/href</a></iframe><p>src/Components/Nav.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/680cf6a7deaf22525ff3c65dbe07bde5/href">https://medium.com/media/680cf6a7deaf22525ff3c65dbe07bde5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40d195357f66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: Creating a Rails JSON API using BCrypt and JWT for auth.]]></title>
            <link>https://medium.com/@mazenswar/part-1-creating-a-rails-json-api-using-bcrypt-and-jwt-for-auth-23bfc2217d7b?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/23bfc2217d7b</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 14:00:18 GMT</pubDate>
            <atom:updated>2019-10-22T14:00:18.687Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part, I will be using Ruby on Rails as an API. Rails is dynamic, intelligent and opinionated. Rails is easy to set-up and has very descriptive errors which make debugging issues a much more pleasant experience.</p><p>Since our project will only focus on auth, we will be only creating one Model, which is the User model.</p><h3>Creating the rails project</h3><p>run rails new rr-auth-api —-api -T -d postgresql</p><p>This command will generate a new rails api project.</p><p>The api flag allows you to create a rails project with a limited subset of rails features that are geared toward api functionality.</p><p>The T flag is a shorthand that equals —-skip-test or —-no-skip-test which will skip creating test files when creating the project. This flag is optional. Since I won’t be using the test files, I want to keep my project setup as small as possible.</p><p>The -d postgresql command tells rails that we want to set up our project with Postgres as our database. The -d flag is shorthand for — database=DATABASE</p><p>After running this command make sure you navigate to the project folder by typing in cd &lt;project-name&gt; and in this case cd rr-auth-api</p><h3>Setting up gems:</h3><p>1. ‘jwt’</p><p>A ruby implementation of the RFC 7519 OAuth JSON Web Token (JWT) standard.</p><p><a href="https://github.com/jwt/ruby-jwt">https://github.com/jwt/ruby-jwt</a></p><p>2. ‘bcrypt’</p><p>Handles salting, hashing and authenticating user passwords.</p><p><a href="https://github.com/codahale/bcrypt-ruby">https://github.com/codahale/bcrypt-ruby</a></p><p>3. ‘cors’</p><blockquote>“Rack::Cors provides support for Cross-Origin Resource Sharing (CORS) for Rack compatible web applications.</blockquote><blockquote>The CORS spec allows web applications to make cross domain AJAX calls without using workarounds such as JSONP. See Cross-domain Ajax with Cross-Origin Resource Sharing”</blockquote><blockquote><a href="https://github.com/cyu/rack-cors">https://github.com/cyu/rack-cors</a></blockquote><p>After adding those gems to Gemfile.rb in your root directory (rack-cors and bcrypt are already there but commented out), we will go into our terminal and run bundle install which will install the gem dependencies for our project.</p><h3>Cors set up:</h3><p>In the root of the app, we need to navigate to config/initializers/cors.rb and uncomment some code to make sure cors is up and running. If you don’t see the cors.rb file, it may mean that you forgot to add —- api flag when initializing your project with rails new.</p><p>In cors.rb our code should look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8151eca367f6173d49f5579d4964790/href">https://medium.com/media/b8151eca367f6173d49f5579d4964790/href</a></iframe><p>Please note that this set-up should only be used in development. In production, you need to make sure that you specify the `origins` that are allowed to make requests to your api and the actions that request should be able to hit.</p><h3>Setting up our User resource</h3><p>Next, we are going to go back to our terminal to create our User resource. In this case, I will utilize the rails g resource &lt;resource-name&gt; generator which will give us everything we need to get up and running. As you will be able to see in your terminal and in your project folder, this command will generate a migration, a model, a controller and a route.</p><p>So, we will create a User resource as follows:</p><p>rails g resource User username password_digest</p><p>Please note that since we are working with bcrypt, we need the password column in our table to be called password_digest. Brcypt looks for that attribute in our table when we try to authenticate user password or create new users and hash their passwords.</p><p>You should now have a</p><p>app/controllers/users_controller.rb</p><p>app/models/user.rb</p><p>db/migrate/&lt;migration_number&gt;_create_users.rb</p><p>And in config/routes.rb you should see resources :users</p><p>This will give your API RESTFUL endpoints(routes) to handle requests.</p><h3>Setting up the postgresql database</h3><p>1. Before we can start writing code, we need to go to our terminal and:</p><p>- Create our database: Since we are using Postgres, Rails does not create the database automatically so we first need to make sure that our postgres application is running.</p><p>- run rails db:create</p><p>- Next, we will migrate our tables using rails db:migrate</p><p>2. The first thing we will do is adding has_secure_password method (which comes from ActiveModel) in our user model. This method provides us with a number of methods to set up and authenticate user passwords with bcrypt.</p><p>3. While we are in the User model, we will also set up a validation to make sure all usernames are unique. To do this, we add this line to our model validates :username, uniqueness: true</p><p>4. Next, we will move on to the UsersController and set up our actions. Since we want to be able to create users, show users, update users and delete users, we will have four actions show, create, update and destroy.</p><p>5. Since I want to ‘log in’ the users automatically when they create an account, I will generate a token for the user once their account is created. To do this, we will use the JWT.encode method. The method takes in three arguments:</p><ul><li>Payload: our payload will be an object that has the key user_id that points to the user’s id.</li><li>Secret: can be a string of your choosing. In this example I will use “thisIsMySecret”.</li></ul><blockquote>NOTE: I will define a method in the application controller named secret which I will be using to be consistent and modular. You should hide your secret in an environment file in production. Check out this link to see how you can do that in Rails 5.2 and up (https://www.viget.com/articles/storing-secret-credentials-in-rails-5-2-and-up/)</blockquote><ul><li>Hashing algorithm: in this instance we will use ‘HS256’.</li></ul><p>6. The return value of the above method will be our token that we will send in our response and store in the browser to maintain the user’s session.</p><p>7. Your controller should look like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba68f6114090b3f6118ff380bc6454d/href">https://medium.com/media/eba68f6114090b3f6118ff380bc6454d/href</a></iframe><p>8. You will notice in the private method defined at the bottom that I used the key :password and not :password_digest. Bcrypt looks in our table for columns that have the &lt;word&gt;_digest where ‘word’ could be any key you choose, and in this case it’s password. So Bcrypt knows that :password corresponds to our :password_digest column in our users’ table.</p><h3>Testing our our table</h3><p>To test our code, we will go to our console and create a user to test out our set-up. Navigate to your terminal and fire up the console using rails c.</p><p>We will then create our first user by running User.create(username: “user1”, password: “123”)</p><p>The command should return the instance of the User model that we created. You will notice that the password_digest key points to a long jumbled up string. This is the user’s hashed password.</p><h3>Setting up JWT and testing with Postman</h3><p>1. With our users’ controller set up to deal with creating, showing, updating and deleting users, we will set up a different controller which I will call auth_controller.rb to handle logging in and persisting the user’s session using JWT. My reasoning for separating this logic from the users’ controller is that I want to separate my concerns. I want my users’ controller to handle CRUD actions related to the users’ table and my auth controller will strictly handle logging in and persisting the user.</p><p>2. So in app/controllers let’s create a new file auth_controller.rb. In this controller we will define two actions login and persist.</p><p>3. login: this action will handle the following:</p><p>- This action will receive a user’s username and password through params.</p><p>- It will try to find a user from the users’ table.</p><p>- If a user is found, it will call the method authenticate on the user instance while passing in the user’s password from params</p><p>- If there is a user and the user is authenticated, we will generate a token for our user and render a json object that has both our user instance and that user’s token.</p><p>- Otherwise, we can render a json object with an error message.</p><p>4. persist: this action should do the following:</p><ul><li>Check if the headers in the request have a Authorization key</li><li>If it does, then we will grab the token from the headers and decode it and use it to find the user instance that this token belongs to and render it as our response.</li><li>If there is no Authorization key, then this action will do nothing.</li></ul><p>auth_controller.rb should look likes this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/600173c5f002b4fa1e6db261f94a1ded/href">https://medium.com/media/600173c5f002b4fa1e6db261f94a1ded/href</a></iframe><p>5. This controller will not correspond to any tables in our database. And since we manually created the file, we need to define the routes. So, we will navigate to config/routes.rb and add two routes:</p><ul><li>A POST route to /login which will direct requests to auth#login</li><li>A GET route to /auth which will send requests to auth#persist</li></ul><p>Now we can test our code and endpoints to make sure that our code is working as expected. I used Postman to make api calls all my endpoints and test them out. I will not go into details of how to test your api here. If you haven’t used postman before, you can check out this helpful post (https://medium.com/aubergine-solutions/api-testing-using-postman-323670c89f6d)</p><p>This concludes Part 1 of this tutorial.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23bfc2217d7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why learning vanilla CSS is so important]]></title>
            <link>https://medium.com/@mazenswar/why-learning-vanilla-css-is-so-important-8e27aa6ed65?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e27aa6ed65</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Tue, 02 Apr 2019 11:46:49 GMT</pubDate>
            <atom:updated>2019-04-02T11:46:49.616Z</atom:updated>
            <content:encoded><![CDATA[<p>To start, let’s talk about what CSS actually means. CSS stands for Cascading Style Sheets, and according to MDN Web Docs, CSS is a:</p><blockquote><a href="https://developer.mozilla.org/en-US/docs/DOM/stylesheet">stylesheet</a> language used to describe the presentation of a document written in <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">HTML</a> or <a href="https://developer.mozilla.org/en-US/docs/XML_introduction">XML</a> (including XML dialects such as <a href="https://developer.mozilla.org/en-US/docs/Web/SVG">SVG</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/MathML">MathML</a> or <a href="https://developer.mozilla.org/en-US/docs/Glossary/XHTML">XHTML</a>). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.</blockquote><p>the term vanilla CSS os used to describe plain old ‘classic’ CSS that doesn’t rely on other plugins or frameworks or libraries. Vanilla CSS is extremely powerful on its own and provides you with a multitude of styling tools.</p><p>I cannot begin to emphasise the importance of learning vanilla CSS if you are looking to do frontend work. Yes there are a lot of amazing libraries like Bootsrap that enable you to do things much faster and not have to worry about the intricate details of positioning and styling elements. But in my personal opinion, knowing “what’s going on under the hood” is an extremely valuable tool to have.</p><p>Most features that libraries provide you can all boil down to vanilla HTML, CSS and Javascript. knowing these languages in their pure form and on a fundamental level gives a lot of power in navigating you codebase and making things look and work how you want them to.</p><p>Moreover, on the debugging front, the need for knowing how and why things work is probably the only fundamental truth. What I mean by that is that, logically speaking, you cannot fix something when you have no effing idea how and why that thing works.</p><p>I’ve noticed this ongoing joke in programming communities that backend developers are scared of frontend work, especially dealing with CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*p9vMf8jhyHhEux4pwvQFpw.png" /></figure><p>I am honestly a bit baffled by this. CSS might be scary at first but if you can navigate programming languages, you are beyond capable of mastering CSS. Perhaps the core point of contention would be design because that is a mountain of its own to conquer. But in my opinion, I don’t believe one needs to be a good designer to master CSS.</p><p><strong>Imagine this scenario for example:</strong></p><p>You work for a startup that wants to make its first website(wooohooo!). They have an awesome graphic designer that knows nothing about coding beyond SVG stuff they picked up from Adobe Photoshop and Illustrator, so they give you a printed out mock-up of the website and hope you can translate that into code.</p><p>You get a bit flustered because you don’t think you have what it takes to style things to look like the mock-up. You get a bit flustered and begin to wonder why you took this job to begin with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*gdK__S0SyCdasscIs_1Slw.gif" /></figure><p>You try to find an “easy” way out and you go to Bootstrap. you get super anxious reading the documentation because you still are not familiar with the CSS jargon and you just want things to look pretty damnit! You get the hang of bootstrap and you make things look similar to the mockup but they still look “bootstrappy” and you end up being confused again and wondering why you took this job.</p><p>Then you think to yourself, “hey I learned JavaScript and it was scary and foreign to begin with but after pushing through the first interactions, but I got that shit down!’. So you decide to do the same with CSS.”</p><p>You decide to take on the CSS monster and you start to try free courses online and read W3 Schools documentation to make sense of it. After reading documentation and testing things out for a while, you realise that dealing with CSS is like dealing clay, yo can shape it to look like anything you want if you have a solid foundation of knowledge and the necessary tools to manipulate it.</p><p>You finally have some clarity on why things work the way they work( like everything else in programming, these are usually fleeting moments of knowledge, rather than epiphany of knowledge).</p><p>You now have a good idea on how things like Bootstrap work! and you have a good base of knowledge that can help you navigate the mock-up that the designer gave you and try to translate it into code!</p><p>Like everything in programming, it is scary and frustrating at first and there’s a lot hiccups and tough lessons to learn along the way. But in my opinion, anyone that can learn and navigate a programming language can master CSS.</p><p><strong>Leaving our completely fake scenario with the happy ending and going back to reality.</strong></p><p>CSS is frustrating and annoying and sometimes cringe-worthy. However, it is extremely powerful and gives you absolute control over how to style your pages/apps and materialise the vision in your head.</p><p>Programmers coming from backend languages should not be intimidated by CSS, it is, like everything else you’ve ever learned, conquerable. You just have to put the time and overcome the unavoidable hurdles that come with learning something new.</p><p>I hope this helps motivate you take a stab at learning pure CSS and getting the hang out what’s going on under the hood of styling libraries and frameworks.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e27aa6ed65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with CSS Grid Layout]]></title>
            <link>https://medium.com/@mazenswar/getting-started-with-css-grid-layout-bfff80a48e9c?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfff80a48e9c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Sat, 16 Mar 2019 21:17:58 GMT</pubDate>
            <atom:updated>2019-03-16T21:17:58.938Z</atom:updated>
            <content:encoded><![CDATA[<p>Getting started with CSS in general is intimidating, especially if you haven’t played around with it before. CSS alone, without any preprocessors gives you a plethora of tools to manipulate your website and make it look exactly how you want it to look.</p><p>One of the biggest struggles I had when I got started with CSS was that I assumed what a property meant without properly reading the documentation. I was holding myself back by assuming instead of actually reading and understanding. Once you go through the documentation and understand what CSS can do for you, it will be much more less intimidating.</p><p>CSS grids were on the things that intimidated me the most when I was teaching myself CSS. I kept going back and forth with my assumptions and getting frustrated. It wasn’t until I decided to learn CSS the “proper way” that I began to understand how grids layout works in CSS.</p><p>My first takeaway from that experience was that the documentation is ALWAYS the best place to start understanding something new. After reading the documentation, what was vital to cementing my understanding was me taking notes and using clear and concise language that I will understand, even on the days where my brain may not functioning in full capacity.</p><p>So, let’s get started with grid layout!</p><p>First we need to know what grid commands we have access to. As always, documentation is a great place to start. I love <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout">MDN</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTP0VVU6nO-938VZJ9z4tQ.png" /></figure><p>for the sake of simplicity, I will start with the ones that I feel are very straight forward and easy to grasp using the made up example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7AakNF5du9eolhil95CjQ.png" /></figure><p>To begin you have to turn the container/element that you want to use into a grid. In this case, I used the body element as my grid. Whenever I want to use a grid to organise my page, I first consider the number of columns and rows that I want and their sizes. In the case of this example project I am making:</p><ol><li>4 equally sized columns, for which I used grid-template-columns</li><li>3 rows, where the top and bottom rows are equally sized and the middle row is three times the size of the other two rows using grid-template-rows.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEZ-yKD9GCro86Z23SE9Hg.png" /></figure><p>for the html, I have 11 &lt;div&gt;&#39;s that look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*bsWRKcNDTjsgnquFT-jIvQ.png" /></figure><p>So, right now we have a grid! but everything is positioning by default. According to MDN, the default positioning for grid items is as follows:</p><blockquote>As you can see with the above example, if you create a grid all child items will lay themselves out one into each grid cell. The default flow is to arrange items by row. Grid will lay an item out into each cell of row 1. If you have created additional rows using the grid-template-rows property then grid will continue placing items in these rows. If the grid does not have enough rows in the explicit grid to place all of the items new <em>implicit</em> rows will be created.</blockquote><p>So as of now, our page looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X0zKnkJmVFWJeRC7XS5Bag.png" /></figure><p>Now that we have this beautiful grid, we can use CSS to place elements as we wish. To do this we can tell each element which column and which row to occupy. I find that having a visual aid helps me navigate grids more efficiently so I make something as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPsKQIUeAXrHP--caKIP7w.jpeg" /></figure><p>This can help us visualise how to define where we need to place our content. Let’s take a look at the CSS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_yJLCPqMJ297YkSxZ1wjQ.png" /></figure><p>for each class we have three main properties related to the grid placement:</p><ol><li>grid-row: which tells the item which row it should be placed in.</li><li>grid column: which tells the item which column we want it to be in.</li><li>span: which tells the elements how many rows or columns it should occupy.</li></ol><p>This has been a very short intro to CSS grids. There’s so much more to CSS grids and encourage you to check out the <a href="https://css-tricks.com/snippets/css/complete-guide-grid/">CSS Tricks’ guide</a> to Grids.</p><p>If you want to play around with the sample project, you can find it <a href="https://codepen.io/mazenswar/pen/EMLoNx">here</a>.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfff80a48e9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build an interactive Freddie Mercury meme using HTML, CSS, JS & jQuery]]></title>
            <link>https://medium.com/@mazenswar/how-to-build-an-interactive-freddie-mercury-meme-using-html-css-js-jquery-d8e36c79f244?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8e36c79f244</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 19:15:32 GMT</pubDate>
            <atom:updated>2019-03-04T19:15:32.158Z</atom:updated>
            <content:encoded><![CDATA[<p>I don’t know about you, but as a budding programmer I hear this sentence a lot: “Just go build something, that’s how you learn”. This statement is daunting for anyone that hasn’t built anything from scratch before. Where do I start? What do I build? Can I actually do this?. Those are but a few of the questions I asked myself whenever I tried to delve into it and build something from scratch.</p><p>In this article I am going to share with you how I built an interactive meme for fun, and to practice a little front-end.</p><h3><strong>My inspiration:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*BsOXrF1sswim5DYR9hZ7jQ.jpeg" /></figure><h3><strong>A static image of my final product:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*7Ztv3CEUdcY9GBz2K7ixHw.png" /></figure><h3><strong>So, where did I start?</strong></h3><p>I started with the HTML as the basic skeleton of the project, I wrapped all of the content in divs to make it more easy to manipulate in CSS(more on that later).</p><p>my body tag reads like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ON4Su6fYgVO84YGJNEV4Q.png" /></figure><p>After doing that, I made sure that I set up my link to my css file in the head of the HTML document:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbsrge4Bw0ewNrgXjXQ0Bw.png" /></figure><p>I also made sure to link my JS file &amp; jQuery in the bottom of the body tag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-tqyx6bbLbTO3L7tI--ig.png" /></figure><p>moving on to the fun part(for me, at least). Before delving into CSS and trying to beautify all the boring HTML, I had to do one thing for the sake of streamlining my work. I decided on the colour palette, for which I used <a href="https://coolors.co/">https://coolors.co/</a> which generates awesome colour palettes for free.</p><p>Moving on to the CSS, I started with making the background black, because I thought it would give the background good contrast with the retro colour palette I chose. I also wanted the “choices” (i.e “to break free”) to change colours when users hovered over them for which :hover came in handy.</p><p>And so I jumped into the css. I kept the following themes in mind how I wanted the page to look:</p><h3>responsiveness to different screen size, symmetry and consistent alignment of content (using vh and vw units is amaaazing)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*G8JqugWvLdHs6LkD2_8h_g.png" /></figure><h3>interactivity using :hover</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*PjrsyhFK1ccnEJJltLKdnw.png" /></figure><p>After that I moved to the logic part of this project. Using JavaScript, I made the “choices” play a soundbite of the song which it refers to. To do this, I first had create soundbites, for which I used <a href="https://www.audacityteam.org/">Audacity</a> which is an open-source audio editor that lets users manipulate audio.</p><p>To implement this logic I first created four HTMLAudioElement using JavaScript:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7OkbJy3D9MDkQNq3gSQ2g.png" /></figure><p>Next I created an array with the song variables and helper method to pause any audio that’s playing on the page whenever another audio element is clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAdKJ3NCJqNqnw1ru7oAdA.png" /></figure><p>Within this file, in addition to playing soundbites, I also implemented logic to change the gif whenever a different choice is clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCA07OV0oRygfDtbOzFrqg.png" /></figure><p>To see all of this action, you can check it out here:</p><p><a href="https://mazenswar.github.io/freddie/">What do you want? Freddie Mercury</a></p><p>In conclusion, this might not have been the most of complex projects but as a developer looking to hone his skills, it was great. I got to learn and implement logic to play music and do something fun related to something I am genuinely interested in. My advice for novice developers that are looking for projects to better their skills is to start simple and choose something that you personally enjoy.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8e36c79f244" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breaking down complicated code (using Ruby as an example)]]></title>
            <link>https://medium.com/@mazenswar/breaking-down-complicated-code-using-ruby-as-an-example-93d332de6dc?source=rss-b72ac0bfd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/93d332de6dc</guid>
            <category><![CDATA[codewars]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[recursion]]></category>
            <dc:creator><![CDATA[Mazen Alswar]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 18:41:48 GMT</pubDate>
            <atom:updated>2019-02-19T18:41:48.556Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve only been programming for less than a year but it’s been an amazing journey so far and I am very grateful for all the wonderful free resources there are to learn code including, <a href="http://freecodecamp.org/">freecodecamp.org</a>, <a href="http://codewars.com/">codewars.com</a>, <a href="http://flatironschool.com/">flatironschool.com</a>’s bootcamp prep course and <a href="http://theodinproject.com/">theodinproject.com</a> which have been massive for my learning journey.</p><p>One of the websites that I really love to spend my free time (if I ever have any) trying to become a better and more well-rounded programmer is <a href="http://codewars.com/">codewars.com</a>. I love going through their challenges learning different ways of working with code. But as someone who hasn’t been programming for a long time, I found myself extremely frustrated and intimidated when I looked at how other people’s solutions fared next to mine.</p><p>Point in case, the “persistent bugger” problem, in which you are asked to:</p><blockquote><em>Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.</em></blockquote><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8BwinjyzA70K297Qsxl6g.png" /></figure><p>At the outset I thought to myself “this is gonna be a piece of cake!”.</p><p><strong>It wasn’t.</strong></p><p>I felt like thinking of the problem in an abstract way was fairly straight forward, but when it came to translating it into code, I hit a wall. I struggled, but I kept pushing through and after some time I had a working solution!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*QY2iXprQcFqWOXHsEkWFig.gif" /></figure><p>Awesome, Right?! Nope.</p><p>So, this was my solution to the problem (this was a while ago, don’t judge me):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cFe9fp3f6KWwxJgW5GgAQ.png" /></figure><p>I was extremely proud to have a working solution but that didn’t last long. I took one look at the top couple of solutions submitted by other users and I felt like an idiot to say the least. I began to put myself down and question if I could ever become a good programmer. Thankfully, with persistence(no pun intended) I managed to leave that mindset behind.</p><p>Instead of telling myself that I’m stupid or that I lack what it takes, I spent a lot of time looking at other people’s code, especially ones that seemed extremely complex or baffling at first sight. I made sure to take time to break down problems into small solvable pieces and then bring those pieces together in an efficient whole.</p><p>Taking the “persistent bugger” problem as an example, I would break it down this way:</p><ol><li>I would check if “n” is smaller than 10; if it is, then the function will return 0.</li><li>If “n” is bigger than 10 then I would have to multiply the digits, for which I need to turn “n” into an array of digits I can manipulate. To do this I would turn the number to a string using .to_s 1989 =&gt; “1989” which enables me to split it in individual digits using string methods such as .split and .chars “1989” =&gt; [“1”, “9”, “8”, “9”].</li><li>Then I would .map over that array of digits(which are still strings at this point) and convert them into integers using .to_i.</li><li>Now that I have an array of integers that I can keep multiplying the array elements until I end up with a single digit, as the problem requires. .reduce is a prime candidate for achieving this.</li></ol><p>Now, if we take a peek at the top ranked solution for this problem on codewars:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsNnrXjKGQl23NlpNlzpGw.png" /></figure><p>The first time I saw this solution I just yelled “oh F*ck off” in frustration. Of course, this is a personal flaw that I acknowledge and try not to let get the best of me. We should never compare ourselves to others because we can never objectively nor accurately see the “full picture”. But looking at this same solution now, I find that it makes perfect sense and the use of recursion is massively important. Moreover, I am more than happy to have taken the time to understand how this solution works.</p><p>To break down how I read this solution now:</p><ol><li>Check if “n” is smaller than 10; if it is, then the function will return 0</li><li>Else, recursively call the persistence function and add 1 for each time the function is run.</li><li>When the recursion is done (the value of the recursion become smaller than 10 and the function has stopped calling itself) return the times 1 was added to itself.</li></ol><p><strong>Important note:</strong> the inner function call does not itself return anything; rather, the 1 just keeps incrementing with every call.</p><p>Another top-ranked solution that uses the same principle, but that I found to be more readable is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8iMV1UvUg6LZtwZjo7nAg.png" /></figure><p>While the two solutions above yield the same results, I found the second one to be more easy to comprehend because the recursion and condition to end the recursion are explicit. The former of the solutions is a bit more complicated(in my opinion) because the manner in which the recursion ends is not very clear at first sight, at least it wasn’t for me. And if you are still struggling to wrap your head around recursion properly (like me) you will definitely appreciate the added clarity in the second solution.</p><p>To conclude, as someone who hasn’t been coding for a long time, I think one of the biggest and most important lessons I’ve learned so far, is the need to breakdown and dissect complicated code. Not only will it help you learn new concepts, but looking at problems form different people’s point of view will help you immensely in looking at problems from multiple points and come up with different ways of solving those problems.</p><p>If you are interested in learning more about recursion, I would recommend you check out these resources:</p><ul><li><a href="https://www.codewars.com/kata/persistent-bugger">Persistent Bugger on Codewars</a></li><li><a href="https://medium.com/@amieeverett/recursion-for-dummies-8da0360d55ad">Recursion for Dummies</a></li><li><a href="https://medium.com/code-zen/recursion-demystified-24867f045c62">Recursion Made Simple</a></li></ul><p><strong>Happy coding!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93d332de6dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>