<?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 Daniel Leitch on Medium]]></title>
        <description><![CDATA[Stories by Daniel Leitch on Medium]]></description>
        <link>https://medium.com/@danleitch?source=rss-5d487289ff6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vezv95scwhK3MPDj8T1K1A.jpeg</url>
            <title>Stories by Daniel Leitch on Medium</title>
            <link>https://medium.com/@danleitch?source=rss-5d487289ff6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:32:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danleitch/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[Angular Signals: The Ultimate Plain-English Cheat Sheet (With React Developer Translations )]]></title>
            <link>https://danleitch.medium.com/angular-signals-the-ultimate-plain-english-cheat-sheet-with-react-developer-translations-86ab8bed770c?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/86ab8bed770c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[global-state]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Tue, 16 Dec 2025 15:40:29 GMT</pubDate>
            <atom:updated>2025-12-16T15:44:48.993Z</atom:updated>
            <content:encoded><![CDATA[<p>Angular has just entered a new era.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPTJBO37bzUxPhTD5ORQJg.png" /></figure><p>For years, Angular developers relied on RxJS, Behavior Subjects, NgRx, and complicated models to manage state and reactivity. That era is ending. With the introduction of <a href="https://angular.dev/guide/signals"><strong>Signals</strong></a>, Angular now has a <em>simple, powerful, explicit, fine-grained reactive system</em> built directly into the framework.</p><p>If you’re coming from React, Solid, Vue, or even vanilla Angular — this guide will give you a clear, practical, no-nonsense understanding of Signals, written in plain English, with real examples and a full React → Angular translation section at the end.</p><p>Enough talk let’s jump in!</p><h3>🎯 What Are Signals?</h3><p>If you remember nothing else from this article, remember this:</p><blockquote><strong><em>Signals are Angular’s new way to do Global State 😎<br>They tell Angular exactly what changed, and Angular updates only what needs to update.</em></strong></blockquote><h3>🎯 1. Core Reactive Primitives</h3><h3>🟦 signal(initialValue)</h3><p><strong>Plain English:</strong><br> 👉 <em>“A box that stores a value — and tells Angular when the value changes.”</em></p><pre>const count = signal(0);<br>count();          // read (tracked)<br>count.set(5);     // replace</pre><h3>🟩 computed(() =&gt; …)</h3><p><strong>Plain English:</strong><br> 👉 <em>“A live formula. Only recalc when the signals I depend on change.”</em></p><pre>const double = computed(() =&gt; count() * 2);</pre><h3>🟧 effect(() =&gt; …)</h3><p><strong>Plain English:</strong><br> 👉 <em>“Whenever the signals I read change, run this side-effect again.”</em></p><pre>effect(() =&gt; console.log(count()));</pre><h3>🧹 Effect Cleanup</h3><pre>effect(onCleanup =&gt; {<br>  const id = setInterval(...);<br>  onCleanup(() =&gt; clearInterval(id));<br>});</pre><p><strong>Plain English:</strong><br> 👉 <em>“Before rerunning or destroying this effect, clean up here.”</em></p><h3>🔍 2. Reading Signals</h3><h3>🟦 mySignal()</h3><p>👉 <em>“Give me the current value, and track that I depend on it.”</em></p><pre><br>count(); // tracked read<br></pre><h3>🟥 mySignal.value</h3><p>👉 <em>“Give me the value, but do NOT track it.”</em><br> ⚠️ Only use this inside computed/effect.</p><pre>const v = mySignal.value;</pre><h3>🔄 3. Writing Signals</h3><h3>🟦 set(value)</h3><p>👉 <em>“Replace the entire value.”</em></p><pre>user.set({ name: &#39;Dan&#39; });</pre><h3>🟩 update(fn)</h3><p>👉 <em>“Return a new value based on the old one — immutable style.”</em></p><pre>user.update(u =&gt; ({ ...u, age: u.age + 1 }));</pre><h3>🟧 mutate(fn)</h3><p>👉 <em>“Modify the existing object/array — mutable style.”</em></p><pre>items.mutate(arr =&gt; arr.push(&quot;new&quot;));</pre><h3>🧠 4. Advanced Helpers</h3><h3>🟪 untracked(() =&gt; …)</h3><p>👉 <em>“Read a signal without reacting to it.”</em></p><pre>const snapshot = untracked(user);</pre><h3>🟨 asReadonly()</h3><p>👉 <em>“Expose the value but prevent writes.”</em></p><pre>readonlyUser = user.asReadonly();</pre><h3>🟫 toSignal(observable)</h3><p>👉 <em>“Make an Observable behave like a signal.”</em></p><pre>const data = toSignal(api$, { initialValue: null });</pre><h3>🟩 toObservable(signal)</h3><p>👉 <em>“Turn a signal into an Observable stream.”</em></p><pre>const data$ = toObservable(count);</pre><h3>🏗️ 5. Signal Store Pattern (Best Practice)</h3><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthStore {<br>  private _user = signal&lt;User | null&gt;(null);<br>  user = this._user.asReadonly();<br><br>  isLoggedIn = computed(() =&gt; !!this._user());<br><br>  setUser(u: User) { this._user.set(u); }<br>  logout() { this._user.set(null); }<br>}</pre><p><strong>Plain English:</strong><br> 👉 <em>“A centralized, reactive box of state + derived values + methods.”</em></p><h3>👀 6. Signals in Components</h3><pre>&lt;div&gt;{{ count() }}&lt;/div&gt;</pre><p>👉 <em>“When this signal changes, only this part of the UI updates.”</em></p><h3>⚡ 7. Signals + OnPush</h3><p>👉 <em>“OnPush becomes automatic — signals tell Angular exactly where to update.”</em></p><h3>🚫 8. Anti-Patterns</h3><p>❌ Using .value in components<br> ❌ Mutating without .mutate()<br> ❌ Circular store dependencies<br> ❌ Using BehaviorSubjects for UI state<br> ❌ Using effects to update state (use set/update instead)</p><h3>⭐ 9. One-Liners (Perfect Memory Hooks)</h3><ul><li>signal() → “Reactive variable.”</li><li>computed() → “Live formula.”</li><li>effect() → “React to changes.”</li><li>set() → “Replace it.”</li><li>update() → “Return a new version.”</li><li>mutate() → “Modify the object.”</li><li>untracked() → “Read once, not reactive.”</li><li>asReadonly() → “Expose, don’t allow writes.”</li></ul><h3>REACT → ANGULAR SIGNALS TRANSLATION SHEET</h3><h3>(From a React Developer’s Perspective — written for you.)</h3><h3>⭐ React useState → Angular signal()</h3><p>React Angular const [count, setCount] = useState(0) const count = signal(0) count count() setCount(x) count.set(x)</p><p><strong>Plain English:</strong><br> 👉 <em>“signal() is Angular’s version of useState, but reactive everywhere, not just the render tree.”</em></p><h3>⭐ React useMemo → Angular computed()</h3><p>React Angular useMemo(() =&gt; value * 2, [value]) computed(() =&gt; value() * 2)</p><p><strong>Plain English:</strong><br> 👉 <em>“computed() is a memoized formula that updates only when needed — no dependency arrays.”</em></p><h3>⭐ React useEffect → Angular effect()</h3><p>React Angular useEffect(() =&gt; {...}, [deps]) effect(() =&gt; {...})</p><p><strong>Plain English:</strong><br> 👉 <em>“effect() runs when any signal it reads changes — dependencies are automatic.”</em></p><h3>⭐ React Component State → Angular Component + Signals</h3><p>React:</p><pre>const [count, setCount] = useState(1);</pre><p>Angular:</p><pre>count = signal(1);</pre><h3>⭐ React Props → Angular Inputs OR inject store</h3><p>React:</p><pre>&lt;MyComp user={user} /&gt;</pre><p>Angular:</p><pre>&lt;my-comp [user]=&quot;user()&quot;&gt;&lt;/my-comp&gt;</pre><p>Or global state:</p><pre>constructor(public auth: AuthStore) {}</pre><h3>⭐ React Context → Angular Signal Store</h3><p>React:</p><pre>&lt;UserContext.Provider value={user}&gt;<br>  &lt;App /&gt;<br>&lt;/UserContext.Provider&gt;</pre><p>Angular:</p><ul><li>Create a store with signals</li><li>Inject it anywhere</li></ul><p>👉 No Provider trees<br> 👉 No context rerenders<br> 👉 Fine-grained updates only</p><p>I hope this guide helps someone else make sense of Angular Signals as they did for me.</p><p>If you’d like to go deeper, the official Angular documentation is excellent and constantly evolving. <br>You can find it here: <a href="https://angular.dev/guide/signals?utm_source=chatgpt.com"><strong>https://angular.dev/guide/signals</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86ab8bed770c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interviewing as a Skill: A React Study Guide]]></title>
            <link>https://blog.stackademic.com/interviewing-as-a-skill-a-react-study-guide-24a02d0307d8?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/24a02d0307d8</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[job-interview]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 11:59:00 GMT</pubDate>
            <atom:updated>2024-06-12T00:59:35.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9TWY3s66lS2vPgqT1xsiQ.png" /></figure><p>Interviewing can be a skill in its own right. To help you refresh your memory and prepare for questions that might come your way, I have created a quick reference React study guide. Having interviewed many times and completed numerous technical assignments — some in boardrooms on projectors with 3–4 senior developers watching me code 😅 — I know the importance of preparation. Each time I encountered a question I couldn’t answer clearly, I updated this list.</p><p><strong>Document Outline</strong></p><p><strong>1. Introduction to JSX in React</strong></p><p>- Explanation of JSX and its role in React development.</p><p><strong>2. State Management in React</strong></p><p>- Overview of different methods of state management including local state with `useState`, global state with Context API, and using external libraries like Redux.</p><p><strong>3. Common React Interview Questions</strong></p><p>- A comprehensive list of potential interview questions categorized by difficulty and topic.</p><p><strong>4. Explanation of Application Side Effects</strong></p><p>- Detailed explanation of what constitutes side effects in applications, especially in the context of React.</p><p><strong>5. Understanding Pure Functions</strong></p><p>- Definition and characteristics of pure functions in programming.</p><p><strong>6. Overview of Variable Types</strong></p><ul><li>Discussion on different kinds of variables, focusing on primitives and reference types.</li></ul><h3>Introduction to JSX in React</h3><p>JSX stands for JavaScript XML. It is a syntax extension for JavaScript, commonly used with React to describe what the UI should look like. JSX allows you to write HTML structures in the same file as JavaScript code, making the structure of your component’s UI more readable and expressive. It is similar to a template language but comes with the full power of JavaScript.</p><p>JSX tags have a tag name, attributes, and children just like HTML. When you use JSX to define components, it gets transformed into JavaScript objects that React can understand. This transformation is typically done using a tool like Babel. Here are a few key points about JSX:</p><p><strong>1. JSX is optional:</strong> You can write React applications without JSX, but it’s widely used because it visually resembles the UI it will produce, making the code easier to understand.</p><p><strong>2. HTML-like syntax:</strong> JSX allows you to write HTML-like tags in your JavaScript code, including a tag name, attributes, and children.</p><p><strong>3. JavaScript Expressions:</strong> JSX allows you to embed JavaScript expressions inside curly braces `{}`, so you can dynamically construct your UI based on props, state, or other JavaScript logic.</p><p><strong>4. Component nesting:</strong> JSX supports component nesting, where components can be nested inside other components, mimicking the structure of HTML but with reusable components.</p><p>Overall, JSX enhances the development experience in React by providing a concise and familiar syntax for declaring the structure of user interfaces.</p><h3>State Management in React</h3><p>State management in React refers to how you handle and update data (or state) across your application. React has built-in capabilities for local state management, but for larger applications, you might need more sophisticated approaches. Here’s an overview of different strategies for state management in React:</p><p><strong>1. Local State Management: </strong>Local state is managed within a component and is not shared with other components unless passed down as props. This is typically handled using the `useState` hook in functional components.</p><pre><br>import React, { useState } from &#39;react&#39;;<br><br>function Counter() {<br>const [count, setCount] = useState(0);<br>return (<br>&lt;&gt;<br>&lt;p&gt;{count}&lt;/p&gt;<br>&lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>&lt;/&gt;<br>);<br>}</pre><p><strong>2. Lifting State Up:</strong> When multiple components need to access or modify the same state, you can lift the state up to their closest common ancestor. This involves passing the state and functions that modify the state as props to the child components.</p><p><strong>3. Context API:</strong> For global state management, React’s Context API allows you to share values across the entire app without having to explicitly pass props through every level of the tree.</p><pre>import React, { createContext, useContext, useState } from &#39;react&#39;;<br><br>const CountContext = createContext();<br><br>function App() {<br>const [count, setCount] = useState(0);<br><br>return (<br>&lt;CountContext.Provider value={{ count, setCount }}&gt;<br>  &lt;Counter /&gt;<br>&lt;/CountContext.Provider&gt;<br>);<br><br>}<br>function Counter() {<br>const { count, setCount } = useContext(CountContext);<br><br>return &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Count: {count}&lt;/button&gt;;<br>}</pre><p><strong>4. Redux: </strong>Redux is a popular library for managing global state. It uses a single immutable state container (“store”), and changes to the state are made through specific actions and reducers. Redux is particularly useful for large applications where state management becomes complex.</p><pre>import { createStore } from &#39;redux&#39;;<br><br>// Reducer function<br>function counter(state = 0, action) {<br><br>switch (action.type) {<br>case &#39;INCREMENT&#39;:<br>return state + 1;<br>case &#39;DECREMENT&#39;:<br>return state - 1;<br>default:<br>return state;<br>}<br>}<br><br>// Create Redux store<br>const store = createStore(counter);<br>store.subscribe(() =&gt; console.log(store.getState()));<br><br>// Dispatch actions<br>store.dispatch({ type: &#39;INCREMENT&#39; });<br>store.dispatch({ type: &#39;INCREMENT&#39; });<br>store.dispatch({ type: &#39;DECREMENT&#39; });</pre><p><strong>5. Other Libraries: </strong>Apart from Redux, there are several other libraries and patterns for managing state in React applications:</p><p><strong>- MobX: </strong>A simple, scalable state management solution that uses observable states and is quite intuitive compared to Redux.</p><p><strong>- Recoil:</strong> A state management library developed by Facebook, which provides several utilities for state management in React that are more integrated with React’s concurrent mode.</p><p><strong>- Zustand:</strong> A minimalistic state management solution which is easy to set up and use, suitable for smaller to medium applications.</p><p>Choosing the right state management approach depends on the complexity of your application, team preferences, and the specific problems you’re trying to solve. For simple to moderately complex applications, using React’s built-in state management with <strong>Context API</strong> might be sufficient. For more complex scenarios, you might consider Redux, MobX, or other libraries.</p><h3>Common React Interview Questions</h3><p><strong>Basic Questions</strong></p><p><strong>1. What is React?</strong></p><p>React is a JavaScript library developed by Facebook for building user interfaces. It allows developers to create reusable UI components and manage the state of their applications efficiently.</p><p><strong>2. What are components in React?</strong></p><p>Components are the building blocks of a React application. They can be thought of as custom, reusable HTML elements that encapsulate behavior and rendering logic. There are two types of components: class components and functional components.</p><p><strong>3. What is JSX?</strong></p><p>JSX stands for JavaScript XML. It allows developers to write HTML-like syntax directly in their JavaScript code, making the structure of component UIs more readable. JSX is transpiled to regular JavaScript at build time.</p><p><strong>4. How do you create a component in React?</strong></p><p>A component in React can be created as a class or a functional component. Functional components are simpler and used for components that do not require state management or lifecycle methods.</p><p><strong>5. What are props?</strong></p><p>Props (short for properties) are a way of passing data from parent to child components. They are read-only and help you populate a component with dynamic data.</p><p><strong>6. What is state in React?</strong></p><p>State is a set of data that determines the rendering and behavior of a component. It can change over time, usually in response to user actions or network responses.</p><p><strong>7. Explain the difference between state and props.</strong></p><p>While both props and state hold information that influences the output of render, props are passed to the component (similar to function parameters) whereas state is managed within the component (similar to variables declared within a function).</p><h3>Intermediate Questions</h3><p><strong>8. What are lifecycle methods in React?</strong></p><p>Lifecycle methods are special methods in class components that get called at different stages of a component’s life. They can be used for things like setting up subscriptions and fetching data when a component mounts, or cleaning up before the component unmounts.</p><p><strong>9. How do you handle events in React?</strong></p><p>Events in React are handled by passing functions as event handlers. React events are named using camelCase, rather than lowercase in HTML.</p><p><strong>10. What are keys in React and why are they important?</strong></p><p>Keys help React identify which items have changed, are added, or are removed in lists. They should be given to the elements inside the array to give the elements a stable identity.</p><p><strong>11. How does conditional rendering work in React?</strong></p><p>Conditional rendering in React works by using JavaScript operators like if or the conditional (ternary) operator to create elements representing the current state, and letting React update the UI to match them.</p><p><strong>12. What is the Context API and how is it used?</strong></p><p>The Context API is a way for a React app to effectively produce global variables that can be passed around. This is the alternative to “prop drilling” or moving props from grandparent to child to parent, and so on.</p><p><strong>13. Can you explain the use of `useEffect`?</strong></p><p>The `useEffect` hook lets you perform side effects in function components. It serves the same purpose as `componentDidMount`, `componentDidUpdate`, and `componentWillUnmount` in React classes, but unified into a single API.</p><h3>Advanced Questions</h3><p><strong>14. What are higher-order components?</strong></p><p>Higher-order components (</p><p>HOCs) are functions that take a component and return a new component. They are a pattern derived from React’s compositional nature to reuse component logic.</p><p><strong>15. What are render props?</strong></p><p>Render props refer to a technique for sharing code between React components using a prop whose value is a function.</p><p><strong>16. How do you optimize performance in React applications?</strong></p><p>Performance can be optimized by preventing unnecessary re-renders through memoization techniques, using `React.memo` for functional components, `PureComponent` for class components, and avoiding inline functions as much as possible.</p><p><strong>17. What is React Router and how do you configure it?</strong></p><p>React Router is a standard library for routing in React. It enables the navigation among views of various components in a React Application, allows changing the browser URL, and keeps UI in sync with the URL.</p><p><strong>18. Explain Redux, its core principles, how it integrates with a React app, and its middleware like thunk or saga.</strong></p><p>Redux is a predictable state container for JavaScript apps that helps you write applications that behave consistently. Its core principles include a single source of truth, state is read-only, and changes are made with pure functions. Middleware like Redux Thunk and Redux Saga help manage side-effects in larger applications.</p><p><strong>19. What are hooks in React? Can you name a few commonly used hooks?</strong></p><p>Hooks are functions that let you use state and other React features in functional components. Common hooks include `useState`, `useEffect`, and `useContext`.</p><p><strong>Explanation of Application Side Effects</strong></p><p>The term “application side effects” in software development, particularly in the context of React (or any other frontend framework/library), refers to operations that affect something outside the scope of the function being executed. These are actions that go beyond the local function’s return values and involve interacting with the outside world. Here are some common examples of side effects:</p><p><strong>1. API Calls:</strong> Fetching or sending data to and from external servers.</p><p><strong>2. Manipulating DOM directly: </strong>Although not common in React applications due to its virtual DOM, direct DOM manipulation is considered a side effect.</p><p><strong>3. Subscriptions:</strong> Setting up listeners or subscriptions, such as WebSocket connections or event listeners that might affect other parts of the application or the system.</p><p><strong>4. Timers:</strong> Using timeouts and intervals to execute code asynchronously.</p><p><strong>5. Logging: </strong>Writing to console or sending logs to a remote logging service.</p><p><strong>6. Persisting state:</strong> Saving or retrieving data from local storage, or interacting with databases.</p><p>In React, managing side effects is typically handled in functional components using the `useEffect` hook. This hook is designed to properly manage side effects by providing a way to organize them according to the lifecycle of a component, ensuring that they are handled at the right time and do not lead to bugs or inconsistent states. The `useEffect` hook allows developers to control when the side effect runs based on specific dependencies that are passed to it. This control helps in avoiding unnecessary operations, thus optimizing the application’s performance and behavior.</p><h3>Understanding Pure Functions</h3><p>A pure function is a concept from functional programming that refers to a specific type of function adhering to two main rules:</p><p><strong>1. Deterministic Output:</strong> The output of the function is determined solely by its input values, without observable side effects. This means if you call a pure function with the same arguments, it will always return the same result.</p><p><strong>2. No Side Effects:</strong> The function does not cause any side effects in the system. That is, it doesn’t alter any external state (like global variables, disk space, etc.) nor does it rely on any external state that might change during its invocation.</p><p><strong>Characteristics of Pure Functions:</strong></p><p><strong>- Consistency:</strong> Since the output is only determined by the input, the function’s behavior is predictable and consistent.</p><p><strong>- Reusability and Modularity: </strong>Pure functions can be more easily moved, copied, or refactored without worrying about external contexts.</p><p><strong>- Testability:</strong> Testing pure functions is straightforward since there’s no need to mock a context or maintain external states.</p><p><strong>- Parallel Code: </strong>No dependencies on external state make it safe to run pure functions in parallel, improving performance without race conditions.</p><p>Example in JavaScript:</p><pre>function add(a, b) {<br>return a + b;<br>}</pre><p>This `add` function is pure because it always returns the same output for the same set of input values and does not modify or depend on external data.</p><p><strong>Contrast with Impure Functions:</strong></p><p>An impure function would be one that fails to meet these criteria. For example, a function that involves reading or modifying global variables, or relies on system state like the current time or generating random numbers, would not be considered pure.</p><pre>let counter = 0;<br>function incrementCounter() {<br>counter += 1; // Modifies external state<br>return counter;<br>}</pre><p>This `<strong>incrementCounter</strong>` function is impure because it modifies the external state (counter) and its output depends on the external state.</p><p>Pure functions are a cornerstone of functional programming and can be beneficial in other paradigms too, particularly in managing complexity and enhancing the reliability of applications.</p><h3>Overview of Variable Types</h3><p>In programming, variables are used to store data that can be manipulated and retrieved throughout the code. These variables can hold different types of data, which are broadly classified into two categories: primitive types and non-primitive types (or reference types).</p><p><strong>Primitive Types:</strong></p><p>Primitive types are basic data types that are built into the language and represent a single value. They are not objects and have no methods. Here are the common primitive data types found in languages like JavaScript:</p><p><strong>1. Boolean:</strong> Represents a logical entity and can have two values: `true` and `false`.</p><p><strong>2. Null: </strong>Represents the intentional absence of any object value.</p><p><strong>3. Undefined:</strong> Indicates that a variable has not been initialized and the value is absent.</p><p><strong>4. Number:</strong> Represents both integer and floating-point numbers. In languages like JavaScript, all numbers are floating point.</p><p><strong>5. BigInt:</strong> Represents integers with arbitrary precision; useful for very large numbers.</p><p>6. String: Represents a sequence of characters used for storing text.</p><p><strong>7. Symbol: </strong>A unique and immutable primitive introduced in ECMAScript 2015, useful for creating private identifiers for object properties.</p><p>In languages like Java, additional primitive types include:</p><p>- <strong>Byte: </strong>An 8-bit signed integer.</p><p>- <strong>Short: </strong>A 16-bit signed integer.</p><p>- <strong>Int: </strong>A 32-bit signed integer.</p><p>- <strong>Long: </strong>A 64-bit signed integer.</p><p>- <strong>Float:</strong> A single-precision 32-bit IEEE floating point.</p><p>- <strong>Double: </strong>A double-precision 64-bit IEEE floating point.</p><p>- <strong>Char:</strong> A single 16-bit Unicode character.</p><p><strong>Non-Primitive (Reference) Types:</strong></p><p>Non-primitive types, also known as reference types, include any data type that represents a compound value — that is, they can hold collections of values or more complex entities. Unlike primitives, reference types refer to objects rather than holding a value directly. Here are some common non-primitive types:</p><p><strong>1. Object:</strong> The base type of all non-primitive types in JavaScript, including functions, arrays, and more.</p><p><strong>2. Array: </strong>An ordered list of values, which can be of any type, including other arrays.</p><p><strong>3. Function:</strong> A callable object that executes a block of code.</p><p><strong>4. Date:</strong> Represents a single moment in time in a platform-independent format.</p><p><strong>5. RegExp: </strong>Represents regular expressions that can be used for pattern matching within strings.</p><p>Key Differences:</p><p><strong>- Storage:</strong> Primitive types store values directly, whereas reference types store references to their data (the memory location).</p><p><strong>- Copying Values:</strong> When you copy a primitive type from one variable to another, a fresh copy of the value is created. For reference types, copying the value from one variable to another simply copies the reference, not the actual data, meaning both variables point to the same object.</p><p>-<strong> Comparison:</strong> Comparisons between primitive types check their values, while comparisons between reference types check whether the references point to the same object, not whether the content is identical.</p><p>Understanding these types and how they operate is crucial for effective programming and optimizing memory usage in applications. Each type has its specific uses and can behave differently based on the operations applied to it.</p><p>- -</p><p>I hope these help you get your next job. Remember, interviewing is its own skill separate from programming. You need to practice it to get better at it. You’re doing great!</p><p>Best of luck! ✌🏼</p><h3>Stackademic 🎓</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a> | <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://stackademic.com/"><strong>Stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24a02d0307d8" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/interviewing-as-a-skill-a-react-study-guide-24a02d0307d8">Interviewing as a Skill: A React Study Guide</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing Between “type” and “interface” in React]]></title>
            <link>https://danleitch.medium.com/choosing-between-type-and-interface-in-react-da1deae677c9?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/da1deae677c9</guid>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[comparison]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[type]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 14:16:51 GMT</pubDate>
            <atom:updated>2023-11-22T11:07:13.845Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first dipped my toes into the world of development, I recall a vivid memory of discussing TypeScript with one of my seniors. Eager to understand the nuances, I asked, “When do I use a custom type versus an interface?” Without hesitation, he responded, “We always use interfaces as the default.” This advice seemed straightforward enough, and for a while, I adhered to it diligently.</p><p>However, as I delved deeper into React and wrestled with complex projects, I realized that the ‘interface as default’ approach wasn’t always fitting. My explorations and projects led me to question that initial guidance. After years navigating the React trenches and countless hours of research, I’ve come to understand that the choice between “<strong>type</strong>” and “<strong>interface</strong>” isn’t black and white. The real answer is, it depends.</p><p>If you’re wading through TypeScript with React, pondering whether to use “type” or “interface” to define your prop types, you’re not alone. In the ever-evolving landscape of React development, both have their unique advantages and applications. So, let’s embark on a journey to decipher when to use which, and why.</p><h3><strong>Use Cases for “type”</strong></h3><p><strong>- Union Types:</strong> This allows a value to be one of several types. An ideal use case for situations where a value might have multiple forms.</p><pre> type ButtonProps = {<br>   label: string<br>   onClick: () =&gt; void<br> } | null</pre><ul><li><strong>Intersection Types</strong>: Perfect for when you want to combine multiple types.</li></ul><pre>type Named = {<br>  name: string<br>}<br> <br>type Aged = {<br>  age: number<br>}<br> <br>type Person = Named &amp; Aged </pre><ul><li><strong>Tuple Types:</strong> Useful for arrays with a fixed number of elements of specific types.</li></ul><pre>type Response = [Boolean, string]</pre><p>- <strong>Type Operators</strong>: Unique features like keyof, typeof, and in aren’t available on interfaces.</p><h3><strong>Use Cases for “interface”</strong></h3><ul><li><strong>Extendibility</strong>: Interfaces excel at being extensible. They’re fantastic for React component props when building extensible libraries or components.</li></ul><pre>interface ButtonProps {<br>  label: string<br>  onClick: () =&gt; void<br>}<br><br>interface IconButtonProps extends ButtonProps {<br>  icon: string<br>}</pre><p>- <strong>Declaration Merging</strong>: Automatically merge multiple interface declarations with the same name.</p><pre>interface User {<br>  name: string<br>}<br> <br>interface User {<br>  age: number<br>}</pre><p>- <strong>Clearer Intent for Objects</strong>: A reader sees an interface and immediately recognizes an object’s shape, ideal for React components.</p><h3><strong>Performance Insights</strong></h3><p>You might wonder, is there a performance difference between these two? In TypeScript, “type” and “interface” are design-time constructs, and they don’t exist in the transpiled JavaScript. Thus, there’s no performance difference between them.</p><h3><strong>Readability and Developer Experience</strong></h3><p>While some developers resonate with the clarity of interfaces due to their background in OOP languages, TypeScript’s `type` has its own charm, particularly for complex type relationships.</p><h3><strong>Conclusion</strong></h3><p>When working on React projects:</p><p>- Start with `interface` for React component prop types, considering its extensibility and clear indication of an object shape.<br> <br>- For intricate type manipulations or when utilizing unions, intersections, etc., go for `type`.</p><p>The main thing is to maintain consistency in your project or team. Discuss, decide on a convention, and then stick with it.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da1deae677c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up Multi-Flavor Android Analytics with Firebase in Flutter]]></title>
            <link>https://blog.stackademic.com/setting-up-multi-flavor-android-analytics-with-firebase-in-flutter-3be96c3a246a?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3be96c3a246a</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[andriod]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 19:00:32 GMT</pubDate>
            <atom:updated>2023-08-10T12:15:14.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoaSR6dslbGv4jBVKK0vNw.jpeg" /></figure><p>Working with a multi-flavored Flutter application for Android can make setting up Firebase for each flavor a challenging task, especially when good guides are so hard to fine. This guide will provide a step-by-step walkthrough of this process, explaining the reasoning behind each decision and how to set up your Firebase repository.</p><h3>Starting the Setup</h3><p>Suppose you have a pre-existing Flutter application for both Web and mobile (iOS and Android), and you’re trying to deploy it with Firebase.</p><p>Start by going to the Firebase console. Click the “+” button and select the Flutter option, as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*1pVY6AEPW6h1gto_XyUDuw.png" /></figure><p>Ensure that the Firebase CLI is installed on your PC. If you already have a pre-existing project, Flutter should be installed too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3J_krJ15QXQ6Mq0cVOWjw.png" /></figure><h3>Following the Instructions</h3><p>Take your time to read the instructions carefully. During this process, you’ll be prompted to select which apps you’d like to connect in your terminal. In my case, I needed to connect the <strong>Web, Android, and iOS apps.</strong></p><p>Firebase will add some files and install some dependencies, which you can notice in your Git as new files are added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Svb1GJiNLIWDyby86jT3PQ.png" /></figure><h3>Updating Your Main File</h3><p>Next, navigate to your lib/main.dart file and add the necessary dependencies and Firebase initialization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P9_tCRAcAakknhx652PaUA.png" /></figure><p>Your implementation might differ from mine, as our application is already in production. Regardless, my approach might provide some insight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMod0A57c1jAeSE62QhNhA.png" /></figure><blockquote>Now your application should be connected to Firebase. 🔥</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/0*Flf6CYB6UzUV-REE.gif" /></figure><h3>Setting Up Google Analytics</h3><p>Google provides a wide range of integrations. Navigate to the integration tab and activate Google Analytics, as shown below (mine is already activated).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JXY8r_vdwLCBXwij2xyH6A.png" /></figure><h3>Checking the Connections</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGSpqnSJ4h0VegLcUmTmVQ.png" /></figure><p>Return to your dashboard to ensure that each part of your application is correctly connected. Let’s start with your web application scroll down, go to the CDN section, and insert the given script at the bottom of your index.html file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D0sR5lhHDRLWFdymS_XnjQ.png" /></figure><p>here is mine notice its placement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s7ckbySPeQrw6sVLvDcs6g.png" /></figure><p>it might already be there, and that should be all you need for web, an edited <strong>lib/main.dart</strong> and <strong>web/index.html</strong> you should be collecting data on your site visitors now.</p><h3>Connecting Android</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWf4jrHH-wlIcB4o2yafEQ.png" /></figure><p>Next, download the google-services.json file and place it in the android/app directory of your project. Now, building your application should provide mobile data feedback, which can be sorted how you like with filters.</p><h3>Managing Multi-Flavors</h3><p>In Android app development, flavors (or “product flavors”) are used to create different versions of an app from the same codebase. This feature of the Android Gradle plugin allows developers to manage variations in their apps without duplicating code.</p><p>Flavors can be used to manage environments (like “dev”, “staging”, and “production”), create white-label apps for different clients, or to conduct A/B testing for app performance.</p><p>For my project, I used it for white-labeling.</p><h3>Step 1: Creating Firebase Projects</h3><p>For each flavor of your application (such as development, staging, production, client1, client2, client1Staging, client1Prod, etc.), create a separate Firebase project through the Firebase Console. Ensure that the correct application ID is used for each flavor when adding an Android app to each Firebase project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*v3CrBQEo9WgyiJImy9CsxQ.png" /></figure><h3>Step 2: Downloading Firebase Config Files</h3><p>After all your Android flavors have been created, download the google-services.json files for each flavor. Don&#39;t download them as you create them, because they all contain information about each other. This misstep can cost hours of work, as I discovered the hard way. Don’t be misled by the instruction the guide gives you, we are doing a different deployment this only works as mentioned above, single android app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBlGlh74bq_bEqltTXouFA.png" /></figure><h3>Step 3: Placing the Config Files</h3><p>In your Android app/src directory, create new directories for each flavor, and place each google-services.json file in the corresponding flavor&#39;s directory, something like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*X4EAiWmFF93nC3X4SEnYoQ.png" /></figure><h3>Step 4: Configuring build.gradle Files</h3><p>Define your app flavors in the Android project. Go to the Android project in the Flutter directory (your_flutter_project/android/app/build.gradle), find the productFlavors section (or create one if it doesn&#39;t exist), and define your flavors. Make sure that your clients listed above match their respective directories exactly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*m_rohUacMu__pJ5UfgScdw.png" /></figure><p>Adjust both build.gradle files in your project. Here&#39;s what the android/build.gradle file should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUC7hddMvtUyubPVkg2c6w.png" /></figure><pre>classpath ‘com.google.gms:google-services:4.3.10’</pre><p>the other one in andriod/app/build.gradle should have the following in it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6j3RYWYdmPQzMog1vpU0g.png" /></figure><p>This information was given on the creation of the project.</p><p>Here is the one form my project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkiDfarwCv_jL05h-EKtdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MID5TH9sJNb6m8BbekZOGA.png" /></figure><p>If you’re missing the required dependencies at the end of your android/app/build.gradle file add them in, I know mine where missing.</p><h3>Step 5: Sync Gradles</h3><p>VS Code doesn’t have a built-in function to “Sync Gradle” as Android Studio does. You can, however, execute a Gradle build or another Gradle task from the command line in the terminal of VS Code, which refreshes Gradle as needed.</p><p>Navigate to your Android project root directory using the cd command, then run a Gradle command like this:</p><pre>cd /android<br>./gradlew assembleDebug</pre><p>This tells Gradle to build a debug version of your app, refreshing as needed during this process.</p><h3>Step 6: Building Your APKs</h3><p>You can now build your APKs using the shell script. Each flavor will use its corresponding google-services.json file, which contains the Firebase credentials for the respective environment.</p><p>For example, your command might look something like this:</p><pre>flutter -v build apk --release --flavor=&quot;client1staging&quot; --dart-define=DEFINE_SLUG=&quot;client1&quot; --dart-define=DEFINE_ENV=&quot;staging&quot; --dart-define=DEFINE_HOST=&quot;mydatabase.com&quot;</pre><p>If your build fails and the terminal cuts off, preventing you from seeing all your logs, you can append &gt; somefilename.txt to the end of your build command to create a log file in your root directory.</p><p>like this</p><pre>flutter -v build apk --release --flavor=&quot;client1staging&quot; --dart-define=DEFINE_SLUG=&quot;client1&quot; --dart-define=DEFINE_ENV=&quot;staging&quot; --dart-define=DEFINE_HOST=&quot;mydatabase.com&quot; &gt; somefilename.tx</pre><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKxcUOCj5jKVYMJElhrnrA.png" /></figure><p>The setup outlined above allows you to manage multiple flavors in your Flutter app, each with its own Firebase configuration. With this setup, you can control your Firebase services per environment, thereby avoiding unwanted interactions between data from different environments. Remember to ensure that the correct Firebase credentials are used in each environment to avoid any mix-ups or errors.</p><p><em>Thank you for reading until the end. Please consider following the writer and this publication. Visit </em><a href="https://stackademic.com/"><em>Stackademic</em></a><em> to find out more about how we are democratizing free programming education around the world.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3be96c3a246a" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/setting-up-multi-flavor-android-analytics-with-firebase-in-flutter-3be96c3a246a">Setting Up Multi-Flavor Android Analytics with Firebase in Flutter</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Initializing a Firewall on an Ubuntu Cloud Server]]></title>
            <link>https://danleitch.medium.com/initializing-a-firewall-on-an-ubuntu-cloud-server-7e0d2c88f0be?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e0d2c88f0be</guid>
            <category><![CDATA[ubuntu-server]]></category>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 09:22:46 GMT</pubDate>
            <atom:updated>2022-03-31T03:08:50.242Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*uSEevqXVvrwVFa5njP05pA.jpeg" /></figure><h4><strong>TLDR: </strong>In this guide, I will give basic instructions and explanations for securing your server.</h4><p>👉 <strong>I’m not a professional on internet security 👈</strong></p><p>Let’s get stuck in…</p><p>When you launch a remote instance the firewalls are disabled and everything is open as they assume that you will need everything open for the initial setup, this kind of set-up would look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uz9_m2rT1nE2P_RSA6fJKQ.jpeg" /></figure><p>As you can imagine this is the most un-secure setup you can have, this setup solely relies on the strength of your password, and should it not be a strong password it could be vulnerable to Brute-force attacks amongst many other kinds of exploits.</p><p><strong>SIDE NOTE / Point of Interest:</strong></p><p>You can Google ‘<a href="https://tmedweb.tulane.edu/content_open/bfcalc.php?uc=1&amp;lc=3&amp;nu=8&amp;sc=1&amp;ran=&amp;rans=&amp;dict=">Brute Force Calculator</a>’ and find a site that will let you know how strong your password is and how long it would take to crack should someone try brute force attack your login, take this one<a href="https://tmedweb.tulane.edu/content_open/bfcalc.php"> I found</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YTCvFN_u44xJUonimABFg.png" /></figure><p><strong>A strong password is a non-negotiable 1st step in securing your server.</strong> There are many sites out there that will help you make a strong random password here is one I found through another Google search. A password like the one below would take an extremely long time to Bruteforce attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P4vhQETo8bYN34Gmea3_DA.png" /></figure><p>To get the firewall set up and going we will be using a really neat package called <a href="https://help.ubuntu.com/community/UFW">Uncomplicated Firewall</a> (UFW). UFW should be installed by default on Ubuntu server. If it is not for some reason, you can install it with.</p><pre>sudo apt install ufw</pre><p>from there we can we will need to block all the open ports, and create exceptions for the ones we would like open, like <strong>port 22 </strong>for <strong>SSH etc.<br></strong>For me, I have port 22 and port 8080 open as I need access to my server and have an application running on port 8080 that I need access to also.</p><p>First, we configure UFW then we turn it on. We do this to avoid being locked out. It sounds obvious I know but trust me you only need the headache of being locked out once to know this is the golden rule initializing a firewall.</p><p>So I’m going to close all ports first by typing</p><pre>sudo ufw default deny incoming</pre><p>Next, let’s add <strong>SSH </strong>or <strong>port 22</strong></p><pre>sudo ufw allow ssh</pre><p>or</p><pre>sudo ufw allow 22</pre><p>Next, I would like to add my application that will be running on port 8080, you can add your application in the same way.</p><pre>sudo ufw allow 8080</pre><p>I think you get the picture.</p><p>Next, we need to activate the UFW we do this by typing</p><pre>sudo ufw enable</pre><p>Fingers crossed you should still be able to get into your server 🤞</p><p>At any point, you can see the status of your firewall by typing</p><pre>sudo ufw status verbose</pre><p>should UFW be off, you will receive a message something like</p><pre>Output</pre><pre>Status: inactive</pre><p>should it be working</p><pre>Output</pre><pre>Status: active<br>Logging: on (low)<br>Default: deny (incoming), allow (outgoing), disabled (routed)<br>New profiles: skip<br><br>To                         Action      From<br>--                         ------      ----<br>22/tcp                     ALLOW IN    Anywhere<br>8080/tcp                   ALLOW IN    Anywhere</pre><p>A good way to check that your firewall is working correctly is to test it.</p><h3><strong>Testing Your FireWall</strong></h3><p>At the time of writing this <a href="https://networkappers.com/tools/open-port-checker">NetWorkAppers</a> has a useful tool for doing this. You simply pop in your IP and the Port you would like to check. As you can see port 22 is open which mean I can SSH into my remote server! 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*mCxGAuLLoPpx12ujZafMvw.png" /></figure><p>Then pick another port that shouldn’t be open and test, I used 8085 and it was blocked. If this interests you and you would like to learn more <a href="https://www.google.com/search?q=Penetration+test+ports&amp;sxsrf=APq-WBsAdKZLi0tbiB_3weReZ93oODD4cw%3A1648111197184&amp;ei=XS48YoTyCuKEhbIPqd6SqAI&amp;ved=0ahUKEwjElNXTrN72AhViQkEAHSmvBCUQ4dUDCA4&amp;uact=5&amp;oq=Penetration+test+ports&amp;gs_lcp=Cgdnd3Mtd2l6EAMyBggAEBYQHjIGCAAQFhAeMgYIABAWEB4yBggAEBYQHjIGCAAQFhAeMgYIABAWEB46BwgjELADECc6BwgAEEcQsAM6CggAEEcQsAMQyQM6CwgAEIAEELEDEIMBOgUIABCABDoICAAQgAQQyQNKBAhBGABKBAhGGABQhwRY5RJg7BNoAXABeACAAYcCiAGLCpIBAzItNZgBAKABAqABAcgBCcABAQ&amp;sclient=gws-wiz">Google Penetration testing</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*om07QsMpFk7EL13i-o5mHA.png" /></figure><p>Below is a nice visualization of what we have accomplished here and what you will be left with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7SJB7mnEBJFar4d1WMz9ig.jpeg" /></figure><p>Congratulations you have a basic working firewall with hopefully a bit of understanding.</p><p>There are loads more settings and preferences you can use to `beef up` your security, some of these are found in the UFW config file.</p><pre>sudo nano /etc/default/ufw</pre><p>and others can be implemented via the CI or 3rd party packages such as</p><p>1. Failtoban<br>2. Disabling Root user<br>3. Public Key authentication<br>4. Geo-blocking<br>5. Reverse Proxies: I use Nginx but Traefik seems to be popular these days.<br>6. Cloudflare CDN<br>7. Moving SSH to a different port</p><p>All of the above I highly recommend for improved server security.</p><p><strong>Be Safe &amp; Good Luck</strong> ✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e0d2c88f0be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How JavaScript uses Hashing]]></title>
            <link>https://danleitch.medium.com/how-javascript-uses-hashing-ecad106b2e31?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecad106b2e31</guid>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[password-management]]></category>
            <category><![CDATA[hashing-algorithm]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Wed, 10 Feb 2021 12:15:22 GMT</pubDate>
            <atom:updated>2022-04-01T10:01:53.052Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TLDR — </strong>Hashing has to do with taking a certain value (for example your password), applying some kind of mathematical operation to it (MD5, SHA-1, SHA-2) called a hashing algorithm or a hashing function, and getting the resulting changed value (known as a hash or hash value or digest message). This is commonly used for passwords and checking document accuracy. See the below image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*E37OHz6xitMHuhhJ.png" /><figcaption><a href="https://blog.jscrambler.com/hashing-algorithms/#:~:text=A%20hashing%20algorithm%20is%20a,way%20function%2C%20infeasible%20to%20invert."><em>Source</em></a></figcaption></figure><p>They are three main uses for hashing namely document hashing for ensuring accuracy, password hashing for increased security and hash tables for indexing data.</p><h3>1. Document Hashing for Ensuring Accuracy</h3><p>Here is the problem document hashing solves: let us say you have a large legal document being emailed around and the receipt has no way to tell if someone has altered one of the many pages of the documents. Perhaps someone added a ‘0’ to the sales price or took out a clause. How would you know?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Wm-vj4EzUSMxzvLU.png" /><figcaption><a href="https://blog.jscrambler.com/hashing-algorithms/#:~:text=A%20hashing%20algorithm%20is%20a,way%20function%2C%20infeasible%20to%20invert."><em>Source</em></a></figcaption></figure><p>Document hashing can solve this problem as the sender could produce a hash value of the document by typing:</p><pre>(Example in Lunix)</pre><pre>#Input<br>sha256sum /path/to/file</pre><pre>#RESULTING HASH VALUE<br>c01b39c7a35ccc3b081a3e83d2c71fa9a767ebfeb45c69f08e17dfe3ef375a7b</pre><p>Once done the sender could send the file as per normal along with the hash value. The receipt of the document could repeat the above steps and then compare the hash values. Should they not be the same you know that the document is not the same and that was sent it has been changed in some way, see example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*p17UVFNlHQDahgzA.png" /><figcaption><a href="https://blog.jscrambler.com/hashing-algorithms/#:~:text=A%20hashing%20algorithm%20is%20a,way%20function%2C%20infeasible%20to%20invert."><em>Source</em></a></figcaption></figure><p>A real-world example of this can be seen on <a href="https://ubuntu.com/">Ubuntu’s </a>website where their ISO for their operating system comes with a hash value so that should you want to check you can be sure that what you have is the exact same one they released. <a href="https://ubuntu.com/tutorials/how-to-verify-ubuntu#1-overview">See here for more of this</a></p><h3>2. Password Hashing for Increased Security</h3><p>For security reasons, you may want to store passwords as a hash value (it is industry standard to store passwords in a hash value). These guards against the possibility that someone who gains unauthorized access to your database can retrieve the passwords of every user in the system. Hashing performs a <strong>one-way</strong> transformation on a password, turning the password into another String, called the <strong>hashed password</strong>. “One-way” means that it is practically impossible to go the other way — to turn the hashed password back into the original password.</p><p>See this Node.js example below.</p><pre>// Node.js using the crypto module</pre><pre>const crypto = require ( &#39;crypto&#39; ); //line 1</pre><pre>const hash = crypto.createHash( &#39;sha256&#39; ); //line 2</pre><pre>hash.update( &#39;some data to hash&#39; ); //line 4</pre><pre>console .log(hash.digest( &#39;hex&#39; )); //line 5</pre><pre>// Prints:</pre><pre>// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50</pre><p>When a member attempts to log in the Personalization module takes the supplied password, performs a similar one-way hash, and compares it to the database value. If the passwords match, then login is successful if not a login error will occur. See the below example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*ibHYhXBFFSQxXT8V" /><figcaption><a href="https://www.slideshare.net/shimulsakhawat/hashing-51192541">Source</a></figcaption></figure><h3>3. Hash Tables for Quick Data Indexing</h3><p>You can also have hashing functions that receive a string or number value as input and produce an integer as output. These types of hashing algorithms are used to create hash tables. Hash tables store key-value pairs. For example, imagine that you would like to store the names and telephone numbers of a group of people. The key could be the person’s name and the value could be the telephone number (see the image below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*ZXlVqO1YNRdBncIObYo5Yw.png" /><figcaption><a href="https://users.cs.fiu.edu/~giri/teach/3530/f16/Lectures/LecX-Hashing.pdf">Source</a></figcaption></figure><p>To create a hash table to store this information, the key would be passed to the hashing function. The hashing function would produce an integer number as output. This number would be used as the index of where the value would be stored in the hash table. When you want to look up a person’s telephone number, you can hash that person’s name and know exactly where (at which index) in the hash table the number can be found.</p><p><strong>Collisions</strong></p><p>It is possible that, when filling up the hash table, you get collisions. A collision is when two or more keys have the same hash value and are thus given the same index number in the hash table. Collisions can be handled by using either<strong> separate chaining </strong>(if the position is already full, place the value in a list associated with that index) or <strong>open addressing</strong> (if the position is already taken, place the value in another open position in the hash table).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PpmFEbRhJ8TYuDkCeeekw.png" /><figcaption><a href="https://www.cs.usfca.edu/~galles/visualization/ClosedHash.html">cs.usfca.edu</a></figcaption></figure><p><a href="https://www.cs.usfca.edu/~galles/visualization/ClosedHash.html">This tool </a>above can help visualize how each of the different open addressing methods works. A top tip would be to slow it down and look at the math taking place and to understand what is going on and then to input that same number in again. Watch how it resolves the collision with <strong>open addressing.</strong></p><p>Thanks for reading this I hope it helped you understand the basics of hashing.</p><p>Check me out on <a href="https://www.linkedin.com/in/danielleitch/"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://github.com/danleitch"><strong>GitHub</strong></a></p><p><strong>Resources</strong></p><p><a href="https://www.youtube.com/watch?v=GI790E1JMgw">Hashing vs Encryption Differences</a></p><p><a href="https://docs.oracle.com/cd/E26180_01/Platform.94/ATGPersProgGuide/html/s0506passwordhashing01.html#:~:text=Hashing%20performs%20a%20one%2Dway,back%20into%20the%20original%20password.">Oracle.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecad106b2e31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Search vs Binary Search]]></title>
            <link>https://danleitch.medium.com/linear-search-vs-binary-search-1e55be4e2565?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e55be4e2565</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[linear-search]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[full-stack-developer]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Thu, 04 Feb 2021 07:42:01 GMT</pubDate>
            <atom:updated>2022-02-16T03:42:35.721Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TLDR — </strong>A<strong> </strong>Linear search cycles through an array from start to finish whilst a binary search breaks the array into halves and does a half-interval search. If the variable is not found it breaks the array into another half based upon with its position being too high or too low relative to the search topic, as seen below. In <em>general </em>a binary search is much faster for large arrays.</p><p>Have a look at this gif below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*9ucnO1Ymbl-qDhJFpgZ6Tw.gif" /><figcaption><a href="https://www.interviewbit.com/courses/programming/topics/binary-search/">Source</a></figcaption></figure><h3>Linear Search</h3><p>A linear search makes more sense in specific circumstances:</p><ul><li>If your array is guaranteed to be small. There’s not much sense in having a fancy binary search for an array of 3 in length. [“Saab”, “Volvo”, “BMW”]</li><li>If you are just implementing the simplest possible solution and don’t care about speed, linear search would be a good choice.</li></ul><h3>Binary Search</h3><p>A Binary search is:</p><ul><li>much fast than a linear search for larger arrays.</li><li>a relatively simple algorithm to implement.</li></ul><p>The biggest advantage is the speed at which a binary search works, this can be best measured by Big O Notation — if you are not updated with Big O Notation, you can see <a href="https://medium.com/r?url=https%3A%2F%2Fdanleitch.medium.com%2Fbig-o-notation-basics-for-web-developers-af02ec3b89f">my post</a> on it here and come back when you are done.</p><h3>Big O Notation</h3><p>Let’s compare these two searches to get a proper understanding of the performance increase binary can give us.</p><p>With a <strong>linear </strong>search, the time complexity will always be O(n) and this is because as the array increases so the iterations increase with it. For instance, an array with 100 items potentially means 100 iterations as the item we need might be the last item on the array.¹</p><p><strong>Binary </strong>search is a bit of a blend of <strong>O(log n)</strong> and <strong>O(n) </strong>but will usually always be closer to <strong>O(log n)</strong>. This makes the binary search method a more efficient search algorithm as it scales better with the size of the array.</p><p>Going back to the gif at the top of the page, you’ll observe that the total iterations made to find ‘37’ was</p><ul><li>3 for Binary <strong>O(3)</strong></li><li>11 Sequential <strong>O(11)</strong></li></ul><p>making <strong>Binary 3.6 times more effective in our example.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*YBHid6bqpPYdgEVwDoi-Yg.jpeg" /></figure><p><strong>Footnote:</strong></p><p><strong>¹ </strong>It will actually be the max value / 2. For example, if you randomly draw a million numbers from 1–100 it would obvious that 50 would be the average.</p><p><strong>Resources Used</strong></p><ul><li><a href="https://qr.ae/pNzzm5">Quora</a></li><li>I<a href="https://www.interviewbit.com/courses/programming/topics/binary-search/">nterviewbit.com</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e55be4e2565" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Big O notation basics for web developers]]></title>
            <link>https://danleitch.medium.com/big-o-notation-basics-for-web-developers-af02ec3b89f?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/af02ec3b89f</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[dummies-guide]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 14:46:09 GMT</pubDate>
            <atom:updated>2023-06-06T10:45:23.631Z</atom:updated>
            <content:encoded><![CDATA[<h3>Big O Notation Basics for Web Developers</h3><h3>The TLDR — Big O Notation takes a look at how an algorithm scales.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*o-g0L1TfmOQoMgrRGiIg5A.jpeg" /><figcaption><a href="https://towardsdatascience.com/big-o-d13a8b1068c8">Source</a></figcaption></figure><h4>As the size of the data set increases, how does the algorithm speed change?</h4><p>The idea of Big O notation was best understood by me in story form, in 2009 a Cape Town homing pigeon called Winston, made history by beating an ISP by delivering 4GB of data 75km, in just 2 hours 6 minutes and 57 seconds, During the same time, the ADSL line had sent just 4% of the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*E4KT3W8bHpgqvh_T8BmIRw.png" /></figure><p>Big O notation looks at the amount of time something takes verse the volume of data it has</p><p>Listed below are a different scenario</p><h3><strong>O(<em>1</em>)</strong></h3><p>So it takes the pigeon just as long to carry 8GB of data as it does 4GB this is known as O(<em>1</em>) (aka the best-case scenario). In programming terms, your project can scale and no extra completely is involved it would run as per normal, regardless of the volume <strong>(n)</strong> given it.</p><h3><strong>O(<em>n</em>)</strong></h3><p>On the other hand, the <strong>internet speed</strong> and the <strong>amount of data</strong> go up together<strong>, </strong>as the volume you are transferring goes up so does the amount of time it takes to complete the task. We have all experienced this at some point( big files take longer to download than little files). This is known as <strong>O(<em>n</em>)</strong> with the <strong>(<em>n</em>) </strong>as a time variable.</p><p>This<em> ‘</em><strong><em>n’</em></strong><em> </em>variable can be substituted for whatever you are working on, it could represent the number of users on a site, the number of requests being made to an endpoint or the amount of data being pulled from a database.</p><h3><strong>O(n²)</strong></h3><p>An example of<strong> O(n²) </strong>would be like having a loop within a loop — otherwise known as a nested loop. This scenario will lead to poor-performing algorithms as your Big O notation is going to scale quickly.</p><p>This would fall under <strong>O(n²) </strong>on the chart given above</p><p>As an example</p><pre><strong>#Data</strong><br><strong>const </strong>data = [‘A’, ‘B’, ‘C’, ‘D’]</pre><pre><strong>const </strong>data2 = [1, 2, 3, 4, 5]</pre><pre><strong>#loops</strong></pre><pre><strong>for </strong>(let j =0; j &lt; data2.length; j++){</pre><pre>  <strong>for </strong>(let i = 0; i &lt; data.length; i++) {</pre><pre>   console.log(data[i] + data2[j])</pre><pre>}</pre><pre>}<br><strong>#Results</strong></pre><pre>A1<br>B1<br>C1<br>D1<br>A2<br>B2<br><strong>etc...</strong></pre><h3><strong>O(n!) — </strong>Travelling Salesman Problem</h3><p>The last variation of the Big O notation I would like to talk about is <strong>O(n!)</strong></p><p>As <strong>(n)</strong> scales it becomes impractical to solve, this example is seen well in T<a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">he Travelling salesman problem</a>.</p><p><strong>Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*GEsQxH2qqR3V2POykSlJ5g.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">Source</a></figcaption></figure><h4>As the number of cities <strong>or </strong>(<strong>n) </strong>variable increases, so the difficulty increases … <strong>absurdly</strong>.</h4><p>At 10 cities the possible parts to consider are already at 362 880 this would bring your codebase to a standstill as your CPU would be pinned at 100% forever 😂 solving this problem.</p><p><strong>For comparison</strong></p><p>10 cities have 362 880 variations</p><p>if we add 6 more cities to the salesmen’s stop that 1 307 674 368 000 variations.</p><p><strong>That has now increased the difficulty by 3.6 million times</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*2JuSule20x1qkksjPa8Fkg.jpeg" /><figcaption><a href="https://en.wikipedia.org/wiki/Factorial">Source</a></figcaption></figure><p>In summary, developers need to keep their code efficient and easy to run. Big O notation can be a helpful way of doing this.</p><p>Thanks for reading this I hope it helped you understand the basics of Big O notation</p><p><a href="https://www.linkedin.com/in/danielleitch/"><strong>LinkedIn</strong></a></p><p><a href="https://github.com/danleitch"><strong>GitHub</strong></a></p><p><strong>Resources:</strong></p><p><a href="https://stuffihavelearnt.home.blog/2018/09/28/cs50-week-2-algorithms-big-o-notation-recursion/">Stuff I have Learned</a></p><p><a href="https://www.youtube.com/channel/UCFbNIlppjAuEX4znoulh0Cw">Web Dev Simplified</a></p><p><a href="https://www.youtube.com/watch?v=v4cd1O4zkGw&amp;t">HackerRank</a></p><p><a href="https://www.topcoder.com/blog/big-o-notation-primer/#:~:text=O(N!)-,O(N!),6%20seconds%20and%20so%20on.">Topcoder</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af02ec3b89f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async/Await: Modern Concurrency In JavaScript]]></title>
            <link>https://danleitch.medium.com/async-await-modern-concurrency-in-javascript-e8e1a2d9e861?source=rss-5d487289ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8e1a2d9e861</guid>
            <dc:creator><![CDATA[Daniel Leitch]]></dc:creator>
            <pubDate>Sun, 31 Jan 2021 10:55:37 GMT</pubDate>
            <atom:updated>2023-02-10T09:01:06.014Z</atom:updated>
            <content:encoded><![CDATA[<h3>Async/Await: Modern Concurrency in JavaScript</h3><p>Traditional CPUs process tasks in a synchronous order one operation after another, this was enhanced by multi-threaded CPUs, most PCs today have multiple cored CPUs. The exception to this is Quantum computing but this isn’t in the scope of this post and as of now is not working.</p><p>Multi-threaded CPUs enable the CPU to handle multiple problems at once increasing the performance of the PC.</p><p>Due to this ‘code’ is synchronous by nature as it is run by the CPU, in JavaScript you give an instruction, that instruction goes to the ‘Call Stack’. The Call stack is the queue of instructions that are waiting to be executed, all the requests line up in the order that they were called.</p><p>For instance.</p><pre><strong>CODE</strong><br>console.log(&quot;Task1&quot;);<br>console.log(&quot;Task2&quot;);<br>console.log(&quot;Task3&quot;);</pre><pre><strong>RESULT</strong><br>Task1<br>Task2<br>Task3</pre><p>pay attention to the order of execution.</p><p><strong>The problem is what happens if something takes a long time to complete?</strong></p><p>Let us say you are querying a busy database and the response is taking a while to come back? This would be a disaster as it would hold up the queue until it had finished executing.</p><p><strong>This problem was address with Asynchronous functions</strong></p><p>Asynchronous allows us to move aside an instruction until the call stack is clear then it will bring it back and re-queue it.</p><p>See Below</p><pre><strong>CODE</strong><br>console.log(“<strong>Task1</strong>”);<br>setTimeout(function(){ console.log(“<strong>Task2</strong>”); }, 3000);<br>console.log(“<strong>Task3</strong>”);</pre><pre><strong>RESULT</strong><br>Task<strong>1</strong><br>Task<strong>3</strong><br>Task<strong>2</strong></pre><p>So you can see here that we ran the same code as earlier except that we gave “Task 2” an asynchronous function which in this instance is ‘setTimeout’ when the interpreter saw this it placed it aside ( It placed it in the Webapis). Then moved on with the next instruction and call “Task 2” back once it had finished everything else.</p><p>They are many kinds of async function available many of which you may have already used. The ‘fetch’ method for instance.</p><pre>fetch(file)<br>.then(x =&gt; x.text())<br>.then(y =&gt; myDisplay(y));</pre><p>Since Fetch is based on async and await, the example above might be easier to understand like this:</p><pre>async function getText(file) {<br>  let x = await fetch(file);<br>  let y = await x.text();<br>  myDisplay(y);<br>}</pre><h3>The Event Loop</h3><p>The best way to fully grasp the power of async you need to have a good grasp of how the JavaScript event loop works, this video for me was mega important and changed the way I approached coding altogether.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8aGhZQkoFbQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8aGhZQkoFbQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8aGhZQkoFbQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4541402f9dfdaec44f3b5286f3880bb/href">https://medium.com/media/d4541402f9dfdaec44f3b5286f3880bb/href</a></iframe><p>The next step in understanding async is by playing with it, testing different things. <a href="http://latentflip.com/loupe/?code=JC5vbignYnV0dG9uJywgJ2NsaWNrJywgZnVuY3Rpb24gb25DbGljaygpIHsKICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gdGltZXIoKSB7CiAgICAgICAgY29uc29sZS5sb2coJ1lvdSBjbGlja2VkIHRoZSBidXR0b24hJyk7ICAgIAogICAgfSwgMjAwMCk7Cn0pOwoKY29uc29sZS5sb2coIkhpISIpOwoKc2V0VGltZW91dChmdW5jdGlvbiB0aW1lb3V0KCkgewogICAgY29uc29sZS5sb2coIkNsaWNrIHRoZSBidXR0b24hIik7Cn0sIDUwMDApOwoKY29uc29sZS5sb2coIldlbGNvbWUgdG8gbG91cGUuIik7!!!PGJ1dHRvbj5DbGljayBtZSE8L2J1dHRvbj4%3D">Here is a sandbox</a> that allows you to do just that. Play around with various scenarios (don’t forget to open the console when playing around to see the outputs.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3is2DYwu-gA40ncxMK4eSQ.jpeg" /><figcaption><a href="http://latentflip.com/loupe/?code=JC5vbignYnV0dG9uJywgJ2NsaWNrJywgZnVuY3Rpb24gb25DbGljaygpIHsKICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gdGltZXIoKSB7CiAgICAgICAgY29uc29sZS5sb2coJ1lvdSBjbGlja2VkIHRoZSBidXR0b24hJyk7ICAgIAogICAgfSwgMjAwMCk7Cn0pOwoKY29uc29sZS5sb2coIkhpISIpOwoKc2V0VGltZW91dChmdW5jdGlvbiB0aW1lb3V0KCkgewogICAgY29uc29sZS5sb2coIkNsaWNrIHRoZSBidXR0b24hIik7Cn0sIDUwMDApOwoKY29uc29sZS5sb2coIldlbGNvbWUgdG8gbG91cGUuIik7!!!PGJ1dHRvbj5DbGljayBtZSE8L2J1dHRvbj4%3D">Source</a></figcaption></figure><p>Resources:</p><p><a href="https://www.w3schools.com/js/js_api_fetch.asp">W3School</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8e1a2d9e861" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>