<?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 MAJ ALIJU on Medium]]></title>
        <description><![CDATA[Stories by MAJ ALIJU on Medium]]></description>
        <link>https://medium.com/@majalijunyc?source=rss-2d1aaa8287cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fO7SWkkKdMKBpztUITzn9w.jpeg</url>
            <title>Stories by MAJ ALIJU on Medium</title>
            <link>https://medium.com/@majalijunyc?source=rss-2d1aaa8287cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:02:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@majalijunyc/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[Do Less]]></title>
            <link>https://medium.com/@majalijunyc/do-less-1cafd33ca3fc?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cafd33ca3fc</guid>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[weight-loss]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[success]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Thu, 29 Jun 2023 17:38:29 GMT</pubDate>
            <atom:updated>2023-06-29T17:39:57.059Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUPh6BRNLHrr-0I-sH76cw.jpeg" /></figure><p>Yes, you read that right: do less!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXuncUZ5kl367gb4Kl0I3A.jpeg" /></figure><p>This post was sparked by a convo I was having with a close friend of mine yesterday, who is having a rough time with life in general. He’s got family issues, he’s got a small apartment full of people, his job is tough, and he’s going through health battles — the stress of all of these things combined just compounds itself and makes it all worse.</p><p>But to his credit, he’s been doing his best in cutting out certain bad habits! He’s recently cut out eating junk food, and started his day with a morning walk. He’s down over 30lbs and at his worst, he was over 350lbs.</p><p>I myself was over 300lbs at one point but lost 80lbs, doing the same things he did…the crazy part is that it wasn’t anything nuts or outlandish like running a marathon every day.</p><p>The truth is actually very boring, and it worked for myself, for my friend, for millions of others — in a world where everybody is hyper-competitive online and everyone is trying to out-lie the other person as to how much fun they have in a day or how much they do in a day, what if I told you the real key to success, and to having the most fun, is by doing less?</p><p>It’s true! The only caveat is: you gotta do that, everyday.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*oXNbdqLIERcMA032EqQrmQ.jpeg" /></figure><p>That’s right, and I’ve seen this first-hand in my own life with several different examples.</p><p>First, let me break down the picture at the top.</p><p>________________________________________________________________</p><p>In this basic graph, it shows the power of just 1% better every single day.</p><p>For those who aren’t into math, it’s nothing too crazy!</p><p>1.01 just means that “I was 1% better than yesterday” and that’s being multiplied by itself every single day, which is what the 365 is on the upper right. 365 days in a year, so 1.01 times 1.01, 365 times, just means “I did 1% better than the day before, for 365 days in a row, which is 1 year.”</p><p>1% isn’t a crazy amount at all. If you had $1000 and I gave you 1%, I’d be giving you $10. $10 compared to $1000 is more or less a raindrop in the ocean.</p><p>But the crazy part is that, over just one year, that made a huge difference.</p><p>If we’re talking in terms of your lifestyle or the live you want to live, just improving by 1% (a small and do-able amount) every single day, that means that you can live two completely different lives just two years apart.</p><p>I’m not here just theorizing to you based on algebra and conceptual psychology — I know the power of 1% improvement everyday because I’ve seen it first-hand with several different things!</p><p>________________________________________________________________</p><p>When it came to losing weight, which most people have tried to do, I like many others tried some hardcore experiments. Do several hours of cardio, limit calories to around 1500, etc. All this did was make the problem worse. I was over 300lbs and my life was so bad, I had to hold my breath to tie my shoe-laces. I was managing a million things over many years and I finally let it get to me because I kept all my problems to myself and just pushed forward. But it caught up to me.</p><p>It’s only when I finally kept it super boring and just said, “Ok 60 minutes of walking a day, and a small deficit in calories. These other ways are just making it worse. Let me just be boring with it.”</p><p>It took me a few but guess what?</p><p>I lost that weight for good and kept it off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWWCYaRytkXXbNAa4lKY6g.jpeg" /></figure><p>When I picked up guitar, or singing, I sucked in the beginning. I couldn’t play a basic chord or sing a clean melody, and it felt like I’d never be able to play a full song or sing anything at all.</p><p>But everyday, all I did was tell myself, I’ll do this for 30 minutes.</p><p>All I gotta do is just open up a YouTube video, and practice some chords (in the case of guitar) or just sing along to a beginner video for singing — for just 30 minutes everyday, no more, no less. If I do 20 minutes one day that’s ok, but I can’t skip a single day.</p><p>And what do you know?</p><p>Just one year later, I was able to play on stage and support some friends as a backup guitarist, and back-up vocalist. I was even able to hit open mics and sing much better than I expected.</p><p>Same thing with lifting weights, with learning a new language, with learning how to program, etc. I’ve seen it time and time again.</p><p>The key to everything is just do a small amount, but do that every single day. No big mountains to climb.</p><p>Just a boring little small amount, every single day.</p><p>You won’t even recognize yourself from one year ago!</p><p>And you’ll feel as good as this little girl does, that you did less for an entire year!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FedNiGE8xS28XvBQBUPBw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cafd33ca3fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phase5: Using Mapbox and/or React-Map-Gl; aka the End of the Road]]></title>
            <link>https://medium.com/@majalijunyc/phase5-using-mapbox-and-or-react-map-gl-aka-the-end-of-the-road-3438fd4742ae?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/3438fd4742ae</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-map-gl]]></category>
            <category><![CDATA[mapbox]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Mon, 01 May 2023 16:08:14 GMT</pubDate>
            <atom:updated>2023-05-01T16:08:14.434Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A quick prologue related to life and managing a difficult road:</em></p><p>After over a year of a very difficult stretch of time, with a Whitman’s Sampler assortment of different challenges thrown my way, I’ve finally reached the end of the road of Flatiron School. Just typing that makes me happy and it’s worth acknowledging, given that I famously downplay all accomplishments — as you too, reader, might be guilty of doing.</p><p>With that said, I’d like to offer some short-hand advice to anybody pursuing anything of a bootcamp-style nature, be it a programming boot-camp or a traditional army-style bootcamp, or any camp involving a boot.</p><p>Rule 1: <strong>drop everything else</strong>, it’ll make things much simpler. As a consequence of things being simpler, it’ll likely make them easier to manage overall. This isn’t always the case and it might be moreso a sign of my coffee kicking in that we could get into a pedantic aside on the precise differences between something being <strong>easy</strong> and something being <strong>simple, </strong>and the two not being tied by necessity….however, I’ll sum all of that up by saying <em>drop everything else except this.</em></p><p>I had a lot of challenges managing different spinning plates, which was emblematic of my life for the past twelve years outright. Only once I cut out the fat and accepted help from others, was I able to center myself in on this one thing and minimize the real-life stress I was causing myself. Burnout is a very real thing, and is more a symptom of an approach to things than it is a necessary consequence of a certain field/industry/hobby. One must truly simplify things and minimize one’s expected array_of_things_to_handle today in order to succeed at something long term.</p><p>With that said, you might here because you too have a problem with MapBox and React-Map-GL and I’m here to offer you some solutions in case you had the same issue I did.</p><p><a href="https://www.mapbox.com/">MapBox</a> is a very popular way for any developer to handle map-based stuff on their website. Given that it’s 2023, as of writing this, that pretty much means everything nowadays. If it doesn’t directly involve rendering a map to the user, it at least involves geocoding and serving the user things based on the user’s proximity to that given thing. So either way, it’s a safe bet you’ll be working with coordinates (lat, lng) and addresses at some point in your life.</p><p>Our daily lives involve a very heavy use of maps and geo-location, especially with the advent of smartphones. What used to be the domain of taxi driver’s brains and Rand McNally maps for road trips, is now the domain of any person who uses a phone. Your Uber ride involves maps and location, a Google search for the nearest Duane Reade involves maps and locations, the best bars around involves, yada yada yada. You can see that the modern day web user basically <strong><em>expects </em></strong>map rendering and automatic geolocation, as a consequence of being Pavlov’d into it by this point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-DDInNEe7TXnBwKBIcQuQ.png" /></figure><p>I myself created a capstone project called <a href="https://best-cocktail-app.onrender.com/">Cocktails?</a>, which is designed to get a user’s location and showcase all the bars around them. I seeded it with some real bars, but from my own API, and some real drinks that I added from the same place. Eventually I want to use a more popular API and auto-generate these things, and involve rankings somehow, but for the time being I knew that at a fundamental level all I need to make sure I’m doing is: getting a user’s location, rendering a map with points, and showing them bars based on the proximity to the user. Once that’s done then bigger things can built on top of it but that’s the fundamental requirements regarding the building of the app.</p><p>What I implemented for the map, is <a href="https://docs.mapbox.com/mapbox-gl-js/api/">MapBox GL JS</a>, which you can find here. However I went for a deeper option, given that I had to use Create-React-App (which I do have some qualms with) and use Uber’s implementation of a wonderful React wrapper for Mapbox called <a href="https://visgl.github.io/react-map-gl/">React-Map-GL.</a></p><p>To install it, assuming you have node 8 (or better) and React 16.3 (or better), just run:</p><pre>npm install --save react-map-gl mapbox-gl</pre><p>On top of that, you’ll have to place this at the top of the App.jsx file:</p><pre>/// app.js<br>import &#39;mapbox-gl/dist/mapbox-gl.css&#39;;</pre><p>And this one at the top of your index.html file:</p><pre>&lt;!-- index.html --&gt;<br>&lt;link href=&#39;https://api.tiles.mapbox.com/mapbox-gl-js/v&lt;YOUR_MAPBOX_VERSION&gt;/mapbox-gl.css&#39; rel=&#39;stylesheet&#39; /&gt;</pre><p><strong>As a major key for production on Render, make sure you include this in your index.css file:</strong></p><pre>.mapboxgl-canvas {<br>  position: absolute;<br>  top: 0;<br>  bottom: 0;<br>  left: 0;<br>  width: 100%;<br>  height: 100%;<br>}</pre><p>My map wasn’t showing at all in production until I included this in the index.css. It was showing in development but not in production, which is more important so make sure you throw that in there.</p><p>With that caveat and intro out of the way, implementing the map itself was fairly easy. In a parent component I simply included the Map just like would any standard component. (The className styling you see there is custom <a href="https://tailwindcss.com/">TailwindCSS</a> styling where I used some <a href="https://daisyui.com/">DaisyUI</a> styling- implementation. Highly recommend that as a UI library.)</p><pre> &lt;div&gt;<br>    &lt;MapGL className=&#39;flex flex-col justify-center w-full h-full&#39; /&gt;<br> &lt;/div&gt;</pre><p>Within the MapGL component itself, I made sure to include my custom MapBox token, which you can do by registering an account with MapBox and generating a custom token. Very easy to do and simple so I won’t waste time here.</p><pre>import * as React from &#39;react&#39;;<br>import { Map, Marker, Popup } from &#39;react-map-gl&#39;;<br>import { useContext, useState, useMemo, useEffect } from &#39;react&#39;;<br>import &#39;mapbox-gl/dist/mapbox-gl.css&#39;;<br>import Pin from &#39;./Pin&#39;;<br>import { useNavigate, Link } from &#39;react-router-dom&#39;;<br>/* eslint-disable import/no-webpack-loader-syntax */<br>import mapboxgl from &#39;mapbox-gl&#39;;<br>// @ts-ignore<br><br>import { UserContext } from &#39;../context/user&#39;;<br>import { BarsContext } from &#39;../context/bars&#39;;<br>import { AddressSubmittedContext } from &#39;../context/addressSubmitted&#39;;<br><br>const MAPBOX_TOKEN =<br>  &#39;{MY-CUSTOM-TOKEN-THIS-IS-ALL-FILLTER. TO PLACE YOURS, <br>JUST REMOVE THE BRACKETS AND MAKE SURE ITS ONLY A STRING.<br>WHEN YOU PUT IT IN PRODUCTION, PLACE THAT ELSEWHERE AND NOT IN THE OPEN}&#39;;<br><br>export default function MapGL({}) {<br>  const { user } = useContext(UserContext);<br>  const { bars } = useContext(BarsContext);<br>  const { addressSubmitted } = useContext(AddressSubmittedContext);<br><br>  const navigate = useNavigate();<br><br>  const [popupInfo, setPopupInfo] = useState(false);<br>  const [barPopUp, setBarPopUp] = useState(&#39;&#39;);<br><br>  const pins = useMemo(<br>    () =&gt;<br>      bars.map((bar, index) =&gt; (<br>        &lt;Link to={`/bars/${bar.id}`} state={{ bar: bar }}&gt;<br>          &lt;Marker<br>            key={`marker-${index}`}<br>            longitude={bar.longitude}<br>            latitude={bar.latitude}<br>            anchor=&#39;bottom&#39;<br>          &gt;<br>            &lt;Pin /&gt;<br>          &lt;/Marker&gt;<br>        &lt;/Link&gt;<br>      )),<br>    []<br>  );<br> <br>  return (<br>    &lt;Map<br>      initialViewState={{<br>        longitude: user.longitude,<br>        latitude: user.latitude,<br>        zoom: 10,<br>      }}<br>      style={{ width: 1000, height: 800 }}<br>      mapStyle=&#39;mapbox://styles/mapbox/dark-v11&#39;<br>      mapboxAccessToken={MAPBOX_TOKEN}&gt;<br>      &lt;Marker<br>        longitude={user.longitude}<br>        latitude={user.latitude}<br>        color=&#39;blue&#39;<br>      /&gt;<br>      {pins}<br>    &lt;/Map&gt;<br>  );<br>}<br></pre><p>In my version above here, I have my array of bar objects (bars) which I map over to create many distinct points on the app. Within each one, I generated a Link (via react-router-DOM) that sends it to a custom page that will show that bar specifically and all the drinks associated with that bar. Each Link nests a &lt;Marker /&gt; which is a React-Map-GL wrapper of their marker element, which generates a ping/marker/point on the map.</p><p>In the return statement below, I render the actual map itself which is initialized with my user’s latitude and longitude so it shows their location immediately. I generate a marker there to show where their location is exactly.</p><pre>const pins = useMemo(<br>    () =&gt;<br>      bars.map((bar, index) =&gt; (<br>        &lt;Link to={`/bars/${bar.id}`} state={{ bar: bar }}&gt;<br>          &lt;Marker<br>            key={`marker-${index}`}<br>            longitude={bar.longitude}<br>            latitude={bar.latitude}<br>            anchor=&#39;bottom&#39;<br>          &gt;<br>            &lt;Pin /&gt;<br>          &lt;/Marker&gt;<br>        &lt;/Link&gt;<br>      )),<br>    []<br>  );</pre><p>It’s here above in the pins that I set up the points that will be rendered, which is to say each bar that will link a custom bar page. It should be fairly simple to follow:</p><p>A <strong>Pin</strong> (the point we see) is wrapped by a <strong>Marker</strong>, which is itself wrapped by a <strong>Link</strong>. The <strong>Pin</strong> is the point we see, the <strong>Marker</strong> is the geolocation tag for that point, the <strong>Link</strong> is how it sends it to another page.</p><p>I still have new changes I’d like to add on top of this implementation, such as pop-ups that generate the bar.name and more info but due to a time crunch, I had to keep it simple. I look forward to learning more about these and not only using it in future projects but spicing up the Cocktails? app by throwing those new, cool features into this one!</p><p>All in all, I’ve had a great time challenging myself here at Flatiron and would like to thank some wonderful students and instructors I’ve met.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3438fd4742ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phase4: Validations aka “the Database’s Doorman”]]></title>
            <link>https://medium.com/@majalijunyc/phase4-validations-aka-the-databases-doorman-1f1521cc8ac1?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f1521cc8ac1</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[validation]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 01:17:17 GMT</pubDate>
            <atom:updated>2023-01-08T01:34:58.481Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Side-note: excited to have reached phase-4 and the full suite of full-stack experience. Couldn’t have imagined I’d be at this point just several months ago due to life factors but here I am!</em></p><p>How does a website know that your password is less than 8 characters long? How does it know that this username you like to use everywhere, was already chosen by someone else on this site? How does a website even know that 7 of something is good, or 3 of something is good, but not 0 of something, or -2 of something? Why should a website even know these things?</p><p>These questions are all answered thanks to something called <strong>validation</strong>.</p><p><em>(I’m personally a major fan of validation, in the sense that knowing it exists and utilizing it the right way makes me actively happy and enthusiastic. Often times during programming, there’s steps in the process that do the exact opposite (i.e. make one miserable) and this feeling is ubiquitous amongst developers, independent of skill level. So to find something that makes you/me/one happy is always exciting and/or encouraging!)</em></p><p>If this is your first time coming across the term then it’s essentially what it sounds like — data validation for database models. Validation just means <strong><em>“we cross-check some conditions against the data coming in to make sure all the data for this model is consistent.”</em></strong> The goal is to make that no ‘bad data’ can enter the database and create bugs, or any unwanted situations.</p><p><a href="https://guides.rubyonrails.org/active_record_validations.html">This is from the ActiveRecord guides:</a></p><blockquote><strong>Validations are used to ensure that only valid data is saved into your database.</strong></blockquote><blockquote>For example, it may be important to your application to ensure that every user provides a valid email address and mailing address. Model-level validations are the best way to ensure that only valid data is saved into your database. They are database agnostic, cannot be bypassed by end users, and are convenient to test and maintain. Rails provides built-in helpers for common needs, and allows you to create your own validation methods as well.</blockquote><blockquote>What’s another simpler way to think about it?</blockquote><p>As a former doorman in my younger years, I often served as the first line of defense for a building: vetting tenants, making sure delivery people were who they said they were, allowing friends and relatives to go upstairs to visit after initial check-ins, etc. I was the one who made sure that everybody who was in an apartment upstairs belonged there, and that nobody or nothing entered illegally. Life lesson for you: <em>It’s always easier to make sure something doesn’t get in than to try and get something out.</em></p><p>With that analogy in mind,<strong> validation is basically the doorman of a database.</strong> It conducts checks of certain conditions you set to make sure that no bad data can enter the database. One piece of data that doesn’t belong can either ruin a live site with render issues, cause havoc within the database itself when it tries to save new instances, break the entire thing and ruin any CRUD capabilities, etc. It can get very hairy very quickly, all from just <strong>one</strong> piece of data that doesn’t belong.</p><p>What’s an example of something requiring validation? I’ll use an example directly from an app I created called Ticketblaster, which is a project that works like Craigslist but for music-related things only — the way Ticketmaster does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bOqfvP7JWRMSQgpRO0N_iQ.png" /><figcaption>a user posting a ticket listing on Ticketblaster, with two entries (one for ticket-quantity, the other for a comment-body)</figcaption></figure><p>In the top section where it shows the number 0, that’s where a user will input how many tickets they either want to buy or sell. In the section below that, a user will enter a comment they’d like to leave to other viewers/users of the site — something where they’ll either list a price, or their phone number, or any regular message.</p><p>Let’s call the top section, <strong>ticketAmount,</strong> and the bottom section, <strong>commentBody</strong>.</p><p>Out the gate we know that ticketAmount can’t be something like “blue” or “Ludwig Wittgenstein” or “Erykah_Badu.” We know, for sure, it’s got to be a number. Not only does it have to be a number but, shoutout to my fellow mathematics majors in college, it has to be an integer above 0. So we can throw out the entire set of non-reals and reals below 1, and all non-integer numbers above 1. What that means in regular human terms is: it has to be a normal amount of tickets like you would really buy in real life! You’ve never bought -3 tickets or 1.56777738 of a ticket or 2i tickets!</p><p>What this means for our site though is that we can’t let a user enter any ticketAmount that isn’t something like 5 or 12 or 100 or 2 or 3 or yada-yada-yada. Now how can we make that happen automatically so that the system won’t even allow the users request to be processed until they enter the right number for <strong>ticketAmount</strong>? This is where we meet our friend, <strong><em>validations</em></strong>.</p><p>Let me prove it to you firsthand. In the example below, I am not able to submit -4 tickets or 2.3 tickets without seeing an error on the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KT_JuEY_cbYzNjt2bl93Q.png" /><figcaption>Attempting to submit a post for -4 tickets</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C5dB7vWgyqtW1HsiH_2wcA.png" /><figcaption>Attempting to submit a post for 2.3 tickets</figcaption></figure><p>Thanks to validations on the backend (in my case, a rails app) — I can set them so that they render errors that I can show to the user on the frontend! All while not saving the users new post to the database unless they meet the requirements I set, thanks to the validations. Let’s check out the backend for how I’m making this happen:</p><pre>class Post &lt; ApplicationRecord<br>  belongs_to :user<br>  belongs_to :concert<br><br>  validates :body, length: { minimum: 6}<br>  validates :tickets, numericality: { greater_than: 0, only_integer: true }<br><br><br>end</pre><p>Here I have a Post model: this is the Post that contains information about what a User posts to the site and it’ll always have a <strong>ticketAmount</strong> and <strong>commentBody</strong> that the user enters. The Post also contains information about the user and the concert that the post is for, but the user doesn’t enter that intentionally — I pull that information based on their user log-in and which concert they’re posting on. For the user, all they know is that they’re telling me (i.e. the database) how many tickets they either want to buy or sell (<strong>ticketAmount</strong>), and the comment they’re leaving on the site (<strong>commentBody</strong>).</p><p>On my backend, I called the <strong>ticketAmount</strong> just “<strong>tickets</strong>” and the <strong>commentBody</strong> is just “<strong>body</strong>.” Let’s start with the <strong>tickets </strong>first:</p><pre>validates :tickets, numericality: { greater_than: 0, only_integer: true }</pre><p>For any attribute (or column) within your model, you’ll write “validates :attribute_name” — then you can follow it up with the details of the validation. In my case, <strong>tickets</strong> needs to be an integer above 0. So after checking the <a href="https://guides.rubyonrails.org/active_record_validations.html#numericality">wonderful Active Record guides</a> I see that I need to check out the helper section that shows us numericality. Helpers here are basically details for the validations: they let you get more specific and really set your conditions for what type of data you’re looking to allow (or reject).</p><p>Here’s a screenshot from the Active Record Validation guide on the numericality helper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0td20_9uTrEvX8Sr4cZkcw.png" /></figure><p>What’s cool is that it allows me several types of options beyond saying just “this needs to be a number.” I can use <strong>only_integer</strong> which in my case is exactly what I need but it’s not everything just yet. Mathematically speaking, 0 is an integer and so is -3 and so is -1100 and so is yada-yada-yada. I can’t sell -5 tickets to a John Mayer or Freddie Gibbs concert (although it would be great to be able to scam the system like that), I can only buy or sell tickets in amounts like 1, 5, 3, 20, 5000, etc.</p><p>So on top of <strong>only_integer</strong>, I have to add another condition.</p><pre>numericality: { greater_than: 0, only_integer: true }</pre><p>By having <strong>greater_than</strong>: 0 I know that I’m only going to get (what we call colloquially) “real numbers.” With these two helper conditions, I know for sure that I’m not going to run into weird errors — the user can only enter normal numbers! If they try, my database won’t even save the post! Let’s check out what’s outputted in these cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*At8s1ojSUgPmJmMYnYToAw.png" /></figure><p>Let’s inspect what’s happening here. Once the user is sending a post, it’s going to “/new_post” which links to my PostsController and finds the create method, which is going to create a new instance of Post and save it to the database. Here’s my PostsController and the create method.</p><pre>  def create<br>    post = Post.create!(new_post_params)<br>    render json: post, status: 201<br>  end<br><br>....<br><br>  def new_post_params<br>    params.permit(:concert_id, :user_id, :for_sale, :tickets, :body)<br>  end</pre><p>Within it, I used Post.create! (with an exclamation mark at the end). I then send <em>new_post_params</em> to the Post.create! and these new_post_params are basically what the user is sending me (the database) from the frontend.</p><p>Using <strong>create!</strong> is important because it raises a RecordInvalid error if the validations fail. I can then call the errors saved by RecordInvalid and send them to my frontend to show to the user (as we saw above in my yellow boxes). With the regular <strong>create</strong> method, it will send back to the frontend the object<strong><em> regardless of if the object was saved or not.</em></strong> The validations will still work and not save that instance but for error-handling, it’s preferable to use create!.</p><p><a href="https://apidock.com/rails/ActiveRecord/Base/create/class">Here’s the create method:</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1srOqAqEIYVaPWfkVTp-Q.png" /></figure><p><a href="https://apidock.com/rails/v5.2.3/ActiveRecord/Persistence/ClassMethods/create!">And here’s the create! method:</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OOuoUgW1xRkK5IfJOlEGCg.png" /></figure><pre>class PostsController &lt; ApplicationController<br>  rescue_from ActiveRecord::RecordInvalid, with: :render_unprocessable_entity_response<br><br>.....<br><br>  def render_unprocessable_entity_response(invalid)<br>    render json: { errors: invalid.record.errors.full_messages }, status: :unprocessable_entity<br>  end</pre><p>In my PostsController, if the validations don’t pass then it’s going to switch over to RecordInvalid and go to the <em>render_unprocessable_entity_response</em> I’ve defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiPYy42Wh3-l2fz5ipJvOw.png" /></figure><p>So let’s check it out again. Within the PostsController#create method as I’ve written it, now the system is checking the parameters (the <em>new_post_params</em>). It starts to create the post and sees that the user_id is good, sees the concert_id is good, but once it gets to <strong>tickets</strong> it has to stop! I have submitted as my <strong>ticketAmount</strong> a value of -4…..these won’t pass the validations so it rolls back, goes to the RecordInvalid and now outputs the <em>422 Unprocessable Entity</em> error I’ve defined in the <strong>render_unprocessable_entity_response </strong>where it submits those errors back to the frontend.</p><p>Now I can tell the user to enter a real number automatically, without the whole database being compromised.</p><p>Now let’s go back to the <strong>commentBody</strong>, where the user enters the comment for their post. This one is simpler because I didn’t set any hard requirements for what a user should write: they can write a price, they can write a phone number, they can write whatever message they want to show to people. Their email-addresses already appear on every post so a user can contact whoever posted but I do want a user to leave a comment every-time, preferably to list a price or options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_e9ykfmQTkaTHCDbdSwKbA.png" /><figcaption>an error message telling the user to leave at least 6 characters</figcaption></figure><p>So now I’ve got the right <strong>ticketAmount</strong> (5 tickets, which passes my validations) but my <strong>commentBody</strong> is empty. I want the user to at least leave some type of message, even a phone number but I don’t want to burden them with having to leave a long message. They can leave ‘thanks’ or ‘asap!!!’ or ‘NEED!’ or ‘555–5555’ if they don’t really have something to write.</p><p>However if the user tries to submit nothing in the commentBody, it’s going to show the user an error that says the body is too short and that they need at least 6 characters. If the user wants they can enter “slakfdjhsdlkfh” but it will pass. <em>(It’s obviously not preferable to have useless messages like this but that’s another conceptual issue in website design and beyond the scope of my current site.)</em></p><p>So now we know we need some type of validation for the commentBody. I want 6 or more characters but don’t care too much about what else they enter. <a href="https://guides.rubyonrails.org/active_record_validations.html#length">So let’s check the Active Record Validations guide and that sends me to the length helper.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hd3i3Ot_Pj1Fw2BtAIZy5Q.png" /></figure><p>This much I’ll keep short since we covered this in the <strong>ticketAmount</strong> process but it’s basically the same thing — just this time, it checks that there’s minimum 6 characters. It gives me other options as far as how many characters I want and allows me to even write an optional message on top of it. I like the custom message also so I write something like this in my Post model:</p><pre>  validates :body, length: { minimum: 6, too_short: &quot;has to be %{count} letters! Leave a phone number or price&quot;}</pre><p>Thanks to <strong>validations</strong> though, I never have to worry that my database is full of compromised information!</p><p>That means that if somebody just hits SUBMIT but doesn’t enter anything or enters both pieces of bad information, they’ll immediately see two errors on the spot and change what they’re submitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPEx8RK5lmkPSLeIqZAHaA.png" /><figcaption>submitting with nothing in each input-box</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gksZJl9ydX87e0g4zMT86A.png" /><figcaption>submitting with a -4 and ww5 in each box; both wrong inputs</figcaption></figure><p>Hope this example helped you if you’re struggling with validations and cheers to you with whatever you’re working on!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f1521cc8ac1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Fun of ActiveRecord Associations, and The Journey That Lead Me to :includes]]></title>
            <link>https://medium.com/@majalijunyc/the-fun-of-activerecord-associations-and-the-journey-that-lead-me-to-includes-c15cabf0957?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c15cabf0957</guid>
            <category><![CDATA[sinatra]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Sat, 20 Aug 2022 01:09:48 GMT</pubDate>
            <atom:updated>2022-08-20T19:47:58.069Z</atom:updated>
            <content:encoded><![CDATA[<h3>Phase3: The Fun of ActiveRecord Associations, and The Journey That Lead Me to :includes</h3><p>I recently finished my first ever go-around of working with an ActiveRecord Sinatra-fueled backend and wow was it a pleasure!</p><p>Prior to this, I’ve been limited to (at best) a json-server backend which, while getting the job done for testing, is as bare-bones as can be. Enter ActiveRecord, which is a powerhouse compared to a json-server package! Not only is an ethos behind it (due to its association with Ruby, and <em>its</em> ethos of programmer happiness and doing things in a certain way to make life easier), but it’s also a cleverly designed system.</p><p>For anyone unfamiliar: ActiveRecord is an object-relational-mapping (ORM) system. ORM is a technique (and can even be argued, a philosophical approach to <em>‘things in the world’</em>) which has/contains/represents a thing (an object) and how it relates to other things. Pretty much any noun in your life can be represented by an object, and is related to other objects in some way.</p><p>For example: being a musician and a music lover, naturally I used music in my project and represented elements of music (which is abstract enough as is) through ORM. A <em>song</em> is an object, an <em>artist</em> is an object, a <em>genre</em> is an object, a <em>music review</em> is an object, a <em>music listener</em> is an object, etc. These are all things we know intuitively! All a system like ActiveRecord (or any ORM system) does is formalize these objects and relationships so that we can throw them into computers and perform operations/functions on them, and get results back.</p><p>Back to our example: a <em>song</em> is made by an <em>artist</em>, or multiple <em>artists</em>. That <em>song</em> belongs to a <em>genre**</em>, or multiple <em>genres</em>.<em> </em>A <em>song</em> can have many music <em>reviews</em>, and a <em>music listener</em> can listen to many <em>songs</em>. This can go on forever and ever with <em>music labels</em>, <em>albums</em>, <em>EPs</em>, etc.</p><p><em>**(Musically Accurate Side note: Genre-categorization itself might as well be an unofficial branch of philosophy as it is near impossible to define where a genre starts, begins, is rigorously defined. Genres are exemplative of the mathematical concept known as Fuzzy Boundaries.)</em></p><p>We deal with a similar concept in object-oriented programming — however we don’t explicate our relationships in OOP. Every object contains information about it all the way down, nested into it. The cool part of ORM and this approach is that every object contains all the essential information about itself within itself, and relies on relationships to tie other objects to itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*7z1kVENgtMJqpPTL3OFtmA.jpeg" /><figcaption>relational vs object-oriented</figcaption></figure><p>So even though a <em>song</em> has an artist in OOP, you can say in ORM that <em>song</em> and <em>artist</em> are each separate objects but they have a relationship to each other in certain situations. An <em>artist</em> makes many <em>songs</em>, and a <em>song</em> can be made by more than one <em>artist</em>.</p><p>For my project specifically I kept it simple and only had four objects: <em>songs</em>, <em>artists</em>, <em>genres</em>, and <em>reviews</em>. Below is my diagram of these objects and their relationships to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yJGUiZlJFJrALkit0u9uNw.png" /><figcaption>my ERD showing my objects and relationships</figcaption></figure><p>The way I chose to define my relationships was as such: a song belongs to an artist, since an artist can have many songs. A song also belongs to a genre, since a genre can have many songs. A song can have many reviews, as different people have different opinions about the song. As a Ruby rookie, I chose to keep it simpler as this is my first go-around with ActiveRecord; in reality, a song can belong to multiple genres, a song can belong to multiple artists.</p><p>One of the things I love about ActiveRecord is that when you define each object, you’re also defining its relationship to other objects immediately. At the top of each header, you’re defining whether A <em>belongs_to:</em> B, or if X <em>has_many:</em> Y, and so on. Something that struck me as interesting was that objects can have many of another object, through another object that ties the two to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*g3f4TOeEyntwX15wN34bDQ.png" /><figcaption>my Artist class</figcaption></figure><p>My Artist object/class has many genres through songs, even though there is no direct link between artist and genre. When you think about it, it’s true in the real world as well. An artist can just make a genre or express a genre out of thin air! They have to make or write a song, and then that song itself belongs to a genre. An artist can have many different genres over many songs, as legends like David Bowie showed us. The beauty of ActiveRecord is that there is a built-in method for these!</p><p>Such relationships happen so frequently that they’re defined in ActiveRecord as associations. This definition is from the Rails guide itself.</p><blockquote>In Rails, an association is a connection between two Active Record models. Why do we need associations between models? Because they make common operations simpler and easier in your code.</blockquote><p>One example of these common operations is the picture above: the <em>has_many through: association</em>. <em>:has_many </em>already exists as an association but <em>has_many through: </em>is like the marriage version of it. What I mean is that when you marry a person, their family now becomes your family. By blood you’re not connected to them, and in terms of memories in your life you barely have any with them when you first get married. But soon as you marry a person, immediately their family becomes part of your family. You have_many cousins :through your wife/husband. Many of who will probably ask you for money at some point!</p><p>With these in hand, I had a breeze writing my code. However, I hit one point where things became difficult for me and I couldn’t wrap my head around it. I tried writing my own methods but couldn’t get around how to do it cleanly, without using full Rails. This project was using only Sinatra and not full Rails so I had to be inventive with methods and my approach to things.</p><p>I knew because of these associations, that I should be able to access <em>artists</em> and <em>genres</em> through <em>songs</em> directly. I had many instances where I tested it out and I was able to access them. However once the moment came to export these out of the backend and send them to the frontend, that’s where I ran into issues. I was sending each object to a separate state in the frontend. While that was good for one element of my frontend, another more important element required me to have each song contain all the information about itself. I needed each song to have a sub-object(hash) that had its artist hash and its genre hash contained within itself, OOP style.</p><p>I spent <strong>days</strong><em> </em>scouring the internet on how to make this happen. Lo and behold, after a few days I found two amazing write-ups from (of all things) two Flatiron alumni! As poetic as that was, I was also grateful to finally come across someone who dealt with my situation before and at that, two people!</p><p><a href="https://medium.com/@coywreid/using-include-in-your-sinatra-application-controller-methods-fc42f297b560">https://medium.com/@coywreid/using-include-in-your-sinatra-application-controller-methods-fc42f297b560</a></p><p><a href="https://dev.to/nicm/including-associated-data-in-a-sinatra-api-response-4kko">https://dev.to/nicm/including-associated-data-in-a-sinatra-api-response-4kko</a></p><p>Major credit to both! I can’t aggregate all my failed methods and writeups, but I can show the result that saved me from losing my hair. In my GET request here, I was pulling all the songs in alphabetical order. In the second line, I added the (<em>include: </em>) to let the program know that I wanted other objects tied to <em>songs</em> to also be included within the object that was coming back to the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bf8BVHjv3_gwSZKCdKobRg.png" /><figcaption>my solution, and the beauty of include:</figcaption></figure><p>The major thing that helped me here was the syntax. I had tried a ridiculous amount of combinations trying to figure out the syntax. There’s barely any documentation on the <em>to_json</em> method so it took a lot of tinkering and trying to figure things out. Thanks to a fellow student (the 2nd link above), that’s where I learned that it’s bracket notation after the<em> includes:</em> .</p><p>It was a journey to get to this point! With that said, I’m excited to delve into Rails and see how many more methods and new techniques are open to me.</p><p>If you’re reading this having a similar :include issue, I hope this post helped and the links helped as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c15cabf0957" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phase 2: The Terrible Silver Lining of Deployment/Production]]></title>
            <link>https://medium.com/@majalijunyc/phase-2-the-terrible-silver-lining-of-deployment-production-c9153cc9118?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9153cc9118</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 23:19:08 GMT</pubDate>
            <atom:updated>2022-07-26T23:19:08.745Z</atom:updated>
            <content:encoded><![CDATA[<p>To preface this: I didn’t have a clue until Deployment/Production until the literal end of my React 2 Flatiron project, where I built a musical artist’s portfolio. I was initially going to talk about forms, state variables, the pros/cons of controlled components (and some alternatives to it) — all things that made themselves glaringly visible during the writing of my project.</p><p>However, all these things (in terms of frustration and confusion) paled in comparison to the iconic mess I experienced in trying to deploy and have a production build of my project. Even as I type this for submission, I know that I have yet to resolve a (relatively small) error regarding _redirects.</p><p>The bright side to all of this is: for the first time in my life, I actually got a full taste of what a developer/software-engineer’s daily life is like, and what tools one would be accustomed to.</p><p>As regards my project itself, this component here (<em>SongRequests</em> and its child component, <em>SongForm</em>) was the one that took up most of my time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhMRmY9lhGnWV105PTmYGQ.png" /><figcaption>the SongRequests component of my project</figcaption></figure><p>Most of the work here was in handling the form and the nuance required to do it well. It was here where I explored several options and touched up on the question of controlled components versus newer alternatives like <em>react-form-hook.</em></p><p>I had a state variable called <em>‘form’ </em>which was reading every keystroke from the user’s inputs of an Artist and a Song name, and updating the state of <em>form</em>. The purpose of this page was to receive a request for a cover song, and have the user enter each an artist’s name as well as that song’s name. Both items were stored as keys within the state variable object <em>form.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*NMceWPbv0JRfkS-DQXdHgQ.png" /><figcaption>the form state variable object</figcaption></figure><p>On this front is what took me a good week to figure out the right way to do things. The controlled component is what’s technically required by the project guidelines but the re-rendering every time could cause performance issues or other issues down the line. On top of that, I was running into issues in trying to make sure that the empty values of “” and “” weren’t passed as form’s key values. Beside John Cage and his famous 4&#39;33, nothingness has never really been a song people want to hear covered. Combine that with my first go-around at using ChakraUI to stylized and organize everything, it was a major headache. This form just wouldn’t behave properly: it would accept values but it would accept redundant ones as well, making the page look unprofessional.</p><p>Endless reading and consultation with current working developers lead me to check out <em>react-hook-form</em>, which isn’t fully controlled. As beautiful of a solution as it was, I found out I can’t technically use it for this project.</p><p>Yada yada yada — I thought this entire issue of the form would be the zenith of my difficulties in working on this project.</p><p>That is — until I finished and it was time to deploy and publish it.</p><p>For starters, I had my initial list of songs stored in a db.json file under the main object of songs.</p><pre>{</pre><pre>&quot;songs&quot;: [</pre><pre>{</pre><pre>&quot;artistName&quot;: &quot;Usher&quot;,</pre><pre>&quot;songName&quot;: &quot;U Remind Me&quot;,</pre><pre>&quot;id&quot;: 1</pre><pre>},</pre><pre>{</pre><pre>&quot;artistName&quot;: &quot;Hall and Oates&quot;,</pre><pre>&quot;songName&quot;: &quot;Sara Smile&quot;,</pre><pre>&quot;id&quot;: 2</pre><pre>},</pre><pre>{</pre><pre>&quot;artistName&quot;: &quot;David Bowie&quot;,</pre><pre>&quot;songName&quot;: &quot;Fascination&quot;,</pre><pre>&quot;id&quot;: 3</pre><pre>},</pre><pre>{</pre><pre>&quot;artistName&quot;: &quot;Marvin Gaye&quot;,</pre><pre>&quot;songName&quot;: &quot;Distant Lover&quot;,</pre><pre>&quot;id&quot;: 4</pre><pre>},</pre><pre>{</pre><pre>&quot;artistName&quot;: &quot;The Jones Girls&quot;,</pre><pre>&quot;songName&quot;: &quot;Who Can I Run To&quot;,</pre><pre>&quot;id&quot;: 5</pre><pre>}</pre><pre>]</pre><pre>}</pre><p>Every time during development, I had no issue as I used json-server to host this object at <a href="http://localhost:3000.">http://localhost:3000.</a> Without fail, I would be able to fetch my songs and display them on the page. It wasn’t until I had to deploy my information to Heroku that I saw the flaws in having my db.json in the same place as my create-react-app.</p><p>I had to go back to the initial instructions and fork a json-server-template, and populate that with my db.json object. I tried several versions of this entire process: from me copying my whole app’s contents into that new fork, vice versa (copying that fork’s contents into my-app), changing git upstream a few times, cloning and deleting several repos trying to figure out how to make this work in one location.</p><p>Eventually, I realized that the front-end is the front-end, and the back-end is the back-end. Maybe it would help to just treat each one as such, at least until I know better and pick up more developed technologies that can handle this in a professional way.</p><p>Pictured below is my current working solution, with the different repo (forked from the json-server-template and populated with my info) deployed to Heroku. That site specifically is being called. This is after I was almost literally pulling out my hair trying to fix environment variables and going back and forth between changing elements of node_modules, and .env files. It was just too much. Even after writing this, I’m sure I will see some flaw here and go back to fix it — however, at this current point in time, this is how it is and it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*dRptrBordOs7u87NbU12kw.png" /></figure><p>Production was a little simpler but still I ran into a good amount of issues: things ranging from CORS errors, to destructive (non)builds. In my speed of trying to solve this thing, I had limited screenshots left to show for my frustration. Had I collected all of them, I’d be at over 100 at absolute minimum and I say that with no hyperbole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZTf-0kIn7cNspVzQnlMMqg.png" /><figcaption>The CORS issue that wouldn’t leave me</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sLO0mmdgR4O1FeySpZGlg.png" /><figcaption>the ESlint error I ran into</figcaption></figure><p>I ran the gamut of technical issues and the funny part was that it had nothing to do with React, which was the entire focus of phase-2. Almost all of them were root-level style issues (package managers, server issues, http requests, etc). I say root-level for lack of a better phrase but I mean truly, these were all foundational things that forced me to learn a lot just in the days-long process of trying to deploy and produce this app. Having just published the app, there’s a lot I’m probably glossing over in my memory through the elation of having reached this step. In this moment of birth, I have forgotten the pains of the pregnancy so to speak.</p><p>My cool takeaway was that even though I had struggled immensely, and was thrown into the fire, I for the first time had a good grasp of what a software-engineer’s daily work might look like. Everyone tends to emphasize the ‘coding’ aspect of it, in a sense “writing new code everyday.” Which isn’t exactly the case — a lot of it appears to be the careful (emphasis on careful) implementation of new features by using production and development environments, the real-world usage of the apps/products that are being built, the real-world support teams required to address bugs and common issues, etc. I had veered away from the pure basement-dwelling nature of coding itself (coding away into the night’s long hours, all alone) and opened myself into what I imagine to be a common collaborative work environment, by seeing and using the tools first hand.</p><p>As frustrating as it was to have to learn a wide range of things in the span of a week, it was always in retrospect probably the most rewarding and also, the closest glimpse I have into an average day at work down the line.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9153cc9118" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phase 1 and How I Found About APIs the Hard Way]]></title>
            <link>https://medium.com/@majalijunyc/phase-1-and-how-i-found-about-apis-the-hard-way-cc09c45e8d73?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc09c45e8d73</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[code-newbie]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 01:57:00 GMT</pubDate>
            <atom:updated>2022-04-16T02:36:25.435Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Brief Preface</h4><p>I’m now about three months into my Flatiron School experience. While it’s been academically enriching, my personal life went through so many twists and turns that couldn’t have come at a worse time. I’ll spare the details for another blog post on another day but I say all that to make the point: I’m glad to have reached this point! Wish I could’ve done it sooner but I’m glad I’m here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sr77X5mgiHx4f4s9u5uUA.png" /><figcaption>the initial page of The Boredom Fixer</figcaption></figure><h4>My Second Choice</h4><p>I recently completed <a href="https://github.com/majaliju/im-bored">my first project</a> where I created <a href="http://majaliju.com/im-bored/">a simple page for a user</a> to explore a wide range of activities, ideally to solve the issue of boredom. A user could cycle through a wide range of activities, and if interested, be able to save the activity to a list. The save button would then be disabled to ensure no duplicates are added to the list.</p><p>As a lover of beautiful, sleek design but someone terribly novice at CSS and styling, I had to do my best to render a beautiful page. On the design side, I took some inspiration from Ramones (regarding the pink and black color scheme) and the NYC subway system both. As a NYC native living in Brooklyn but raised in Queens, I felt an obligation to represent NY. As is stereotypical of NY natives!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*s7biLqt7cUQVs3FqfN2Wfw.jpeg" /><figcaption>MTA Subway’s System use of Helvetica</figcaption></figure><p>†However, this project was not my first choice! I found out the hard way the limitations of API’s and the nuance required in one’s desired utilization of them.</p><p>On the Boredom Fixer project above, I used the the boredapi.com site and simply created a function that involved a fetch call on that API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe8c1426c54ac63edb01d39a967e6ac1/href">https://medium.com/media/fe8c1426c54ac63edb01d39a967e6ac1/href</a></iframe><p>That boredAPI hosted many objects. While I couldn’t access the higher-level object or array which hosted these smaller objects, I could access a single object using the /activity/ pathway on the API. A sample object looked like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50e3ce29b6906e19592c398919bd5ffe/href">https://medium.com/media/50e3ce29b6906e19592c398919bd5ffe/href</a></iframe><p>For my project, I called the <em>activity</em> key and the <em>type</em> key when demonstrating the activity. I personally would’ve loved to have more utility on the site and call other keys as well to demonstrate more information; however the keys/values here were very limited in terms of what they could provide regarding user experience.</p><p>For example: the <em>price</em> key wasn’t tied to a financial system, it was a decimal value. (Even then, if it was tied to a single currency more issues would arise in translating the ideal price of the user based on geolocation — a problem larger than the scope of my current abilities!) The <em>participants</em> key was limited to smaller numbers and didn’t make any philosophical or practical sense. For the given example above, one could watch a KhanAcademy video with a friend. So the information wasn’t as precise as it would be in reality.</p><p>As neat as this was to do, it was much simpler than I had aimed and I stillran into technical limitations on the APIs end as well: such as not being able to access the “super-object” of objects. Despite this, this was my cleanest experience as my original project showed me the dark side of APIs and authorization.</p><h4>My First Choice; Where APIs Bit Me</h4><p>My original desire was to host a music page that would receive the user’s choice of an artist/band, and then receive five similar artists/bands to check out that were similar. We’ve all run into the problem of knowing what type of sound we wanted to hear but not knowing where to turn. I wanted to solve a real problem and put forth some work on the end in my phase 1 project.</p><p>I had found <a href="https://tastedive.com/read/api">the ideal API to make that happen</a>. I tested a single line where I set my q key to “Michael Jackson” and found 20 artists similar. “Great, I’m set!” was my first thought. Then per my cohort lead’s recommendation, he recommend I do a slightly more rigorous test where I fetch’d it in my app and checked the console log.</p><p>That’s where I learned the hard truth about authorization limitations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zaTGJEJpJL2uo-Cf4JlHw.png" /><figcaption>my JS to test the API</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZ15cWIdC7iIppLtioJu-w.png" /><figcaption>my console log after fetch testing the API</figcaption></figure><p>I was shocked. API’s and back-end based work isn’t my strong suit at all but I was sure it would’ve worked. After all, when I entered that same URL into my browser I got a JSON object that showed me 20 similar artists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*M4aLY6kprDBsOdgt_u-MyQ.png" /><figcaption>the JSON object, after the URL being entered into my browser</figcaption></figure><p>I was slightly dejected but not dismayed completely: I knew that I might just have to make a slight adaption and then my code would be running. I knew that this thing that I was seeing for the first time, CORS, had to be the element I had to deal with.</p><p>After scouring the internet for many minutes, I still couldn’t fix the issue. I even elaborated the fetch request and listed out its elements. I knew that by default a fetch request was a GET request but still figured that “if I elaborate it and fix these parameters, I should be set.” Below is a sample example of the code I wrote, hoping it would fix my issue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdf5630dcf7d90669f71f0e1c0b0e5bc/href">https://medium.com/media/cdf5630dcf7d90669f71f0e1c0b0e5bc/href</a></iframe><p>I figured I could just set the mode to “no-cors” so I could disable the CORS requirement. Surely, this would fix my API issue!</p><p>Low and behold, it didn’t. In my haste to make this work, and in my limited understanding of the full depth of client-side and server-side, my eyes had brushed over the fact that “CORS is a client-side” issue had popped up on many pages of my research. While we had delved into server-side and client-side at moments in the curriculum, I didn’t fully appreciate the limitations and figured that it was just a gap in my own understanding. So I headed to office hours to get a better sense of what to do.</p><p>There at office hours, I spoke to Nancy and she informed that this is beyond my scope. I should save my time and just choose a different API that required NO authorization at all. My cohort lead Michael had mentioned that I should avoid OAuth, which was great advice, but Nancy took it a step further and said avoid all authorization for this phase.</p><p>I took her advice and found a different API, and was able to work out the project and proceed onwards. Had I not jumped into office hours, my persistence would’ve worked against me. Determination has an ugly side, that rears its head when one is determined yet on the wrong path.</p><p>I found many APIs but none that appealed in a way that an activity generator did. I’m an active person and never personally struggle with boredom. However, I also had phases in my life where I was immensely bored and always looking for something to do. Just because I’m now on the side of “I don’t have enough time” doesn’t mean I don’t remember the days of “How do I kill time?” So I figured: if I’m going to pursue a project, I’d like to at least be one that is semi-relevant.</p><p>I’m excited to move into React and Phase 2, and develop a better understanding of the full stack. I can’t wait to look forward to the moment where I understand how to properly manage the CORS issue and have an understanding of why it exists!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc09c45e8d73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I’ve learned one week into Flatiron]]></title>
            <link>https://medium.com/@majalijunyc/what-ive-learned-one-week-into-flatiron-2ee04167b23a?source=rss-2d1aaa8287cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ee04167b23a</guid>
            <dc:creator><![CDATA[MAJ ALIJU]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 01:48:36 GMT</pubDate>
            <atom:updated>2022-01-13T01:48:36.253Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, my name is Maj Aliju and I’m about one week into my experience at Flatiron. I won’t get deep into why I started (we’ll save that for another post) but I do want to write this down and note something of interest.</p><p>So far, the biggest issue I’ve had as far as running into any problems, or something taking more time than it should, was: I wasn’t thinking simply enough.</p><p>I was assuming the answer should be more difficult than what the answer actually was.</p><p>As an example, I had a small exercise regarding CSS selectors and specificity. I’ll show examples with code, below.</p><p>Here, I have some HTML detailing elements that are graffiti on a wall. The goal is to eliminate the graffiti by using CSS on a separate page.</p><pre>&lt;body&gt;</pre><pre>&lt;div id=&quot;wall&quot;&gt;</pre><pre>&lt;div class=&quot;tag-1&quot;&gt;&lt;/div&gt;</pre><pre>&lt;div id=&quot;tag-2&quot;&gt;&lt;/div&gt;</pre><pre>&lt;div id=&quot;tag-3&quot; class=&quot;slick wicked&quot;&gt;&lt;/div&gt;</pre><pre>&lt;div class=&quot;parent&quot;&gt;</pre><pre>&lt;div id=&quot;tag-4&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div class=&quot;parent&quot;&gt;</pre><pre>&lt;div id=&quot;tag-5&quot; class=&quot;slick&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div class=&quot;parent&quot;&gt;</pre><pre>&lt;div&gt;&lt;/div&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;div id=&quot;tag-6&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div class=&quot;parent&quot;&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;div id=&quot;tag-7&quot; class=&quot;slick&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div&gt;&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><p>The thing that’s big here is that there’s 2 separate CSS pages: one that renders the graffiti (paint.css) and another one that’s meant to override the graffiti (cleanup.css). The goal of the exercise is to get you to understand specificity by using stronger and more specific CSS selectors to override the contents of paint.css.</p><p>I was able to tackle 3 out of 6 selectors but ran into a (pun un-intended) wall trying to override the remaining 3. (Side note: the 7th piece of graffiti <em>(#tag-7)</em> seems to be a Banksy piece that was intended for the wall so I left that one alone.)</p><p>For reference, here’s the selectors from the paint.css file.</p><pre>.tag-1 {</pre><pre>background: url(https://medium.com/images/tag-1.png) no-repeat;</pre><pre>z-index: 7;</pre><pre>display: block;</pre><pre>}</pre><pre>#wall #tag-2 {</pre><pre>background: url(https://medium.com/images/tag-2.png) no-repeat;</pre><pre>z-index: 6;</pre><pre>display: block;</pre><pre>}</pre><pre>div#wall #tag-3.slick {</pre><pre>background: url(https://medium.com/images/tag-3.png) no-repeat;</pre><pre>z-index: 5;</pre><pre>display: block;</pre><pre>}</pre><pre>#wall #tag-4 {</pre><pre>background: url(https://medium.com/images/tag-4.png) no-repeat;</pre><pre>z-index: 4;</pre><pre>display: block;</pre><pre>}</pre><pre>div#wall .parent #tag-5.slick {</pre><pre>background: url(https://medium.com/images/tag-5.png) no-repeat;</pre><pre>z-index: 3;</pre><pre>display: block;</pre><pre>}</pre><pre>div#wall div.parent div:last-child div#tag-6 {</pre><pre>background: url(https://medium.com/images/tag-6.png) no-repeat;</pre><pre>z-index: 2;</pre><pre>display: block;</pre><pre>}</pre><p>After trying out several re-formatted versions and poring through Google, it finally clicked as the name of the specificity principle shone its way into my eyes: “be more specific.”</p><p>In several cases all I had to do was just detail a level above that tag, in several cases this was as simple as identifying the html element “body” before it.</p><p>At this nascent stage of my coding life, this is what I believe was the fix here. Only time will tell if I was wrong or if I was more ahead than I gave myself credit for, in understanding the simplicity required.</p><p>Either way, it’s a fun journey to embark upon!</p><p>Thank you for reading — and I look forward myself to reading this months from now. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ee04167b23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>