<?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 Lionel Mason, MPA on Medium]]></title>
        <description><![CDATA[Stories by Lionel Mason, MPA on Medium]]></description>
        <link>https://medium.com/@lionelmason?source=rss-14091d115a96------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6p1QrqsdDBHDuWJVNnTQlg.jpeg</url>
            <title>Stories by Lionel Mason, MPA on Medium</title>
            <link>https://medium.com/@lionelmason?source=rss-14091d115a96------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:17:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lionelmason/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[Building a Weather & Climate Intelligence Application, Part 2: Designing the V1 System Architecture]]></title>
            <link>https://lionelmason.medium.com/building-a-weather-climate-intelligence-application-part-2-designing-the-v1-system-architecture-f53c1c5cea91?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/f53c1c5cea91</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[climatetech]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 22:41:24 GMT</pubDate>
            <atom:updated>2026-10-22T22:41:24.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOgwtSUB2RyTC6H3z3UmYg.png" /></figure><p>In Part 1, I established the data foundation for the application by identifying the environmental parameters I needed and selecting the services that could provide them. That answered where the data would come from, but it introduced a different problem: how should those services actually work together inside an application? Although React could communicate directly with each API, doing so would tightly couple the frontend to multiple external services and their individual data structures.</p><p>Open-Meteo<br>├── Current weather<br>├── Hourly forecast<br>├── Daily forecast<br>├── Historical weather<br>└── Climate projections</p><p>NWS<br>└── Official U.S. alerts</p><p>Stadia Maps<br>└── Basemap tiles</p><p>PostgreSQL<br>└── Persistent application data</p><p>Each system serves a different purpose and exposes data differently. Rather than allowing the frontend to become responsible for understanding each external service independently, I needed to define clear boundaries between the frontend, backend, database, and external providers.</p><h4>Defining the Application Layers</h4><p>USER<br> ↓<br>Next.js / React<br> ↓<br>Django / Python<br> ├── PostgreSQL<br> ├── Open-Meteo<br> └── NWS</p><p>Separate mapping path:</p><p>React<br>↓<br>React Leaflet<br>↓<br>Leaflet<br>↓<br>Stadia Maps</p><p>React — Handles the presentation and interaction.</p><p>Django — The application intelligence layer that will handle validation, provider communication, normalization, analytics, authentication, and database operations.</p><p>PostgreSQL — Persistent application memory.</p><p>External Services — Weather, historical, climate, alert, and mapping data.</p><h4>Creating a Backend Boundary Between React and External APIs</h4><p>If the application architecture connected React directly to external APIs such as Open-Meteo and NWS, React would be responsible for understanding and managing the different data structures, requirements, and behaviors of each provider. This would tightly <a href="https://www.geeksforgeeks.org/software-engineering/software-engineering-coupling-and-cohesion/">couple</a> the frontend to those external services and make the application more difficult to maintain as it evolves.</p><p>By placing <strong>Django</strong> between React and these external providers, the frontend can communicate using the application’s own data structures while Django handles provider-specific communication, validation, normalization, and business logic.</p><p>This backend boundary also strengthens security by preventing the browser from communicating directly with PostgreSQL; Django authenticates and authorizes users, validates requests, and controls which database operations the application is permitted to perform.</p><h4>Designing the Application Data Flow</h4><p>With the application layers defined, the next step was determining how data would move between them. Location became the common starting point. Whether a user selects their current location, enters one manually, or chooses a saved location, the application ultimately resolves that selection to latitude and longitude coordinates.</p><p>For the Home screen, React can send those coordinates to a single application endpoint:</p><pre>GET /api/v1/home?latitude=…&amp;longitude=…</pre><p>Django can then use those coordinates to retrieve current, hourly, and daily weather data from Open-Meteo while also checking NWS for applicable U.S. weather alerts. Instead of passing those provider responses directly to React, Django normalizes them into a consistent, application-owned response.</p><p>This means React does not need to understand how Open-Meteo and NWS structure their APIs independently. It only needs to understand the data contract defined by the application. The same location coordinates can also support other parts of the system, including historical weather, climate projections, and map visualization.</p><h4>Separating Persistent and Environmental Data</h4><p>Another architectural decision was determining what information actually needed to be stored in PostgreSQL. Although the application will work with large amounts of weather and climate data, storing all of that environmental data in the application database would unnecessarily duplicate information already available from external providers.</p><p>PostgreSQL will instead store persistent application data: user accounts, resolved locations, and the relationships between users and the locations they save, prefer, or recently select.</p><p>USER ──────&lt; USER_LOCATION &gt;────── LOCATION</p><p>Weather forecasts, NWS alerts, historical weather, and climate projections will generally remain external data retrieved when needed. For example, saving New York as a preferred location requires the application to remember New York and its relationship to the user; tomorrow’s temperature in New York does not need to become a permanent database record.</p><p>This separation keeps PostgreSQL focused on information the application owns and needs to remember, while environmental providers remain responsible for supplying the environmental data they specialize in.</p><h4>Designing for Resilience and Moving Toward Implementation</h4><p>The final consideration was how the application should behave when every service does not respond as expected. Because the system depends on multiple external providers, one unavailable service should not automatically make the entire application unusable.</p><p>For example, if Open-Meteo successfully returns weather data but NWS is temporarily unavailable, the Home screen should still display the available forecast while indicating that alert information could not be retrieved. Similarly, receiving no active NWS alerts is a successful response — not an error. Designing around these distinctions allows individual parts of the application to fail without unnecessarily taking the rest of the experience with them.</p><p>With these decisions made, the V1 architecture now has clear boundaries. React handles the user experience, Django coordinates application logic and external data, PostgreSQL stores information the application needs to remember, and specialized providers remain responsible for supplying weather, climate, alert, and mapping data.</p><p>The next step is implementation. Rather than attempting to build the entire system at once, I plan to begin with a small vertical slice:</p><p><strong>Location → Next.js / React → Django → Open-Meteo → Normalized Response → Current Conditions</strong></p><p>This will test the core path through the architecture before additional capabilities are layered on top. From there, the application can grow incrementally while maintaining the boundaries established during the design process.</p><p>In Part 3, I’ll begin implementing this architecture by building the first vertical slice from location selection through the backend to current weather conditions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f53c1c5cea91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Weather & Climate Intelligence Application, Part 1: Designing the Data Foundation]]></title>
            <link>https://lionelmason.medium.com/building-a-weather-climate-intelligence-application-part-1-designing-the-data-foundation-7d025b47e389?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d025b47e389</guid>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[climatetech]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Fri, 25 Sep 2026 17:33:27 GMT</pubDate>
            <atom:updated>2026-09-25T17:33:27.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Hurriccane Sandy 2012" src="https://cdn-images-1.medium.com/max/640/1*_VK9KO6_z5KRxxSOchcPvQ.jpeg" /><figcaption>NYC flooding following Hurricane Sandy, October 30, 2012. Photo by <a href="https://www.flickr.com/photos/ruanon/8155031913/">Patrick McFall</a> / Flickr, licensed under <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA 2.0</a>.</figcaption></figure><p>In October 2012, Hurricane Sandy brought severe flooding and widespread damage across parts of New York and the surrounding region. My own neighborhood was significantly affected. Seeing the impact first hand changed the way I thought about weather—not simply as something we check before leaving the house, but as information that can directly affect how communities prepare for disruptive events.</p><p>That experience planted an early idea: what if weather data could be used not only to describe current conditions, but also to help people better understand what may come?</p><p>Years later, that idea has evolved into the weather and climate intelligence application I am building today.</p><p>The initial version won’t attempt to predict the next hurricane. Instead, I am focusing on the data foundation first: current weather conditions, forecasts, historical weather data, climate information, official weather alerts, and geographic visualization. Over time, I want to explore how historical patterns, climate trends, statistical analysis, and eventually predictive models can turn the underlying data into increasingly useful location-specific intelligence.</p><p>The long term question behind the project is simple: <strong>Can we turn increasingly available weather and climate data into information that helps people better understand and prepare for the environmental risks around them?</strong></p><h3>Defining the Data the Application Actually Needs</h3><p>Before I could build an application capable of accomplishing that vision, I first had to determine what kinds of data it would actually need. As I worked through the concept, I realized that “weather data” wasn’t a single requirement. This application would need several distinct categories of data, each serving a different purpose.</p><p>Initially, “weather data” seemed like a relatively straightforward requirement. I would need the current temperature, precipitation, humidity, wind conditions, and a forecast. But as I began defining what I wanted the application to eventually accomplish, the data requirements became much broader.</p><h4>Current Conditions</h4><p>What is happening at a user’s location right now? Current conditions provide the application’s starting point by giving users an immediate view of temperature, humidity, precipitation, wind, and other conditions affecting their location.</p><h4>Forecast Data</h4><p>What conditions are expected in the coming hours and days? Forecast data moves the application beyond describing the present and allows users to anticipate changing conditions and plan accordingly.</p><h4>Historical Weather Data</h4><p>Past conditions provide context that current conditions alone cannot. Historical data makes it possible to compare present conditions with previous years, establish baselines, identify patterns, and eventually calculate trends and anomalies.</p><h4>Climate Data</h4><p>Weather describes atmospheric conditions over relatively short periods, while climate examines patterns over much longer periods. Climate data allows the application to move beyond historical weather and explore longer-term trends and modeled future conditions.</p><h4>Official Weather Alerts</h4><p>For potentially dangerous conditions, I wanted the application to rely on authoritative watches, warnings, and advisories rather than attempting to generate its own emergency alerts. This creates a separate requirement for official alert data tied to a user’s location.</p><h4>Geographic Data</h4><p>Weather is inherently geographic. Coordinates allow the application to connect a user’s location with weather conditions, forecasts, alerts, and eventually other location-specific environmental information. Geographic visualization can then give that information spatial context on a map.</p><p>Breaking the problem into these categories changed the way I approached the API research. Instead of looking for a single service that could do everything, I could evaluate each data requirement independently and determine which source was best suited for that responsibility.</p><p><strong>Application Data Requirements → Data Source</strong></p><p>Current Conditions + Forecast Data → <strong>Open-Meteo Forecast API</strong><br>Historical Weather Data → <strong>Open-Meteo Historical Weather API</strong><br>Climate Data → <strong>Open-Meteo Climate API</strong><br>Official Weather Alerts → <strong>National Weather Service (NWS) API</strong><br>Geographic Visualization → <strong>Leaflet + Stadia Maps</strong></p><p>Once the data requirements were separated, the technology decisions became much clearer. Rather than forcing a single provider to handle every responsibility, I began evaluating services based on the specific type of data the application needed. That research ultimately led me to a small group of technologies that could collectively form the application’s initial data foundation.</p><p><strong>Open-Meteo</strong> would provide current conditions, forecasts, historical weather data, and climate-model data. The <strong>National Weather Service (NWS)</strong> would provide authoritative U.S. weather alerts. <strong>Leaflet</strong>, paired with <strong>Stadia Maps</strong> as the basemap provider, would provide the geographic visualization layer needed to give weather and alert data spatial context.</p><h4>What I Learned</h4><p>The biggest takeaway from this first phase wasn’t about any particular API. It was realizing that choosing technology should come after defining what the application actually needs.</p><p>I started this process thinking primarily about weather data. By the end of the research phase, I was thinking in terms of distinct data responsibilities: operational forecasts, historical conditions, climate information, authoritative alerts, and geographic context.</p><p>With those responsibilities defined and the initial data sources selected, the next challenge is determining how all of these pieces should work together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d025b47e389" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[STRIPE INTEGRATION IN A REACT APP WITH RAILS API]]></title>
            <link>https://lionelmason.medium.com/stripe-integration-in-a-react-app-with-rails-api-af7614867fc0?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/af7614867fc0</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[stripe]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 00:43:43 GMT</pubDate>
            <atom:updated>2023-11-04T00:43:43.428Z</atom:updated>
            <content:encoded><![CDATA[<h3>STRIPE INTEGRATION WITH RUBY ON RAILS API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJ0IyyafxbThcs_SedrO2Q.jpeg" /><figcaption>SHAMBLES ~ Harlem, NY.</figcaption></figure><p>Stripe payment processing is a small-business favorite — especially in e-commerce industries — for its quick onboarding of merchant services, advanced reporting tools, fast payouts through its Instant Payouts option and transparent pricing structure. Stripe offers more customization and I currently use it for one of my small businesses and decided to share the process of implementing the payment processing into my e-commerce application.</p><p><strong>Step 1: Setup a stripe account:</strong></p><p><a href="https://dashboard.stripe.com/login">https://dashboard.stripe.com</a></p><p><strong>Step 2: Add the stripe gem to your Gemfile:</strong></p><pre>gem &#39;stripe&#39;</pre><p><strong>Step 3: Create a stripe.rb file:</strong></p><p>Create a config/initializers/stripe.rb file with the following code:</p><pre>Rails.configuration.stripe = { <br>  :publishable_key =&gt; ENV[&#39;STRIPE_PUBLISHABLE_KEY&#39;],<br>  :secret_key =&gt; ENV[&#39;STRIPE_SECRET_KEY&#39;]<br>} <br>Stripe.api_key = Rails.configuration.stripe[:secret_key]</pre><p>The above code is storing the Stripe publishable key and secret key which can be retrieved from your Stripe Developers &gt; API keys.</p><p><strong>Step 4: Controller &amp; Routes:</strong></p><p>Generate a controller and setup your route(s):</p><pre>rails g controller ClientSecretController</pre><pre># config/routes.rb<br><br>Rails.application.routes.draw do<br>  # ...<br>  post &#39;create_payment_intent&#39;, to: &#39;client_secret#create&#39;<br>  # ...<br>end</pre><p>You don’t necessarily need to create a model specifically for handling payments, especially if your application’s primary purpose is not centered around managing payments and you’re using Stripe’s API directly.</p><p>Our Ruby on Rails controller will be used for handling a request to create a payment intent using the Stripe API:</p><pre>require &#39;stripe&#39;<br><br>class ClientSecretController &lt; ApplicationController<br>    <br>    def create<br>        begin<br>            Stripe.api_key = ENV[&quot;STRIPE_SECRET_KEY&quot;]<br>            intent = Stripe::PaymentIntent.create({<br>                :amount =&gt; 2000,<br>                :currency =&gt; &#39;usd&#39;,<br>                :payment_method_types =&gt; [&#39;card&#39;]<br>            })<br>            render json: {client_secret: intent.client_secret}<br>        rescue Stripe::CardError =&gt; e<br>        # Handle card errors<br>            render json: {error: e.message, code: e.code}, status: :unprocessable_entity<br>        rescue Stripe::StripeError =&gt; e<br>        # Handle other Stripe errors<br>            render json: {error: e.message}, status: :unprocessable_entity<br>        rescue =&gt; e<br>        # Handle other unexpected errors<br>            render json: {error: &quot;An unexpected error occurred.&quot;}, status: :internal_server_error<br>        end<br>    end<br>end</pre><ul><li>First, we will require ‘stripe’ — This line is importing the Stripe Ruby gem, which is a library that allows you to interact with the Stripe API in your Ruby code.</li><li>Second, ` class ClientSecretController &lt; ApplicationController ` defines new class ClientSecretController that inherits from ApplicationController .</li><li>def create — defines our create method which will set up our POST request.</li><li>Next, Stripe.api_key = ENV[&quot;STRIPE_SECRET_KEY&quot;]: This sets the Stripe API key to be used for authentication. It retrieves the API key from an environment variable STRIPE_SECRET_KEY.</li><li>intent = Stripe::PaymentIntent.create({ ... }): This line makes a request to create a Payment Intent using the Stripe API. A Payment Intent represents a payment attempt. It includes details like the amount, currency, and payment method types.</li><li>render json: {client_secret: intent.client_secret}: This line sends a JSON response back to the client. It includes the client_secret property of the created Payment Intent. The client_secret is a unique key generated by Stripe that is used on the client side to authenticate the payment attempt.</li><li>I am using begin because I am interacting with external services (Stripe API), which may potentially raise exceptions (such as Stripe::CardError or Stripe::StripeError) if something goes wrong during the payment process.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*B8CBqmn5urtzSTb3sDMnxQ.jpeg" /></figure><p>Overall, this controller handles a request to create a Payment Intent using the Stripe API. It authenticates with the Stripe API using a secret key, creates a Payment Intent with specific details, and then sends back the client_secret for further processing on the client side.</p><p>Using begin and rescue allows us to handle exceptions that might occur during the execution of the code, ensuring that the application doesn&#39;t crash when encountering unexpected situations.</p><p>You have officially setup A Stripe API for payment processing with your Rails backend. Keep in mind this blog is written with the purpose to work with the Stripe API to create a payment intent. You don’t necessarily need to create a model specifically for handling payments, especially if your application’s primary purpose is not centered around managing payments and you’re using Stripe’s API directly.</p><p>-Till next time.</p><p><a href="https://kinsta.com/blog/list-of-credit-card-declined-codes/#:~:text=If%20the%20very%20first%20digit,entering%20an%20invalid%20card%20number">https://kinsta.com/blog/list-of-credit-card-declined-codes/#:~:text=If%20the%20very%20first%20digit,entering%20an%20invalid%20card%20number</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af7614867fc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Redux State: Centralized State Management in React Applications]]></title>
            <link>https://lionelmason.medium.com/understanding-redux-state-centralized-state-management-in-react-applications-82b92f5d7453?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/82b92f5d7453</guid>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Tue, 30 May 2023 13:14:59 GMT</pubDate>
            <atom:updated>2023-05-30T13:16:09.229Z</atom:updated>
            <content:encoded><![CDATA[<h3>Redux State</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iNV0HRaGzow6tr7xW_QO5Q.png" /><figcaption>Understanding Redux State: Centralized State Management in React Applications</figcaption></figure><p>In modern web development, managing application state is a crucial aspect. As applications grow in complexity, maintaining and synchronizing state across different components can become challenging. This is where Redux, a powerful state management library, comes into play. Redux provides a predictable approach to managing application state, making it easier to debug, test, and scale React applications. In this blog, we will explore the fundamentals of Redux state and its benefits.</p><p><strong>What is Redux State?</strong><br>Redux state refers to the data stored in the Redux store, which serves as a single source of truth for an entire application. Unlike local component state that is limited to a specific component’s scope, Redux state is accessible across components, making it ideal for sharing data between different parts of an application.</p><p><strong>The Redux Store</strong>:<br>At the core of Redux is the store, which holds the application state. The store is created using the `createStore` function provided by Redux. It represents a JavaScript object that contains all the data needed by the application. Components can access and update this state by dispatching actions.</p><p><strong>Actions and Reducers:</strong><br>Actions are JavaScript objects that describe an event or user interaction in the application. Actions carry information about what happened and the data associated with it. When an action is dispatched, it flows through the reducers.</p><p>Reducers are functions responsible for updating the application state based on the dispatched action. Each reducer handles a specific part of the state and specifies how it should be updated. Redux follows the principle of immutability, meaning that reducers create new state objects instead of mutating the existing ones.</p><p><strong>Updating the State:</strong><br>To update the state, reducers take the current state and an action as parameters and return a new state object. This ensures that state updates are predictable and traceable. Redux enables a unidirectional data flow, where actions trigger state updates through reducers.</p><p><strong>Connecting Components:</strong><br>To access Redux state and dispatch actions from a component, the `connect` function from the `react-redux` library is used. By connecting a component to the Redux store, it becomes a “container component” that can access the state and dispatch actions via props. When the state changes, connected components are automatically re-rendered with the updated data.</p><p><strong>Top 3 Benefits of Redux State:</strong><br>1. Centralized State: Redux promotes a single source of truth, making it easier to manage and synchronize application state across components. It eliminates the need for complex data flow patterns and enables predictable behavior.</p><p>2. Scalability: As applications grow, managing state becomes more complex. Redux provides a scalable solution by enforcing a structured approach to state management. Developers can easily add new features or modify existing ones without worrying about state conflicts or having to pass state continuosly via props (cleaner code).</p><p>3. Debugging and Testing: With Redux, debugging becomes more straightforward as the entire application state is centralized. Redux DevTools provide powerful debugging capabilities, allowing you to inspect and replay actions. Additionally, testing becomes easier since components can be tested independently without mocking complex state setups.</p><p>Redux state is a fundamental concept in Redux-based React applications. By providing a centralized store, actions, and reducers, Redux simplifies state management and promotes predictable data flow. It enables developers to build scalable and maintainable applications by providing a structured approach to handling application state. With Redux, you can create robust and efficient React applications that are easier to debug, test, and scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82b92f5d7453" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby on Rails Serializer]]></title>
            <link>https://lionelmason.medium.com/ruby-on-rails-serializer-58facf3e698e?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/58facf3e698e</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineer]]></category>
            <category><![CDATA[serializers]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 22:55:39 GMT</pubDate>
            <atom:updated>2023-03-16T22:56:01.039Z</atom:updated>
            <content:encoded><![CDATA[<h4>Customizing JSON</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*8d8DNpEfQYspu2Ttl9lHaA.png" /></figure><p>As I continue my software engineer career, I have familiarized myself with AMS (Active Model Serializer) to streamline my full-stack projects.</p><p><strong>Serializers</strong> in Ruby on Rails <strong>convert a given object into a JSON format</strong>. Serializers control the particular attributes rendered when an object or model is converted into a JSON format. We no longer have to use <em>only:</em> or <em>except:</em> in our controller actions to render the json. Now that we have some information on the benefits of using Serializers, lets dive into the setup:</p><p>The first step is to add the gem to our Gemfile:</p><pre># Gemfile <br>#...<br>gem &#39;active_model_serializers&#39;</pre><p>After adding the gem, run <em>bundle install</em>.</p><p>This gem will help us build out our serializers that will handle the customization. Now that our serializer is installed, we can use the command ‘rails g serializer’ to generate a new serializer file. Your serializer name should be singular. In the terminal, enter:</p><pre>rails g serializer #serializer name</pre><p>This command will create a serializer. Take a look at the generated restaurant_serializer.rb in the app/serializers directory. It should look something like this:</p><pre>class RestaurantSerializer &lt; ActiveModel::Serializer<br>  attributes :id<br>end</pre><p>To customize our JSON, we simply provide the list of attributes that we want to be included:</p><pre>class RestaurantSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :name, :city, :rating <br>end</pre><p>AMS provides a convention-based approach to serializing our resources, which means that if we have a Restaurant model, we can also have a RestaurantSerializer, and by default, Rails will use our serializer if we simply call render json: restaurant on our controller action(s).</p><p>Our restaurant_serializer.rb now has the attributes we want to include.</p><p>With this in place, we can render json: restaurant in our restaurant_controller.rb which will render all the attributes we added to our serializer:</p><pre># app/controllers/restaurant_controller.rb<br>def show<br>  restaurant = Restaurant.find(params[:id])<br>  render json: restaurant<br>end</pre><p>This example works well with one model but what happens if we have multiple models with relationships?</p><p>Let’s create another serializer for <em>chef </em>so when we make a fetch for Restaurant, we will also be able to display our chefs client side.</p><pre>class ChefSerializer &lt; ActiveModel::Serializer<br>attributes :id, :name, :cuisine, :experience_level<br><br>belongs_to :restaurant<br>end</pre><p>Because of the relationship in our model, we can add the belongs_to relationship in our ChefSerializer. A Chef belongs to a Restaurant.</p><p>We will also add the has_many relationship to our Restaurant Serializer:</p><pre>class RestaurantSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :name, :city, :rating <br><br>  has_many :chefs <br>end</pre><p>Now, when we fetch our Restaurants, we will have the nested data of chefs associated:</p><p>A serializer handles the logic for organizing our data in a specific way while our controller stays specific to communicating between our model and our view. Our Serializer now controls our data through customization, rendering the JSON how we want without sacrificing the Rails principles of “convention over configuration” and separation of concerns.</p><p>-Till next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58facf3e698e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backend: Ruby & Active Record Associations]]></title>
            <link>https://lionelmason.medium.com/backend-ruby-active-record-associations-7f1d1a859594?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f1d1a859594</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[activerecord]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Fri, 25 Nov 2022 21:23:29 GMT</pubDate>
            <atom:updated>2022-12-24T04:20:28.305Z</atom:updated>
            <content:encoded><![CDATA[<p>When visiting a website or using our favorite social media platforms, the first thing we see is the frontend also known as the user interface. What users do not have access to is the backend also known as the server which stores data under the hood. Imagine stepping out to dine at a restaurant where the kitchen is not on display. The “front of house” is where we can see the dining room and all of its furnishings that makes the ambiance aesthetically pleasing. However, what we do not have access to is the “back of house” a.k.a the kitchen, where all the magic happens to prepare a wonderful spread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0_CL7Huc6UpcNkbjkJ3Pw.jpeg" /></figure><p>The Backend is the server side of the website that stores and arranges data. It is the part of the website that you cannot see and interact with. It is the portion of software that does not come in direct contact with the users.</p><p><strong>What is Active Record?<br></strong>Active Record is a Ruby gem, meaning we get an entire library of code just by running gem install activerecord or by including it in our Gemfile.Active Record makes fetching and representing data easier.</p><p>Active Record gives you the tools to link a database to your application. An <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html"><strong>Active Record Association</strong></a> is a set of macro-like class methods for tying objects together through<em> foreign keys</em>. A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them. These foreign keys express relationships like “Capital City belongs to a Country” or “City belongs to a State”. Each macro adds a number of methods to the class which are specialized according to the collection or association symbol and the options hash. It works much the same way as Ruby’s own attr* methods.</p><p>Active Record Associations make it easy to establish relationships between our models, without having to write a ton of SQL ourselves. Through our Active Record Associations we can create one-to-one, one-to-many, and many-to-many relationships:</p><h3>One-to-one</h3><p>Use <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_one">has_one</a> in the base, and <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to">belongs_to</a> in the associated model.</p><pre>class Country &lt; ActiveRecord::Base<br>  has_one :capital_city<br>end<br>class CapitalCity &lt; ActiveRecord::Base<br>  belongs_to :country   # foreign key - country_id<br>end</pre><h3>One-to-many</h3><p>Use <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many">has_many</a> in the base, and <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to">belongs_to</a> in the associated model.</p><pre>class State &lt; ActiveRecord::Base<br>  has_many :cities<br>end<br>class City &lt; ActiveRecord::Base<br>  belongs_to :state     # foreign key - state_id<br>end</pre><h3>Many-to-many</h3><p>Use a <a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many">has_many</a> association with the :through option and a join model, so there are two stages of associations.</p><pre>class City &lt; ActiveRecord::Base<br>  belongs_to :state  # foreign key - state_id<br>  belongs_to :country     # foreign key - country_id<br>end<br>class Country &lt; ActiveRecord::Base <br>  has_many :states<br>  has_many :cities, through: :states<br>end</pre><p>By writing a few migrations and making use of the appropriate Active Record macros, we will be able to:</p><ul><li>ask a Country about its Capital City</li><li>ask a State about its Cities</li><li>ask a City about its State and Country</li><li>ask a Country about its States and Cities</li></ul><p>We can now call methods on the objects we associated with one another.</p><p>Active Record Associations make common operations simpler and easier in your code. Understanding these associations also saves us time so we’re not writing out a ton of SQL ourselves.</p><p>Until next time!</p><p><strong>References:</strong></p><p><a href="https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html">ActiveRecord::Associations::ClassMethods</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f1d1a859594" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks — useEffect]]></title>
            <link>https://lionelmason.medium.com/react-hooks-useeffect-647154e7e7e1?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/647154e7e7e1</guid>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 16:11:21 GMT</pubDate>
            <atom:updated>2022-08-01T16:23:04.725Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Hooks — useEffect</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrH6P_BJ10DdckmGWOOA_g.jpeg" /></figure><p>“The useEffect Hook allows developers to perform side effects in our Components. Some examples of side effects are fetching data, directly updating the DOM, and timers.”¹</p><p>[1] <a href="https://www.w3schools.com/react/react_useeffect.asp">https://www.w3schools.com/react/react_useeffect.asp</a></p><p>useEffect is one of the most important concepts to mastering React. Best practice is using useEffect asynchronously to avoid unnecessary complexity and introducing errors to your code. In order to use useEffect, we must initialize the Hook by importing it at the top level of our component; i.e</p><pre>import React, {useEffect, useState} from &#39;react&#39;;</pre><p>The Component will be rendered first, then useEffect will be called. Every time our component re-renders, useEffect will also run.</p><p>The order of operations for our Component is:</p><pre>render &gt; useEffect &gt; setState &gt; re-render &gt; useEffect</pre><p>We can control when the useEffect runs by adding a second argument of a dependencies array:</p><pre>useEffect (() =&gt; {<br> console.log(&quot;UseEffect called&quot;);<br> //fetch<br>}, [] //dependency array if empty, only runs once!</pre><p>If we add arguments to the array, it will check the variable for renders, and then re-run the useEffect based on changes:</p><pre>useEffect(() =&gt; {<br> console.log(&quot;UseEffect called&quot;);<br> //fetch<br>}, [count]</pre><p>I created a single page application React project (Medicinal Wellness Center), where i created my own REST API with JSON Server that includes an array of objects where I used useEffect hook to fetch the data in my db.json file when the app first loads. First, I declared the variables strains and searchTerm and their setter functions setStrains and setSearchTerm, respectively. I assigned strains to an empty array. The second .then() is a promise used to deal with the asynchronous task of updating the empty array of strains by using the setter function of setStrains to update strains with the fetched data at our localhost.</p><pre>const [strains, setStrains] = useState([]);</pre><pre>const [searchTerm, setSearchTerm] = useState(&quot;&quot;)</pre><pre>useEffect(() =&gt; {</pre><pre>fetch(&quot;http://localhost:3000/strains&quot;)</pre><pre>.then((r) =&gt; r.json())</pre><pre>.then((strains) =&gt; setStrains(strains));</pre><pre>}, []);</pre><p>This allows the user to see all the data when the app first loads. The Medicinal Wellness Center is an application where users can enter their diagnoses in the search box, and cannabis strains that can manage the diagnosis will be filtered then mapped through to appear on the home page. The populated strains will also have information pertaining to the name, strain, species, an image, top effect, flavor and aroma, THC percentage, and rating.</p><p>In my opinion, useEffect is the best part of React Hooks. useEffect provides reusability, readability, and testability. useEffect also helps reduce clutter of the components life cycle and also separates different logic. Holding state and useEffect in a parent component allows me to pass data via props to child components. This was beneficial while building the Medicinal Wellness Center because I was able to reuse data without having to fetch multiple times, it make my code a lot cleaner and saved time as well. Adding a second argument to useEffect can also control when side effect code will run.</p><p>No dependencies array:</p><pre>useEffect(() =&gt; {})</pre><p>Run the side effect every time our component renders (whenever state or props change).</p><p>Empty dependencies array:</p><pre>useEffect(() =&gt; {}, [])</pre><p>Run this side effect only the first time our component renders.</p><p>Dependencies array with elements in it:</p><pre>useEffect (() =&gt; {}, [variable1, variable2])</pre><p>Run this side effect any time the variable(s) change.</p><p>-Till next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=647154e7e7e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flatiron First Project Using Javascript]]></title>
            <link>https://lionelmason.medium.com/flatiron-first-project-using-javascript-ec5705dfd2c?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec5705dfd2c</guid>
            <category><![CDATA[bootcamp]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 21:57:17 GMT</pubDate>
            <atom:updated>2022-01-31T21:57:17.598Z</atom:updated>
            <content:encoded><![CDATA[<p>For my first project I decided to make a website that will allow you to create your own NBA Roster composed of Starters and Reserves (bench players).</p><p>🚨 Fun fact — I have played sports since forever (Basketball, Football, Track &amp; Field, Muay Thai) and thought It would be <em>fun</em> to create something specific to sports for my first project.</p><p>The main objective of the first project is to use Javascript and focus on functionality. The HTML <em>structure</em> is pretty simple so I wont get into it. I will continue to work on the CSS file to obtain a better aesthetic and <em>style</em> the website in the near future.</p><p>While learning Javascript was my first language and somewhat a challenge, putting it all together to create something from scratch was far more challenging 😥. The API I used is <a href="https://www.balldontlie.io/api/v1/players">https://www.balldontlie.io/api/v1/players</a></p><p><strong>Getting Started</strong>:</p><p>While fetching the API, I discovered that i can use interpolation to pass in the player’s name.</p><pre>function fetchPlayer(test) {</pre><pre>fetch(`https://www.balldontlie.io/api/v1/players?search=${test}`)</pre><pre>.then(res =&gt; res.json())</pre><pre>.then(data =&gt; {</pre><p>This was super helpful in manipulating the application.</p><p>Next, I created a Function containing the data that would populate from the API in order to be appended to the player container div.</p><pre>const createdPlayer = (player) =&gt; {</pre><pre>const playerDiv = document.createElement(&#39;div&#39;)</pre><pre>const name = document.createElement(&#39;h1&#39;)</pre><pre>name.innerText = player.first_name + &#39; &#39; + player.last_name</pre><pre>const playerPosition = document.createElement(&#39;h3&#39;)</pre><pre>playerPosition.innerText = player.position</pre><pre>const heightFeet = document.createElement(&#39;h4&#39;)</pre><pre>heightFeet.innerText = player.height_feet</pre><pre>const heightInches = document.createElement(&#39;h4&#39;)</pre><pre>heightInches.innerText = player.height_inches</pre><pre>const weightPounds = document.createElement(&#39;h4&#39;)</pre><pre>weightPounds.innerText = player.weight_pounds</pre><pre>const team = document.createElement(&#39;h2&#39;)</pre><pre>team.innerText = player.team.full_name</pre><pre>playerDiv.append(name, playerPosition, heightFeet, heightInches, weightPounds, team)</pre><pre>const playerContainer = document.getElementById(&#39;playercontainer&#39;)</pre><pre>playerContainer.append(playerDiv)</pre><pre>}</pre><p>Although this application is not totally styled, separating the data into different divs made it super easy to isolate functions and was a seamless way to work through this project. It was as simple as declaring a variable and accessing elements from the DOM.</p><p>I then was able to create a function that allowed me to ‘renderPlayer’ to the playerContainer.</p><pre>function renderPlayer(player) {</pre><pre>players.push(player)</pre><pre>const div = document.createElement(&#39;div&#39;)</pre><pre>div.className = &#39;playerCard&#39;</pre><pre>div.innerHTML = `&lt;p&gt;Player Name: ${player.first_name} ${player.last_name}&lt;/p&gt;`</pre><pre>const button1 = document.createElement(&#39;button&#39;);</pre><pre>const button2 = document.createElement(&#39;button&#39;);</pre><pre>button1.innerText = &quot;START!&quot;</pre><pre>button2.innerText = &quot;BENCH!&quot;</pre><pre>button1.addEventListener(&#39;click&#39;, addToStart)</pre><pre>button2.addEventListener(&#39;click&#39;, addToBench)</pre><pre>div.append(button1)</pre><pre>div.append(button2)</pre><pre>playerContainer.append(div)</pre><pre>}</pre><p>I used this function to create buttons, add its innerText and event listeners. I would also create two functions ‘addToStart’ and ‘addToBench’ to target the addEventListeners in the renderPlayer function.</p><p>Instead of adding a DOMContentLoaded event which fires when the initial HTML document has been completely loaded and parsed, I used a defer src script tag at the bottom of my HTML file.</p><pre>&lt;script language=&quot;javascript&quot; defer src=&quot;index.js&quot;&gt;&lt;/script&gt;</pre><p>Ultimately, this website functions the way it is intended to, creating a list of starters and reserve players that are all accessible from the API.</p><p><strong>Discovery</strong> 🔎</p><p>This was my very first start-to-finish project and took longer than I anticipated. Pair programming with my cohort mates and making use of the resources at Flatiron School proved to be very helpful and allowed me to find confidence in executing my vision. One of the beauties of being a developer and working on personal projects is that you can always revisit these projects and make improvements. Being that this is my “baby” and first project, I take pride in what I have accomplished and will revisit throughout my career.</p><p>-Till next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec5705dfd2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting A Coding Bootcamp]]></title>
            <link>https://lionelmason.medium.com/starting-a-coding-bootcamp-ce1bfec479f3?source=rss-14091d115a96------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce1bfec479f3</guid>
            <category><![CDATA[career-change]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[engineer]]></category>
            <category><![CDATA[bootcamp]]></category>
            <dc:creator><![CDATA[Lionel Mason, MPA]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 15:25:51 GMT</pubDate>
            <atom:updated>2022-01-31T15:25:51.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*B1nm2QL0duHtIbBG5bdqOA.gif" /></figure><p>On October 11, 2021 I started my journey to become a Software Engineer at a coding bootcamp — “Flatiron School”. Needless to say I was beyond nervous as I am not a technical person. I spent over 10 years in Healthcare but grew tired with the lack of creativity and monotonous work; I wanted a change! My search for a new career started with a conversation with a good friend who is now a Senior Engineer at Apple . She told me of many success stories and the expansive opportunities the tech industry has to offer.</p><p>I started my search and found Flatiron School. I secured a scholarship for the SWE (Software Engineer) program and my journey to becoming a developer began. While waiting for my start date, I found some intro to HTML instructional YouTube vids. where I designed a website with very limited styling. This process further sparked my interest as I was able to build something in a few hours that can be shared and live on the internet for as long as I saw fit. The first phase is mostly Javascript and it scared the S#it out of me!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*6Zkp8QwNlxgTeOiNBOWJQw.gif" /></figure><p>As I am writing this blog, I have just completed Phase 1 of my coding bootcamp and it wasn’t as bad as I thought. I am looking forward to continuing my education, learning new languages, and building community and projects.</p><p>-Till next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce1bfec479f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>