<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Albert Jokelin</title>
    <description>The latest articles on Forem by Albert Jokelin (@albertjokelin).</description>
    <link>https://forem.com/albertjokelin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F672224%2F9bf2d1b5-44b8-4e28-9e60-8ca5b9461423.png</url>
      <title>Forem: Albert Jokelin</title>
      <link>https://forem.com/albertjokelin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/albertjokelin"/>
    <language>en</language>
    <item>
      <title>Turbocharged C: How to engineer a Sub-50ms Program!⚡🚀</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Sun, 02 Feb 2025 17:03:24 +0000</pubDate>
      <link>https://forem.com/albertjokelin/turbocharged-c-how-to-engineer-a-sub-50ms-program-hb7</link>
      <guid>https://forem.com/albertjokelin/turbocharged-c-how-to-engineer-a-sub-50ms-program-hb7</guid>
      <description>&lt;p&gt;Imagine working on several programs that together must route messages across 5 devices in less than 50ms!&lt;/p&gt;

&lt;p&gt;That's what I was working on at my workplace for the last couple of months. &lt;/p&gt;

&lt;p&gt;A bit of context here- we work on Backend data transfer technology that routes data across hundreds of kilometres using optical fibre. &lt;/p&gt;

&lt;p&gt;There comes a time when those links fail and we must route that data through an alternative path. Because we are dealing with terabytes of data every second, this must be done quickly; within milliseconds. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphofkfuotv1nsy2uyuns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphofkfuotv1nsy2uyuns.png" alt="Image description" width="521" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how the flow works: &lt;br&gt;
1) The framing device raises an alarm when it stops receiving data. &lt;br&gt;
2) The switching device processes this alarm and sends relevant information about the connection to the switching device of the alternate path. &lt;br&gt;
3) The alternate switching device starts processing data. &lt;/p&gt;

&lt;p&gt;All of these steps have to be completed within 50ms. Needless to say, our solution worked but not within the intended timeframe and that's when we got to debugging. &lt;/p&gt;

&lt;p&gt;Since our switching devices communicate using ethernet packets, we had to determine whether the number of packets transmitted made any difference. Surprisingly, it did. We expected the message to be broadcast across the system rather than sent specifically to a single device, but that wasn't the case. &lt;/p&gt;

&lt;h2&gt;
  
  
  Debugging the system
&lt;/h2&gt;

&lt;p&gt;In my opinion, the best way to debug any system (especially embedded ones) is to break them into the smallest possible units and thoroughly examine each one. &lt;/p&gt;

&lt;p&gt;We started by adding timers to the operations essential to the switching mechanism in all the devices. Since we were using C, we used the built-in timer. &lt;/p&gt;

&lt;p&gt;This method highlighted two issues- the processor we used had too many operations going on and there was an avoidable time delay when the switch received the data and processed it. &lt;/p&gt;

&lt;p&gt;How did we resolve it? Well, the first was fairly straightforward. Since the switching mechanism had different threads, our first approach was to keep the process out of the general scheduler and have a single core work on it. However, our processor had only two cores which meant all the other processes hogged up the first core and lesser urgent but important tasks weren't completed on time. &lt;/p&gt;

&lt;p&gt;The next best solution was to increase the thread priority which worked reasonably well. &lt;/p&gt;

&lt;p&gt;The second issue was challenging to solve because we had to dive into the switch manufacturer's code and figure out how they sent ethernet packets. &lt;/p&gt;

&lt;p&gt;After a week of going through the code, we found out that messages received by the switch were stored in a queue (an elegant solution, realization should have struck earlier IMO). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabawveg9jgt66nkawzuu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabawveg9jgt66nkawzuu.png" alt="Image description" width="631" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, there are two ways to retrieve messages from the queue- either the processor polls or the queue pushes. By default, our processor was set to polling which explained the time delay between receiving and processing the messages. We switched to an interrupt/push-based mechanism and voila! It worked. &lt;/p&gt;

&lt;p&gt;Although the above optimizations did work, what made the program execution faster was using highly optimized algorithms and structures like hashmap. Their effect was noteworthy with times reaching as low as 8ms!&lt;/p&gt;

</description>
      <category>c</category>
      <category>testing</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>All of Reacts concepts- one article</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Sun, 30 Jun 2024 09:30:36 +0000</pubDate>
      <link>https://forem.com/albertjokelin/all-of-reacts-concepts-one-article-1ij9</link>
      <guid>https://forem.com/albertjokelin/all-of-reacts-concepts-one-article-1ij9</guid>
      <description>&lt;p&gt;React, developed by Facebook, has transformed web development with its component-based architecture and efficient rendering. However, mastering React requires a solid grasp of its core concepts.&lt;/p&gt;

&lt;p&gt;In this comprehensive article, we'll explore all the essential aspects of React. Whether you're a beginner or an experienced developer, this guide covers everything from components and state management to hooks and lifecycle methods.&lt;/p&gt;

&lt;p&gt;By the end, you'll have a thorough understanding of React's ecosystem and be ready to build sophisticated, maintainable applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;A function that returns markup (JSX). Kind of like legos, basic building blocks of a react app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Profile() {
  return (
    &amp;lt;img
      src="https://i.imgur.com/MK3eW3As.jpg"
      alt="Katherine Johnson"
    /&amp;gt;
  );
}

export default function Gallery() {
  return (
    &amp;lt;section&amp;gt;
      &amp;lt;h1&amp;gt;Amazing scientists&amp;lt;/h1&amp;gt;
      &amp;lt;Profile /&amp;gt;
      &amp;lt;Profile /&amp;gt;
      &amp;lt;Profile /&amp;gt;
    &amp;lt;/section&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Curly braces
&lt;/h2&gt;

&lt;p&gt;Allows react to be dynamic by allowing values to pass through it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;img
      className="avatar"
      src={avatar}
      alt={description}
    /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fragments
&lt;/h2&gt;

&lt;p&gt;An empty component is usually used as a parent container to return multiple components simultaneously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;gt; 
    &amp;lt;ChildComponent /&amp;gt;
&amp;lt;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Props
&lt;/h2&gt;

&lt;p&gt;The parameters passed through containers. Anything can be a prop including other components (as children, known as composition). &lt;/p&gt;

&lt;p&gt;A 'key' in props (similar to the primary key in SQL) is used to identify a component. Usually, it is the current index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Writing a function that supports props
function Avatar({ person, size }) {
  return (
    &amp;lt;img
      className="avatar"
      src={getImageUrl(person)}
      alt={person.name}
      width={size}
      height={size}
    /&amp;gt;
  );
}

// Using props with the component
return (
    &amp;lt;Avatar
      person={{ name: 'Lin Lanying', imageId: '1bX5QH6' }}
      size={100}
    /&amp;gt;
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rendering
&lt;/h2&gt;

&lt;p&gt;Works by using a virtual DOM (VDOM). how does it work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State changed? update VDOM to reflect changes&lt;/li&gt;
&lt;li&gt;'Diff'ing is performed: Check for changes between DOM and VDOM. &lt;/li&gt;
&lt;li&gt;'Reconciliation' with the DOM is performed. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4d96xj2l0pkl10782b6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4d96xj2l0pkl10782b6.png" alt="Image courtesy of Telerik.com, Describes rendering in react" width="800" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Handling
&lt;/h2&gt;

&lt;p&gt;Handles different events like onClick(), onChange(), and onSubmit().&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kclgvvmfeo5c2ewuo2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kclgvvmfeo5c2ewuo2w.png" alt="Image description" width="800" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  State
&lt;/h2&gt;

&lt;p&gt;A snapshot of the app at any given point. We use special functions like useState and useReducer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
        Click me
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Controlled Components
&lt;/h2&gt;

&lt;p&gt;Components used by a state to have a more predictable behaviour.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [value, setValue] = useState('')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We change the state to change the behaviour. &lt;/p&gt;

&lt;h2&gt;
  
  
  Hooks
&lt;/h2&gt;

&lt;p&gt;It allows us to hook into features like state within function components. There are 5 types of hooks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State Hooks- useState, useReducer, to manage state&lt;/li&gt;
&lt;li&gt;Context Hooks- useContext, use data through context&lt;/li&gt;
&lt;li&gt;Ref Hooks- useRef, to reference HTML&lt;/li&gt;
&lt;li&gt;Effect Hooks- useEffect, Lets you connect to external systems and APIs.&lt;/li&gt;
&lt;li&gt;Performance Hooks- useMemo, useCallback, Boosts performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f4nmizzu7ayokgraizi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5f4nmizzu7ayokgraizi.png" alt="Types of hooks in react" width="800" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Purity
&lt;/h2&gt;

&lt;p&gt;Describes how react components should work (Like the one in Functional Programming). It follows two rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only return JSX&lt;/li&gt;
&lt;li&gt;Don't change stuff that existed before rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Strict Mode
&lt;/h2&gt;

&lt;p&gt;A component that detects problems during app development. Here's how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;StrictMode&amp;gt;
  &amp;lt;App /&amp;gt;
&amp;lt;/StrictMode&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Effects
&lt;/h2&gt;

&lt;p&gt;Code that reaches outside the react application (like an API). Best done using event handlers or useEffect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ChatRoom({ roomId }) {
  const [serverUrl, setServerUrl] = useState('https://localhost:1234');

  useEffect(() =&amp;gt; {
    const connection = createConnection(serverUrl, roomId);
    connection.connect();
    return () =&amp;gt; {
      connection.disconnect();
    };
  }, [serverUrl, roomId]);
  // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Refs
&lt;/h2&gt;

&lt;p&gt;Used to reference an element on DOM. Useful for tasks like focusing on an element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Counter() {
  let ref = useRef(0);

  function handleClick() {
    ref.current = ref.current + 1;
    alert('You clicked ' + ref.current + ' times!');
  }

  return (
    &amp;lt;button onClick={handleClick}&amp;gt;
      Click me!
    &amp;lt;/button&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;Passing data without sending as props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button() {
  const theme = useContext(ThemeContext);
  return &amp;lt;button className={theme} /&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flff4uxzt650idixjt94h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flff4uxzt650idixjt94h.png" alt="Image courtesy of Shamalka Vanod (medium)" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Portals
&lt;/h2&gt;

&lt;p&gt;Context for components. Ideal for modals, dropdowns and tooltips.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;p&amp;gt;This child is placed in the parent div.&amp;lt;/p&amp;gt;
  {createPortal(
    &amp;lt;p&amp;gt;This child is placed in the document body.&amp;lt;/p&amp;gt;,
    document.body
  )}
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Suspense
&lt;/h2&gt;

&lt;p&gt;Component to wait for something to load/occur. Provides a fallback UX till the other component is fetched/rendered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Suspense fallback={&amp;lt;Loading /&amp;gt;}&amp;gt;
  &amp;lt;SomeComponent /&amp;gt;
&amp;lt;/Suspense&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Error Boundaries
&lt;/h2&gt;

&lt;p&gt;Component to show a fallback component should that app encounter an error (like a 404 page).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function MessageContainer({ messagePromise }) {
  return (
    &amp;lt;ErrorBoundary fallback={&amp;lt;p&amp;gt;⚠️Something went wrong&amp;lt;/p&amp;gt;}&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;p&amp;gt;⌛Downloading message...&amp;lt;/p&amp;gt;}&amp;gt;
        &amp;lt;Message messagePromise={messagePromise} /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
    &amp;lt;/ErrorBoundary&amp;gt;
  );
}

function Message({ messagePromise }) {
  const content = use(messagePromise);
  return &amp;lt;p&amp;gt;Here is the message: {content}&amp;lt;/p&amp;gt;;
}

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

&lt;/div&gt;



&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://react.dev/"&gt;React Dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Removing redundant libraries from Makefiles</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Wed, 26 Jun 2024 06:56:26 +0000</pubDate>
      <link>https://forem.com/albertjokelin/removing-redundant-libraries-from-makefiles-55nl</link>
      <guid>https://forem.com/albertjokelin/removing-redundant-libraries-from-makefiles-55nl</guid>
      <description>&lt;p&gt;It can be awfully frustrating when your binary is massive, you can’t &lt;code&gt;strip&lt;/code&gt; your executable otherwise you may lose vital debugging information and the only way to figure out what libraries are and aren’t needed is by brute-forcing your way through. &lt;/p&gt;

&lt;p&gt;There is an alternative way i discovered while working on my C++ program. &lt;/p&gt;

&lt;p&gt;Theory: Assume we have two sets S1 and S2 defined as follows,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;S1: Set of all libraries included in the makefile. 
S2: Set of all libraries used by the compiler to build the binary. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is obvious that S1 is the complete domain (i.e. S1 = U) and n(S1) &amp;gt;= n(S2). Now we define a third set, S3 as follows,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;S3: Set of all libraries to be removed from the makefile. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The way we obtain S3 is by using the following equation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;S3 = S1 – S2
   = (S1 ∩ S2)’ [The complement of the intersection of S1 and S2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this line to the end of your COMPILER variable in the makefile &lt;code&gt;-Xlinker -Map=output.map&lt;/code&gt;. This flag creates a map of all the functions called while linking the binaries. &lt;/p&gt;

&lt;p&gt;Now, to make your life easier you can either use the &lt;code&gt;sed&lt;/code&gt; command to parse through &lt;code&gt;output.map&lt;/code&gt; or you can search for individual libraries and remove the ones not called from your Makefile. &lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
    <item>
      <title>Demystifying Monads: A Primer</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Wed, 08 May 2024 17:03:38 +0000</pubDate>
      <link>https://forem.com/albertjokelin/demystifying-monads-a-primer-in-computer-science-22ig</link>
      <guid>https://forem.com/albertjokelin/demystifying-monads-a-primer-in-computer-science-22ig</guid>
      <description>&lt;p&gt;In the realm of functional programming and category theory, there's a concept that often mystifies newcomers and seasoned programmers alike: the monad. Monads are considered difficult to understand, but with the right approach, they can be demystified and appreciated for their elegance and utility.&lt;/p&gt;

&lt;p&gt;At its core, a monad is a design pattern used to encapsulate computations in a structured manner. It provides a way to chain operations together while managing side effects, error handling, and state. While this definition might sound abstract, we can break it down into simpler components to gain a better understanding.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Three Laws of Monads
&lt;/h1&gt;

&lt;p&gt;Before diving deeper, let's first establish the three fundamental laws that govern monads:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Left Identity&lt;/strong&gt;: &lt;code&gt;return a &amp;gt;&amp;gt;= f&lt;/code&gt; is equivalent to &lt;code&gt;f a&lt;/code&gt;, where &lt;code&gt;return&lt;/code&gt; lifts a value into the monadic context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Right Identity&lt;/strong&gt;: &lt;code&gt;m &amp;gt;&amp;gt;= return&lt;/code&gt; is equivalent to &lt;code&gt;m&lt;/code&gt;, where &lt;code&gt;m&lt;/code&gt; is a monadic value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Associativity&lt;/strong&gt;: &lt;code&gt;(m &amp;gt;&amp;gt;= f) &amp;gt;&amp;gt;= g&lt;/code&gt; is equivalent to &lt;code&gt;m &amp;gt;&amp;gt;= (\x -&amp;gt; f x &amp;gt;&amp;gt;= g)&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Understanding Monads through Examples
&lt;/h1&gt;

&lt;p&gt;To truly grasp the essence of monads, let's explore a classic example: the Maybe monad. The Maybe monad is used for computations that may fail, by encapsulating the possibility of a value being absent or present.&lt;/p&gt;

&lt;p&gt;Consider a scenario where we want to perform division but need to handle the case where the divisor is zero, which would result in an error. Without monads, we might write code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Result:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: Division by zero&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this code works, it requires explicit error checking and handling, which can clutter our codebase. Enter the Maybe monad to rescue us from this verbosity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="kr"&gt;data&lt;/span&gt; &lt;span class="kt"&gt;Maybe&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;

&lt;span class="kr"&gt;instance&lt;/span&gt; &lt;span class="kt"&gt;Monad&lt;/span&gt; &lt;span class="kt"&gt;Maybe&lt;/span&gt; &lt;span class="kr"&gt;where&lt;/span&gt;
    &lt;span class="n"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
    &lt;span class="kt"&gt;Nothing&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; &lt;span class="kr"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
    &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;

&lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="kt"&gt;Float&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Float&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Maybe&lt;/span&gt; &lt;span class="kt"&gt;Float&lt;/span&gt;
&lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
&lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;do&lt;/span&gt;
    &lt;span class="kr"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;do&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
        &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
        &lt;span class="n"&gt;divide&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="kr"&gt;case&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="kr"&gt;of&lt;/span&gt;
        &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;putStrLn&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="s"&gt;"Result: "&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
        &lt;span class="kt"&gt;Nothing&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;putStrLn&lt;/span&gt; &lt;span class="s"&gt;"Error: Division by zero"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a &lt;code&gt;Maybe&lt;/code&gt; type that represents computations that may fail. We implement the &lt;code&gt;Monad&lt;/code&gt; type class for &lt;code&gt;Maybe&lt;/code&gt;, defining how values are lifted and composed within this monadic context. With the Maybe monad, error handling becomes implicit, and we can chain computations together elegantly using the &lt;code&gt;do&lt;/code&gt; notation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Monads are powerful abstractions that simplify the management of side effects, error handling, and state in functional programming. By following the laws of monads, programmers can write cleaner, more maintainable code.&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://blog.ploeh.dk/2022/04/25/the-maybe-monad/"&gt;https://blog.ploeh.dk/2022/04/25/the-maybe-monad/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://builtin.com/software-engineering-perspectives/monads"&gt;https://builtin.com/software-engineering-perspectives/monads&lt;/a&gt;&lt;br&gt;
&lt;a href="https://ncatlab.org/nlab/files/KohlSchwaiger-Monads.pdf"&gt;https://ncatlab.org/nlab/files/KohlSchwaiger-Monads.pdf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Terraform pt-2</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Wed, 13 Sep 2023 17:18:00 +0000</pubDate>
      <link>https://forem.com/albertjokelin/terraform-pt-2-2f7p</link>
      <guid>https://forem.com/albertjokelin/terraform-pt-2-2f7p</guid>
      <description>&lt;p&gt;Hey Reader-&lt;br&gt;
Just started learning terraform and this articles serves to explain what I have learnt. If you have any thoughts or feel that I may be wrong, do let me know. My plan for this is to make this a series of articles that can explain the tool from my POV.&lt;/p&gt;

&lt;p&gt;Cheers&lt;br&gt;
A&lt;/p&gt;



&lt;p&gt;Contents&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/albertjokelin/intro-to-terraform-3j2a"&gt;Intro to terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Terraform pt-2&lt;/li&gt;
&lt;/ol&gt;



&lt;p&gt;In this post, we will discuss how to install and use terraform on your PC. &lt;/p&gt;
&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;First, we head over to the &lt;a href="https://developer.hashicorp.com/terraform/downloads?product_intent=terraform"&gt;Terraform downloads&lt;/a&gt; page and choose the operating system we want to download Terraform for. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8U_e2j_C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8d1gs7zg9t4ycfujhaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8U_e2j_C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8d1gs7zg9t4ycfujhaq.png" alt="Installation page" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're downloading for Windows like I did, then there are a couple of steps you must follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download, unzip and place the terraform binary somewhere you wouldn't accidentally delete it. &lt;/li&gt;
&lt;li&gt;Add the location to your system &lt;code&gt;PATH&lt;/code&gt; variable. Check out this guide for &lt;a href="https://dev.tomore%20details"&gt;https://stackoverflow.com/questions/1618280/where-can-i-set-path-to-make-exe-on-windows&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Verify the installation by running &lt;code&gt;terraform -help&lt;/code&gt;. You should be getting this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oT9JH0GV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xydgc68y1mesxtdatkw2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oT9JH0GV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xydgc68y1mesxtdatkw2.png" alt="Terraform help response" width="782" height="561"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Quick start
&lt;/h1&gt;

&lt;p&gt;Let's try using Terraform with an Nginx server and understand how it works. &lt;/p&gt;

&lt;p&gt;Before we go ahead, install Docker on your PC. If you're on windows, you will need WSL 2 to run docker. &lt;/p&gt;

&lt;p&gt;We're gonna be referencing the guide &lt;a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Let's start off by making a working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir myTerraformDir
cd myTerraformDir 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're gonna create a file called &lt;code&gt;main.tf&lt;/code&gt; and paste the following code into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~&amp;gt; 3.0.1"
    }
  }
}

provider "docker" {
  host    = "npipe:////.//pipe//docker_engine"
}

resource "docker_image" "nginx" {
  name         = "nginx"
  keep_locally = false
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.image_id
  name  = "tutorial"

  ports {
    internal = 80
    external = 8000
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you're done, &lt;em&gt;save&lt;/em&gt; the file and run &lt;code&gt;terraform init&lt;/code&gt;. This is the output you'll get on Windows. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rGJkbXjq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0zog6v37noa9di5g6na.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rGJkbXjq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0zog6v37noa9di5g6na.png" alt="terraform init response" width="748" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then you run &lt;code&gt;terraform plan&lt;/code&gt; which give you the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t8OWNplW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygtzv8suzsdqeiu0v3bs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t8OWNplW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygtzv8suzsdqeiu0v3bs.png" alt="Terraform plan response" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;terraform apply&lt;/code&gt; and head over to &lt;code&gt;localhost:8000&lt;/code&gt;, this is what you'll find:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mEipUr2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewr84fcbnp6103carfa2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mEipUr2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewr84fcbnp6103carfa2.png" alt="Nginx server" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you run &lt;code&gt;docker ps&lt;/code&gt;, this is what you'll get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0V1_024M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqgn0omgam0duqaooxjw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0V1_024M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pqgn0omgam0duqaooxjw.png" alt="Image description" width="800" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To shut this down, run &lt;code&gt;terraform destroy&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2mnI4m1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9l3jc1ducv9hrhogn0n3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2mnI4m1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9l3jc1ducv9hrhogn0n3.png" alt="Image description" width="800" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! you've made and destroyed your first server with terraform. In the following guides, we're gonna explore how to use terraform with AWS. &lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.hashicorp.com/terraform/downloads?product_intent=terraform"&gt;https://developer.hashicorp.com/terraform/downloads?product_intent=terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli"&gt;https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://spacelift.io/blog/terraform-tutorial"&gt;https://spacelift.io/blog/terraform-tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>devop</category>
      <category>terraform</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Intro to terraform</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Sun, 27 Aug 2023 09:02:35 +0000</pubDate>
      <link>https://forem.com/albertjokelin/intro-to-terraform-3j2a</link>
      <guid>https://forem.com/albertjokelin/intro-to-terraform-3j2a</guid>
      <description>&lt;p&gt;Hey Reader- &lt;br&gt;
Just started learning terraform and this articles serves to explain what I have learnt. If you have any thoughts or feel that I may be wrong, do let me know. My plan for this is to make this a series of articles that can explain the tool from my POV. &lt;/p&gt;

&lt;p&gt;Cheers&lt;br&gt;
A&lt;/p&gt;




&lt;p&gt;Contents&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Intro to terraform&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/albertjokelin/terraform-pt-2-2f7p"&gt;Terraform pt-2&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  What is terraform?
&lt;/h1&gt;

&lt;p&gt;Terraform is HashiCorp's Infrastructure-as-a-Code (IaaC) Service that allows you to automate provision resources on cloud providers like AWS, GCP and Azure using human-readable configuration files. &lt;/p&gt;

&lt;p&gt;IaaCs allow you to automatically provision resources through code in contrast to earlier methods where DevOps teams had to manually provision resources in order to scale up/down systems. &lt;/p&gt;

&lt;p&gt;This is awful and reserves unnecessary resources especially if you want to use them for a certain amount of time. Terrafrom on the other hand, observes the initial or current state and the final state (written in the config file) and figures out how to get to that state i.e. it is &lt;strong&gt;declarative&lt;/strong&gt; in nature.  &lt;/p&gt;

&lt;h1&gt;
  
  
  What is it used for?
&lt;/h1&gt;

&lt;p&gt;Terraform can be used: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;To manage any infrastructure- From AWS, GCP and Azure to personal servers, Terraform can manage almost any infrastructure you throw at it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To track your infrastructure- Terraform plans changes to be made to your infrastructure and saves it as state file for you to review it. Terraform uses the state file to determine the changes to be made. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To automate changes- The declarative nature of Terraform's state files enables it to automatically figure out what needs to be provisioned, how and where and does it with minimal involvement from the developer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Standardize configurations- Terraform supports reusable components known as &lt;strong&gt;modules&lt;/strong&gt; which allows users to have standardized configuration code across the board. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Collaborate- State file can be deployed to a Version Control System (VCS) and upload it to Terraform Cloud or any cloud (AWS S3 + DynamoDB for instance) where anyone on the team can easily make changes and deploy. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is often used in combination with different tools depending on the usecase:&lt;br&gt;
1) Provisioning (Terraform) + Configuration Management (Ansible- AWS)&lt;br&gt;
2) Provisioning (Terraform) + Server templating (Packer- Hashicorp) &lt;br&gt;
3) Provisioning (Terraform) + Orchestration (Kubernetes) &lt;/p&gt;

&lt;h1&gt;
  
  
  How does it work?
&lt;/h1&gt;

&lt;p&gt;In a nutshell, Terraform architecture can be divided into three main components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n4U7Je76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qynrj96hkb6y6rnuv2yf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n4U7Je76--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qynrj96hkb6y6rnuv2yf.png" alt="Terraform architecture, developer.hashicorp.com" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Terraform creates and manages resources on cloud platforms and other services through their application programming interfaces (APIs). Providers enable Terraform to work with virtually any platform or service with an accessible API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ouN-FDM---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20zjwqe92ifbqqxq4eso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ouN-FDM---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20zjwqe92ifbqqxq4eso.png" alt="Image description" width="800" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We start off by defining the infrastructure we need in the configuration file. And then run &lt;code&gt;terraform plan&lt;/code&gt; on it. &lt;/p&gt;

&lt;p&gt;Plan returns the changes that will be made to the infrastruture. If satisified, run &lt;code&gt;terraform apply&lt;/code&gt; to apply the changes. &lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
    </item>
    <item>
      <title>Microservices</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Sun, 20 Nov 2022 11:53:41 +0000</pubDate>
      <link>https://forem.com/albertjokelin/microservices-2c33</link>
      <guid>https://forem.com/albertjokelin/microservices-2c33</guid>
      <description>&lt;p&gt;Usually, when we make applications (especially as beginners), we tend to make one application to do everything. This application is said to follow a monolith architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Monolith architecture?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The standard way of writing code here all the components are a part of a single unit/ codebase.&lt;/li&gt;
&lt;li&gt;The app must be written with one tech stack. &lt;/li&gt;
&lt;li&gt;Teams need to be careful to not affect each other's work.&lt;/li&gt;
&lt;li&gt;Every time you update a part of the application, you need to redeploy the entire application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges with the monolith architecture
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Applications become too large and complex.&lt;/li&gt;
&lt;li&gt;Parts are more tangled into each other.&lt;/li&gt;
&lt;li&gt;You can't scale particular components which leads to higher infrastructure costs. &lt;/li&gt;
&lt;li&gt;Difficulties arise if different services require different dependency versions.&lt;/li&gt;
&lt;li&gt;Longer release process.&lt;/li&gt;
&lt;li&gt;For every change made, the entire application needs to be tested. &lt;/li&gt;
&lt;li&gt;A single bug in a relatively insignificant component can bring down the entire application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since there are a lot of problems with the standard monolith structure, we resolve them by using &lt;strong&gt;microservices&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are microservices?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We break down the application into several small/micro applications.&lt;/li&gt;
&lt;li&gt;What does their architecture look like?

&lt;ul&gt;
&lt;li&gt;The splits are based on each component's business functionalities. &lt;/li&gt;
&lt;li&gt;It follows the idea of 'Separation of concerns'- 1 service for 1 specific job.&lt;/li&gt;
&lt;li&gt;They must be self-contained and independent of each other. Each service must be developed, deployed and scaled separately even though they are a part of the same application. (Known as &lt;strong&gt;loose coupling&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Communications between microservices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Usually done using API Calls.

&lt;ul&gt;
&lt;li&gt;Each service has its own API and they can talk to each other by sending HTTP requests&lt;/li&gt;
&lt;li&gt;It is a synchronous communication&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;It can also be done asynchronously using a message broker

&lt;ul&gt;
&lt;li&gt;Common patterns- Pub/Sub and point-to-point messaging&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;A third way to communicate is by using a service mesh.

&lt;ul&gt;
&lt;li&gt;There's a helper service that takes over the complete communication logic.&lt;/li&gt;
&lt;li&gt;You don't have to code the communication logic into the microservice, it is delegated to the service mesh.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Downsides to using microservices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Added complexity because the microservices application is a distributed system.

&lt;ul&gt;
&lt;li&gt;Configuring the communications between services for scenarios where one of the services is down.&lt;/li&gt;
&lt;li&gt;More difficult to monitor with multiple instances of each service distributed across servers. 
Tools for overcoming these challenges have been built over the years. One of them is &lt;em&gt;Kubernetes&lt;/em&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  CI/CD pipelines for microservices
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Companies like Meta, Google and Netflix deploy hundreds of microservices every day. The complexity of the pipeline increases with the number of such services deployed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Monorepo vs Polyrepo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Monorepo means using 1 git repository that contains many projects. 

&lt;ul&gt;
&lt;li&gt;Each service has its own folder/ directory.&lt;/li&gt;
&lt;li&gt;Makes code management and development easier.&lt;/li&gt;
&lt;li&gt;Clone and work only with 1 repo.&lt;/li&gt;
&lt;li&gt;Changes can be tracked together, tested together and released together. &lt;/li&gt;
&lt;li&gt;Share code and configurations like docker-compose and manifest&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Some of the challenges are:

&lt;ul&gt;
&lt;li&gt;Tight coupling of projects. &lt;/li&gt;
&lt;li&gt;Easier to break the 'loosely coupled' criterion.&lt;/li&gt;
&lt;li&gt;Cloning, fetching and pushing slowdown due to increased size. &lt;/li&gt;
&lt;li&gt;Makes pipeline code more complex and challenging to write.&lt;/li&gt;
&lt;li&gt;If the main branch is broken, the entire repo is gone.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Used by companies like Google.&lt;/li&gt;

&lt;li&gt;Polyrepo means that each service has its repository.

&lt;ul&gt;
&lt;li&gt;Code is completely isolated&lt;/li&gt;
&lt;li&gt;Clone and work on them separately.&lt;/li&gt;
&lt;li&gt;In services like GitLab, you can have projects to configure connected projects (&lt;strong&gt;Groups&lt;/strong&gt;).

&lt;ul&gt;
&lt;li&gt;This helps to keep an overview.&lt;/li&gt;
&lt;li&gt;Create shared secrets, CI/CD variables, runners, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The CI/CD is more straightforward. &lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;Some downsides are:

&lt;ul&gt;
&lt;li&gt;Cross-cutting changes is more difficult.&lt;/li&gt;
&lt;li&gt;Changes spread across projects must be submitted as separate Merge requests instead of a single, atomic MR.&lt;/li&gt;
&lt;li&gt;Switching between projects is tedious&lt;/li&gt;
&lt;li&gt;Searching, testing and debugging is more difficult.&lt;/li&gt;
&lt;li&gt;Sharing resources is relatively more difficult.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;I made these notes after watching Techworld with Nana’s &lt;a href="https://youtu.be/rv4LlmLmVWk" rel="noopener noreferrer"&gt;video&lt;/a&gt;. Let me know what you think of it and if you’ve loved it, drop a like :)&lt;/p&gt;

</description>
      <category>architecture</category>
    </item>
    <item>
      <title>System Design 101</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Sun, 03 Jul 2022 20:24:32 +0000</pubDate>
      <link>https://forem.com/albertjokelin/system-design-101-4cji</link>
      <guid>https://forem.com/albertjokelin/system-design-101-4cji</guid>
      <description>&lt;h2&gt;
  
  
  What is system design?
&lt;/h2&gt;

&lt;p&gt;To define the term &lt;strong&gt;system design&lt;/strong&gt;, we need to take a closer look at the term itself, which has two parts- &lt;em&gt;system&lt;/em&gt; and &lt;em&gt;design&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  System
&lt;/h3&gt;

&lt;p&gt;A system can be loosely defined as an architecture or a collection of technologies that work together to serve a particular purpose. This purpose always has a set of users that have a certain or even specific requirements. &lt;/p&gt;

&lt;p&gt;An easier way of understanding this is to relate this to real-world systems like a restaurant.&lt;/p&gt;

&lt;p&gt;A restaurant is a system with many different components. We have a &lt;em&gt;kitchen&lt;/em&gt; that is responsible for cooking the food, the &lt;em&gt;wait staff&lt;/em&gt; is responsible for the customer's experience, the &lt;em&gt;cleaning staff&lt;/em&gt; is responsible for supplying the kitchen with clean dishes and maintaining the retaurant, the &lt;em&gt;manager&lt;/em&gt; is responsible for the overall functioning of the restaurant. &lt;/p&gt;

&lt;p&gt;In layman's terms, that's exactly how a system behaves. A collection of components that work together in harmony to produce some sort of useful output which in the restaurant's case is delicious food with an equally fulfilling dining experience. &lt;/p&gt;

&lt;h3&gt;
  
  
  Design
&lt;/h3&gt;

&lt;p&gt;Coming back to the example of a restaurant, we can see that we have to setup each component in such a way that it produces the optimal output. &lt;/p&gt;

&lt;p&gt;If we're setting up a fast food restaurant, we can get rid of the wait staff for self-service counters and drive-throughs. The kitchens have machines that prepare higher volume of food so that customers won't have to wait long for their meals. &lt;/p&gt;

&lt;p&gt;Even though a Michellin-star restaurant and a fast food joint have roughly the same, basic components, the way they have been set up or &lt;em&gt;designed&lt;/em&gt; has made all the difference. &lt;/p&gt;

&lt;p&gt;Thus, we can define &lt;strong&gt;design&lt;/strong&gt; as the process of understanding the user's requirements and selecting/modifying the software modules and technologies so that they can better serve the need of the user. &lt;/p&gt;

&lt;h3&gt;
  
  
  What's the point of all this?
&lt;/h3&gt;

&lt;p&gt;By now, you must having a rough idea of what happens in system design. And you might be wondering, "what is the exactly the point of all of this?"&lt;/p&gt;

&lt;p&gt;Personally, I'm used to just building projects and publishing them on GitHub, not caring about UI/UX, performance, etc. But we must remember that developers, in a way are engineers. &lt;/p&gt;

&lt;p&gt;Sure, we may love programming and building stuff and writing about it. However, at the end of the day we're building products for other people to use and, like any good craftsman, an engineer must know about all the tools he has at his disposal, and knowing which ones to use when and where makes all the difference. &lt;/p&gt;

&lt;p&gt;Stay tuned for more articles about system design!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>systems</category>
      <category>performance</category>
    </item>
    <item>
      <title>Improve your programming skills with 2 beers!</title>
      <dc:creator>Albert Jokelin</dc:creator>
      <pubDate>Thu, 22 Jul 2021 16:03:21 +0000</pubDate>
      <link>https://forem.com/albertjokelin/improve-your-programming-skills-with-2-beers-3bg5</link>
      <guid>https://forem.com/albertjokelin/improve-your-programming-skills-with-2-beers-3bg5</guid>
      <description>&lt;p&gt;Alas! Imposter syndrome is real… One day, it hit me so hard I said, “Enough is enough. I have to do something about it.” So, I started going through Reddit, Youtube and every other platform that’s ever existed, looking for ways to be a ‘better programmer’. Hours of scrolling and all I could find was Leetcode, practice and other stuff you’d find everywhere. I wanted to give up until I came across the Ballmer Peak.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The theory that computer programmers obtain quasi-magical, superhuman coding ability when they have a blood alcohol concentration percentage between 0.129% and 0.138%.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ksg3lyu4iivek5muiob.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ksg3lyu4iivek5muiob.jpg" alt="Drunk Programmer"&gt;&lt;/a&gt;&lt;br&gt;
[Photo by thom masat on Unsplash]&lt;br&gt;
That’s what Urban Dictionary has to say about this. In layman’s terms, drink two beers and becoming a literal programming god. Honestly, I don’t believe in this. Any sane person would know that you’d find programmers laying drunk on-campus of many of the tech giants the moment they set up a bar next to the cafe.&lt;br&gt;
A little bit of googling may prove otherwise. Some articles have even compared booze to Popeye’s spinach! Steve Ballmer, is an incredibly energetic guy (not kidding check out his retirement speech). You’d think that with all this energy he’d have to spend a lot of time letting it out of him but instead he used to sit around, observing people (and himself). This constant observation led him to see the effects of this graph:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtpeu3ad1wh3fqicdaj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtpeu3ad1wh3fqicdaj9.png" alt="Ballmer Peak"&gt;&lt;/a&gt;&lt;br&gt;
source: &lt;a href="http://ballmerpeak.web.elte.hu" rel="noopener noreferrer"&gt;http://ballmerpeak.web.elte.hu&lt;/a&gt;&lt;br&gt;
As we can infer from the graph given, moderate alcohol consumption does yield a notable increase in creative output. If we remove the typing out of it, programming is just creativity with computer software. The language is your paint, the functions you use, your style and the billions of devices capable of running the code, your canvas.&lt;br&gt;
In my opinion, whenever people drink alcohol their brains tend to be unable to focus on things at hand which makes them carefree. If a person has a carefree attitude, they may not worry about the future and tend to take bold steps like trying out the wildest solution to fix the code.&lt;br&gt;
This is a pretty cool phenomenon, would I try it before coding rounds? Certainly not. But if you wanted an excuse to drink beer you’ve got it :). Additionally, if you’re interested in maintaining the blood alcohol levels check this out: &lt;a href="https://github.com/alexcrist/ballmer-peak" rel="noopener noreferrer"&gt;https://github.com/alexcrist/ballmer-peak&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>startup</category>
      <category>jokes</category>
    </item>
  </channel>
</rss>
