<?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 Raja Osama on Medium]]></title>
        <description><![CDATA[Stories by Raja Osama on Medium]]></description>
        <link>https://medium.com/@supersami?source=rss-c7c048bd85b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wG3Aro-PyX0J2jYztungXQ.png</url>
            <title>Stories by Raja Osama on Medium</title>
            <link>https://medium.com/@supersami?source=rss-c7c048bd85b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:27:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@supersami/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[VibeX: the architecture diagram you never have to draw]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/vibex-the-architecture-diagram-you-never-have-to-draw-b74144e5244a?source=rss-c7c048bd85b0------2"><img src="https://cdn-images-1.medium.com/max/2600/1*h_loVDZKrjKhf0p99PUsOw.png" width="3200"></a></p><p class="medium-feed-snippet">Somebody asks where the order state actually lives. You open the Confluence page. It was last edited in 2023, by someone who left in 2024&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/swlh/vibex-the-architecture-diagram-you-never-have-to-draw-b74144e5244a?source=rss-c7c048bd85b0------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/vibex-the-architecture-diagram-you-never-have-to-draw-b74144e5244a?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b74144e5244a</guid>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 17:14:44 GMT</pubDate>
            <atom:updated>2026-09-19T17:14:44.150Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Solving User Authentication in MCP Servers]]></title>
            <link>https://supersami.medium.com/solving-user-authentication-in-mcp-servers-031634547204?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/031634547204</guid>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Fri, 19 Sep 2025 11:54:20 GMT</pubDate>
            <atom:updated>2025-09-19T11:54:20.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzpVFogksX7J6QzWetfw9w.png" /></figure><p>I was building MCP servers recently and hit an interesting problem. MCP (Model Context Protocol) servers are pretty cool — they’re basically the bridge between LLMs and external services. They feel like the future of AI integration, but there’s one thing that caught me off guard: user authentication.</p><h3>The Problem with MCP Authentication</h3><p>Here’s the thing: traditional web authentication doesn’t really work with MCP servers for multi-user scenarios. You can use API keys and secrets (we all know how to do basic token verification), and yes, you can set up authentication during the MCP handshake process. But here’s the catch: that authentication is per-connection, not per-user.</p><p>The real issue is multi-user support. When an LLM calls your MCP server tools, you get:</p><ul><li>The tool being called</li><li>The arguments passed to it</li><li>Connection-level context (from the handshake)</li></ul><p>But if multiple users are interacting with the same MCP server instance through different conversations, you have no way to distinguish between them. The handshake authentication works great for single-user scenarios, but falls short when you need to handle multiple users with different permissions and data access.</p><h3>The Solution: DIY Sessions</h3><p>After thinking about it for a while, I realized: if we don’t get a session ID from the system, why not create our own?</p><p>Here’s how it works:</p><h3>Step 1: Create a Session Tool</h3><p>Build a create_session tool that generates a unique session ID from your backend. The LLM calls this first and gets back something like session_id: &quot;abc123&quot;.</p><h3>Step 2: Let the LLM Handle Context</h3><p>LLMs are actually pretty good at maintaining conversation context. Once they get that session ID, they’ll keep using it throughout the conversation.</p><h3>Step 3: Authenticate the Session</h3><p>Now you can implement proper authentication:</p><ul><li>User provides their email</li><li>Send them an auth link for that specific session</li><li>They verify, and the session becomes authenticated</li></ul><h3>Step 4: Guard Your Tools</h3><p>Every protected tool now requires a valid session ID. Check if the session is authenticated before allowing access.</p><h3>Real Example</h3><p>Here’s how it flows in practice:</p><ol><li>LLM calls create_session → gets back session_id: &quot;user-session-789&quot;</li><li>User provides email → system sends auth link for that session</li><li>User clicks link → session “user-session-789” becomes authenticated</li><li>LLM calls other tools with the session ID → server verifies it’s valid</li><li>Operations proceed with proper user context</li></ol><h3>Why This Works</h3><p>This approach solves the MCP authentication problem elegantly:</p><ul><li><strong>Works within constraints</strong>: No fighting with MCP’s stateless design</li><li><strong>Actually secure</strong>: Each session requires explicit authentication</li><li><strong>Flexible</strong>: Use email, OAuth, whatever auth method you prefer</li><li><strong>Simple</strong>: No complex state management needed</li></ul><h3>Wrapping Up</h3><p>Authentication in MCP servers doesn’t have to be a roadblock. By creating our own session layer, we get the security we need while working with MCP’s design rather than against it.</p><p>The MCP ecosystem is still pretty new, so we’re all figuring out patterns like this. This session-based approach has worked well for me — hopefully it helps you too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=031634547204" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intercepting Concurrent Requests in NestJS to Avoid Race Conditions]]></title>
            <link>https://supersami.medium.com/intercepting-concurrent-requests-in-nestjs-to-avoid-race-conditions-7fc2d954899a?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fc2d954899a</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nestjs]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 05:30:38 GMT</pubDate>
            <atom:updated>2024-10-03T05:30:38.809Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6A2YrI4-8mc0L3YDd6XzOQ.png" /></figure><p>When working with APIs that handle a high volume of concurrent requests, there is a risk of race conditions. These occur when multiple requests try to access or modify the same data simultaneously, resulting in inconsistent or incorrect outcomes. In NestJS, one effective strategy to prevent such race conditions is to intercept requests and throttle them based on specific criteria, such as the uniqueness of the request input.</p><p>This article walks through how you can intercept concurrent GraphQL requests in NestJS and prevent race conditions using a custom interceptor. Let’s take a closer look at how this is done.</p><p><strong>Understanding Race Conditions</strong></p><p>Race conditions happen when two or more concurrent processes access shared data and their behavior depends on the timing of the operations. For example, if two users try to modify the same resource at the same time, the final state may be unpredictable. This is especially problematic in distributed systems where data consistency is critical.</p><p>In the context of a GraphQL API, a user might send multiple requests with identical or conflicting data. If both requests are processed at the same time, they could lead to data integrity issues.</p><p><strong>Why Intercepting Concurrent Requests is Necessary</strong></p><p>When building APIs, especially in distributed systems, concurrency issues can arise due to race conditions. These conditions can lead to inconsistent data, failed transactions, and unexpected behavior. For example, in a scenario where two users attempt to update the same resource simultaneously, without proper synchronization, the final state of that resource could be unpredictable.</p><p>In NestJS, race conditions can be mitigated by intercepting requests and ensuring that no two concurrent requests with identical or conflicting data are processed simultaneously. This is especially important in GraphQL APIs, where input data plays a crucial role in determining the uniqueness of a request. By throttling requests, we can ensure that only one request with the same input is handled at a time, thereby maintaining data integrity.</p><p>Without this mechanism, concurrent requests could:</p><p>1. <strong>Overwrite Data</strong>: Two requests might modify the same resource, leading to data loss.</p><p>2. <strong>Inconsistent States</strong>: One request might read stale data while another is updating it.</p><p>3. <strong>Performance Degradation</strong>: Processing conflicting requests at the same time could lead to unnecessary load on the system.</p><p>By implementing an interceptor, you ensure that requests are processed in a controlled manner, preventing race conditions and maintaining the overall reliability of your system.</p><p><strong>Test Script for Concurrent Requests</strong></p><p>Here’s an alternative test script to simulate concurrent requests, similar to the original but with slight modifications:</p><pre>#!/bin/bash<br><br># Number of concurrent requests<br>request_count=10<br><br># Function to send a GraphQL mutation request<br>send_graphql_request() {<br>  curl -X POST \<br>    -H &quot;accept: application/json&quot; \<br>    -H &quot;content-type: application/json&quot; \<br>    -H &quot;application-id: abc123&quot; \<br>    -H &quot;x-correlation-id: $(uuidgen)&quot; \<br>    -H &quot;authorization: Bearer your_auth_token&quot; \<br>    http://localhost:3000/graphql \<br>    -d &#39;{<br>      &quot;operationName&quot;: &quot;UpdateProfile&quot;,<br>      &quot;variables&quot;: {<br>        &quot;input&quot;: {<br>          &quot;email&quot;: &quot;testuser@example.com&quot;,<br>          &quot;firstName&quot;: &quot;John&quot;,<br>          &quot;lastName&quot;: &quot;Doe&quot;<br>        }<br>      },<br>      &quot;query&quot;: &quot;mutation UpdateProfile($input: UpdateProfileInput!) {\n  updateProfile(input: $input) {\n    id\n    firstName\n    lastName\n    email\n  }\n}&quot;<br>    }&#39;<br>}<br><br># Send multiple requests in parallel<br>for i in $(seq 1 $request_count); do<br>  send_graphql_request &amp; # Execute in the background<br>done<br><br># Wait for all requests to complete<br>wait<br><br>echo &quot;All $request_count requests have been sent.&quot;</pre><p><strong>Explanation of the Test Script</strong></p><p>• <strong>Parallel Requests</strong>: The for loop sends multiple concurrent requests (10 in this case) using the &amp; operator, which allows each request to run in the background.</p><p>• <strong>Random Correlation ID</strong>: The x-correlation-id header uses uuidgen to generate a unique identifier for each request. This is useful for tracking and debugging in systems that log correlation IDs.</p><p>• <strong>GraphQL Mutation</strong>: The request simulates an update operation (e.g., updating user profile data) via a GraphQL mutation, which tests the ability of the interceptor to throttle requests with identical input data.</p><p>• <strong>Wait for Completion</strong>: The wait command ensures that the script waits for all background requests to complete before printing the final message.</p><p>This script can be adjusted to test different mutation operations or input data to ensure that the ThrottleInterceptor is working correctly and effectively mitigating race conditions.</p><p><strong>Introducing ThrottleInterceptor</strong></p><p>The goal of our ThrottleInterceptor is to temporarily block any concurrent requests that contain the same input data. This prevents multiple requests from being processed simultaneously, ensuring only one request is processed at a time for any unique input.</p><p>Here’s the code that implements this strategy:</p><pre>import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from &#39;@nestjs/common&#39;;<br>import { GqlExecutionContext } from &#39;@nestjs/graphql&#39;;<br>import { Observable, map } from &#39;rxjs&#39;;<br>import * as crypto from &#39;crypto&#39;;<br><br>@Injectable()<br>export class ThrottleInterceptor implements NestInterceptor {<br>  private storage = new Map&lt;string, NodeJS.Timeout&gt;();<br><br>  intercept(context: ExecutionContext, next: CallHandler): Observable&lt;any&gt; {<br>    const ctx = GqlExecutionContext.create(context);<br>    const request = ctx.getContext();<br>    const input = request?.req?.body?.variables?.input;<br><br>    const key = this.generateKey(input);<br>    const ttl = 5000; // 5 seconds in milliseconds<br><br>    // Check if a request with the same key is already being processed<br>    if (this.storage.has(key)) {<br>      throw new ConflictException(&#39;Another request with the same input is currently being processed. Please try again later.&#39;);<br>    }<br><br>    // Set a timeout to remove the key after the specified TTL (5 seconds)<br>    this.storage.set(<br>      key,<br>      setTimeout(() =&gt; this.storage.delete(key), ttl)<br>    );<br><br>    return next.handle().pipe(<br>      map(data =&gt; {<br>        // Automatically clean up the key after processing the request<br>        return data;<br>      })<br>    );<br>  }<br><br>  private generateKey(input: any): string {<br>    // Create a unique key based on the request input<br>    const hash = crypto.createHash(&#39;sha256&#39;);<br>    hash.update(JSON.stringify(input));<br>    return hash.digest(&#39;hex&#39;);<br>  }<br>}</pre><p><strong>How the Interceptor Works</strong></p><p>1. <strong>Context Extraction</strong>:</p><p>The GqlExecutionContext is used to extract the GraphQL request context. This allows us to retrieve the request body and access the input variables sent in the GraphQL mutation or query.</p><p>2. <strong>Key Generation</strong>:</p><p>The generateKey method creates a unique hash of the request input. This ensures that requests with the same input will generate the same key, allowing the interceptor to identify duplicate or conflicting requests.</p><p>3. <strong>Concurrency Check</strong>:</p><p>Before allowing the request to proceed, the interceptor checks if a key already exists in the storage Map. If a key is found, it means that a request with the same input is already being processed, and an error is thrown to prevent the new request from proceeding.</p><p>4. <strong>TTL-Based Throttling</strong>:</p><p>When a new request is processed, a key is stored in the Map with a TTL (Time to Live) of 5 seconds. After this time, the key is automatically deleted using setTimeout, allowing future requests with the same input to be processed after the throttle period.</p><p>5. <strong>Request Handling</strong>:</p><p>If no key is found, the request is allowed to proceed. The next.handle() method continues the request-processing pipeline, and once completed, the request’s input is no longer throttled.</p><p><strong>Key Advantages</strong></p><p>• <strong>Preventing Race Conditions</strong>:</p><p>By ensuring that no two identical requests are processed at the same time, this interceptor prevents conflicts that could lead to race conditions.</p><p>• <strong>Simple Throttling Logic</strong>:</p><p>The 5-second throttle ensures that a small window of time exists where only one request can modify the same data. This is especially useful for operations that involve updates to shared resources.</p><p>• <strong>Customizable TTL</strong>:</p><p>The TTL (5 seconds in this case) can be adjusted based on your application’s needs. If you need to allow requests sooner or throttle for a longer period, you can simply modify the ttl value.</p><p><strong>Handling Errors Gracefully</strong></p><p>The current implementation throws a generic error, Server have a problem, when a duplicate request is detected. In a production system, you may want to improve this by throwing a more descriptive error, like a ConflictException, or by returning a more user-friendly response that informs the client about the concurrency issue.</p><p>You can modify the error handling like this:</p><pre>if (this.storage.has(key)) {<br>  throw new ConflictException(&#39;Another request with the same input is currently being processed. Please try again later.&#39;);<br>}</pre><p><strong>Use Cases</strong></p><p>This pattern is particularly useful in scenarios where:</p><p>• <strong>Concurrency is high</strong>, and the API needs to prevent conflicting operations.</p><p>• <strong>Transactions on shared resources</strong> need to be serialized to ensure data consistency.</p><p>• <strong>Debounced or delayed operations</strong> are necessary to prevent overloading systems with duplicate or unnecessary requests.</p><p><strong>Conclusion</strong></p><p>The ThrottleInterceptor in NestJS provides a powerful way to manage concurrent requests and avoid race conditions by throttling duplicate requests. This approach is simple, scalable, and easily customizable, making it a great tool for ensuring data consistency in applications with high request volume.</p><p>By understanding and implementing strategies like these, you can build more robust APIs that handle concurrency gracefully, ensuring that data remains consistent and that users experience fewer issues when sending requests in parallel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fc2d954899a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlined iOS App Deployment: A Guide to Using Fastlane for the App Store in year 2024]]></title>
            <link>https://supersami.medium.com/streamlined-ios-app-deployment-a-guide-to-using-fastlane-for-the-app-store-in-year-2024-b59fd94a29fa?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b59fd94a29fa</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[pipeline]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 05:14:14 GMT</pubDate>
            <atom:updated>2024-10-03T05:16:16.330Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPyVkmheoA6cDY_to39m0w.jpeg" /></figure><p>Picture this: You’re cruising down the development highway in your React Native ride, wind in your code, and excitement in your commits. Suddenly, you hit a fork in the road: App Store or App Connect? Fear not! Fastlane swoops in like a superhero, capes flapping, to save the day.</p><p>Fastlane isn’t just a tool; it’s your trusty sidekick. It handles the nitty-gritty — code signing, test distribution, and app store magic — all while you sip your virtual coffee. 🎉</p><p>So buckle up, fellow developer! Let’s rev those engines, increment those build numbers, and deploy like there’s no tomorrow. Fastlane: because life’s too short for manual deployments! 🚀📱</p><h3><strong>“Fastlane: Your React Native Sidekick for Epic Deployments!”</strong></h3><p><strong>Install Fastlane with a Ruby Twist:</strong> First, make sure you’ve got Ruby on your system (it’s like the secret sauce). Then, sprinkle some Fastlane magic with this command:</p><pre>sudo gem install fastlane -NV</pre><p>🌟 Pro tip: Fastlane is like the espresso shot for your React Native project — energizing and efficient!</p><p><strong>Navigate Like a Pro:</strong> Grab your terminal compass and sail to the root directory of your React Native project:</p><pre>cd /path/to/your/project</pre><p>🗺️ Fun fact: React Native devs are the modern-day explorers, charting new territories in code!</p><p><strong>Fastlane Init: </strong>The Hero’s Call: Now, brace yourself! Execute this command to summon Fastlane into your project:</p><pre>fastlane init</pre><p>🚀 Fastlane swoops in, asking questions like a curious parrot. Answer wisely! Specify iOS, Android, or both. Oh, and don’t forget your app’s secret identity (package name) and Apple Developer credentials. 🍎</p><p><strong>Choose Your Adventure</strong>: Fastlane offers four paths:</p><p><strong>📸 Automate Screenshots</strong>: Capture app moments like a pro photographer.</p><p><strong>👩‍✈️ Beta Distribution to TestFlight</strong>: Because beta testers deserve VIP treatment.</p><p><strong>🚀 App Store Distribution:</strong> Launch your app like a rocket!</p><p><strong>🛠️ Manual Setup:</strong> DIY mode for the brave souls.</p><p><strong>Certified Fastlane Goodness: </strong>Fastlane will fetch certificates for iOS (like a digital butler). No more certificate scavenger hunts! Just sprinkle some Fastlane match init and voilà!</p><p><strong>Fastfile: The Scroll of Power: </strong>Inside the mystical Fastlane folder, behold the Fastfile! We’ll rewrite its ancient runes with our own magic. And fear not — I’ll be your guide through this enchanted code forest.</p><pre># This file contains the fastlane.tools configuration<br># You can find the documentation at https://docs.fastlane.tools<br>#<br># For a list of all available actions, check out<br>#<br>#     https://docs.fastlane.tools/actions<br>#<br># For a list of all available plugins, check out<br>#<br>#     https://docs.fastlane.tools/plugins/available-plugins<br>#<br># Uncomment the line if you want fastlane to automatically update itself<br># update_fastlane<br><br>default_platform(:ios)<br>platform :ios do<br>  desc &quot;Push a new beta build to TestFlight&quot;<br><br>  lane :beta do<br>    // Writing for Beta<br>   end<br>end</pre><p>The code below begins by retrieving inputs from the GitHub pipeline, including the build number and version name. Subsequently, it validates the API_KEY_PATH, a .p8 file from your App Store Connect account found under Users and Access &gt; Integrations &gt; App Connect API. This file should be securely stored in your GitHub repository’s Settings &gt; Secrets as APP_CONNECT_AUTH. The YAML file will be configured later, with the assumption that api_key_path is acquired after saving APP_CONNECT_AUTH locally within GitHub Actions.</p><pre>    build_number = ENV[&quot;BUILD_NUMBER&quot;]<br>    version_name = ENV[&quot;VERSION_NAME&quot;]<br>    api_key_path = ENV[&quot;API_KEY_PATH&quot;]<br><br>    if File.exist?(api_key_path)<br>      if File.size?(api_key_path)<br>        puts &quot;File exists and is not empty&quot;<br>      else<br>        puts &quot;File exists but is empty&quot;<br>      end<br>    else<br>      puts &quot;File does not exist&quot;<br>    end</pre><p>The next step involves authenticating this token. Ensure you retrieve the issuer ID and key ID from App Store Connect’s API Keys section. This authentication method validates your key from App Store Connect, providing an api_key for deploying your application.</p><pre>    api_key = app_store_connect_api_key(<br>      key_id: &quot;Some Key ID &quot;,<br>      issuer_id: &quot;Some Issuer ID&quot;,<br>      key_filepath: ENV[&quot;API_KEY_PATH&quot;],<br>      duration: 1200, # optional (maximum 1200)<br>      in_house: true # optional but may be required if using match/sigh<br>    )</pre><p>Following that, we create a straightforward keychain setup to remain unlocked, eliminating the need for user interaction. Without this setup, your pipeline might halt waiting for a nonexistent keychain password.</p><pre>   setup_ci if ENV[&#39;CI&#39;]<br>    create_keychain(<br>      name: &quot;fastlane_tmp_keychain&quot;,<br>      password: &quot;&quot;,<br>      default_keychain: true,<br>      unlock: true,<br>      timeout: 3600,<br>      add_to_search_list: true<br>    )</pre><p>Next step, we update the build number and version name, responsible for keeping your application’s build details current. You may choose to skip this step by manually editing files as needed.</p><pre><br>   increment_build_number(<br>      xcodeproj: &quot;App.xcodeproj&quot;,<br>      build_number: build_number<br>    )<br><br>    unless version_name =~ /^\d+(\.\d+){0,2}$/<br>      UI.user_error!(&quot;Invalid version name: #{version_name}. It must be in the format A, A.B, or A.B.C where A, B, and C are integers.&quot;)<br>    end<br><br>    increment_version_number(<br>      xcodeproj: &quot;App.xcodeproj&quot;,<br>      version_number: version_name<br>    )</pre><p>Now, by utilizing fastlane match, you can retrieve the certificates from the private repository established during the fastlane match setup. As it is private, a token is required for access. The remaining configuration is quite straightforward and self-explanatory.</p><pre>  ENV[&quot;ARCHS&quot;] = &quot;arm64&quot;<br>    match(<br>      git_url: &quot;@github.com/some/some-certificates&quot;&gt;https://#{ENV[&#39;GHP_TOKEN&#39;]}@github.com/some/some-certificates&quot;,<br>      app_identifier: [&quot;com.example.app&quot;, &quot;com.example.app.OneSignalNotificationServiceExtension&quot;],<br>      api_key: api_key, # Path to your API Key<br>      readonly: true,<br>      git_branch: &quot;master&quot;, # replace with your branch name<br>      shallow_clone: true, # faster cloning on CI<br>      keychain_name: &quot;fastlane_tmp_keychain&quot;,<br>      keychain_password: &quot;&quot;<br>    )</pre><p><strong>Building the App:</strong> This crucial step involves creating the archive of our application. Afterwards, we can easily upload the generated archive to the App Store as the final step.</p><pre>  build_app(<br>      export_options: {<br>        provisioningProfiles: {<br>          &quot;com.example.app&quot;: &quot;match AppStore com.example.app&quot;,<br>          &quot;com.example.app.OneSignalNotificationServiceExtension&quot;: &quot;match AppStore com.example.app OneSignalNotificationServiceExtension&quot;<br>        }<br>      },<br>      include_symbols: false<br>    )<br><br>    upload_to_testflight(api_key: api_key, skip_waiting_for_build_processing: true)</pre><p>In our upcoming article, we will explore how to craft a Pipeline to execute this Fastlane action.</p><p>Next Step : <a href="https://medium.com/@supersami/supercharge-your-react-native-deployment-with-fastlane-8f27dca00c38">Crafting a pipeline that can be triggered via github actions, with manual intervention.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b59fd94a29fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlined Android App Deployment: A Guide to Using Fastlane for the App Store in year 2024]]></title>
            <link>https://supersami.medium.com/streamlined-android-app-deployment-a-guide-to-using-fastlane-for-the-app-store-in-year-2024-34a581abf1e3?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/34a581abf1e3</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 05:13:01 GMT</pubDate>
            <atom:updated>2024-10-03T05:17:52.408Z</atom:updated>
            <content:encoded><![CDATA[<p>Envision yourself zooming along the development expressway in your sleek React Native vehicle, code streaming behind you, commit after commit adding to the thrill. Then, you’re faced with a decision: Google Play Store or internal distribution? Have no fear, for Fastlane arrives just in time, like a superhero, to rescue your day.</p><p>Fastlane is more than a mere tool; it’s the trusty sidekick you didn’t know you needed. It takes care of the tedious tasks — code signing, beta testing, and the alchemy of app store submissions — all while you relax with your digital cup of joe. 🎉</p><p>So strap in, dear developer! It’s time to fire up those engines, bump up those build numbers, and launch your app as if tomorrow is a myth. Embrace Fastlane, the champion of automated deployments, because who has time for manual processes? 🚀📱</p><h3>“Fastlane: Your React Native Sidekick for Epic Deployments!”</h3><p>This file contains the configuration for Fastlane, your superhero sidekick in the world of Android development. Let’s dive into the details:</p><ol><li><strong>Install Fastlane with a Ruby Twist:</strong> First, make sure you’ve got Ruby on your system (it’s like the secret sauce). Then, sprinkle some Fastlane magic with this command:</li></ol><pre>sudo gem install fastlane -NV</pre><p><strong>2. Obtain the Service Account JSON:</strong></p><ol><li><strong>Create a Service Account:<br>- </strong>Go to the Google Cloud Console: Google Cloud Console<br>- Navigate to your project (or create a new one if needed).<br>- In the left sidebar, click on “IAM &amp; Admin” &gt; “Service accounts.”<br>- Click the “+ CREATE SERVICE ACCOUNT” button.<br>- Fill in the details (name, description), and choose the role “Project” &gt; “Editor” (or a more specific role if you prefer).<br>- Click “Create.”</li></ol><p>2. <strong>Generate a JSON Key File:<br> - </strong>Locate the newly created service account in the list.<br> - Click the three dots (⋮) next to it and select “Create key.”<br> - Choose the JSON format and click “Create.”<br> - Save the downloaded JSON file securely. This is your service account key.</p><p>3. <strong>Uploading Service Account JSON to GitHub secrets<br></strong>Simply upload the service account JSON file you’ve downloaded to your GitHub repository secrets. This will enable you to upload the app without any manual interactions.</p><p><strong>3. Fastlane Init: </strong>The Hero’s Call: Now, brace yourself! Execute this command to summon Fastlane into your project:</p><pre>fastlane init</pre><p>🚀 Fastlane swoops in, asking questions like a curious parrot. Answer wisely! Specify Android, or both.</p><pre># This file contains the fastlane.tools configuration<br># You can find the documentation at https://docs.fastlane.tools<br>#<br># For a list of all available actions, check out<br>#<br>#     https://docs.fastlane.tools/actions<br>#<br># For a list of all available plugins, check out<br>#<br>#     https://docs.fastlane.tools/plugins/available-plugins<br>#<br># Uncomment the line if you want fastlane to automatically update itself<br># update_fastlanedefault_platform(:ios)<br>platform :ios do<br>  desc &quot;Push a new beta build to TestFlight&quot;<br>  lane :beta do<br>    // Writing for Beta<br>   end<br>end</pre><p><strong>4. Fetching Version Code:</strong> Let’s talk about the elephant in the room — the build number and version name directly fetched from your Android app. Imagine how good it would be to have a function that does that for you. Here’s one that fetches the version code:</p><pre>  def get_max_version_code(track)<br>    google_play_track_version_codes(<br>      package_name: &quot;com.you.app&quot;,<br>      track: track,<br>      json_key_data: &quot;#{ENV[&#39;ANDROID_JSON_DATA&#39;]}&quot;<br>    ).max<br>  end</pre><p><strong>5. Fetching Version Name:</strong> Now, let’s get the version name from the app store directly:</p><pre>  def get_released_track_version_code_and_name()<br>    version_codes = google_play_track_release_names(track: &#39;production&#39;, package_name: &#39;com.your.app&#39;, json_key_data:&quot;#{ENV[&#39;ANDROID_JSON_DATA&#39;]}&quot;)<br>    latest_release_name = version_codes.last<br>    match = latest_release_name.match(/(\d+) \(([\d\.]+)\)/)<br>    release_code = match[1].to_i<br>    release_name = match[2]<br>    return release_code, release_name<br>  end</pre><p><strong>6. Getting the Last Version Code:</strong> Retrieve the last version code from both internal and production tracks:</p><pre> def get_last_version_code()<br>    internal_version_code = get_max_version_code(&quot;internal&quot;)<br>    production_version_code = get_max_version_code(&quot;production&quot;)<br>    return [internal_version_code, production_version_code].max<br>  end</pre><p><strong>7. Beta Deployment:</strong> In your Fastlane beta lane, use the last version code to increment and handle release names:</p><pre> lane :beta do<br>    version_code = get_last_version_code()<br>    raise &quot;Failed to get last version code&quot; unless version_code<br>  <br>    increment_version_code(<br>      gradle_file_path: &quot;./app/build.gradle&quot;, # replace with your actual path<br>      version_code: version_code + 1<br>    )<br>  <br>    release = get_released_track_version_code_and_name()<br>    raise &quot;Failed to get released track version code and name&quot; unless release &amp;&amp; release.length &gt;= 2<br>  <br>    release_code = release[0].to_i<br>    release_name = release[1]<br>  <br>    if version_code &gt;= release_code<br>      version_segments = Gem::Version.new(release_name).segments<br>      raise &quot;Failed to parse release name&quot; unless version_segments &amp;&amp; version_segments.length &gt; 0<br>  <br>      version_segments[-1] += 1<br>      release_name = version_segments.join(&#39;.&#39;)<br>    end<br>  end</pre><p><strong>8. Clean Bundle Release:</strong> Create a clean bundle release:</p><pre>    gradle(task: &quot;clean bundleRelease&quot;)</pre><p><strong>9. Upload to Play Store:</strong> Finally, let’s upload the app to the Play Store directly:</p><pre>json_key_data = ENV[&#39;ANDROID_JSON_DATA&#39;]<br>raise &quot;ANDROID_JSON_DATA environment variable is not set&quot; unless json_key_data<br><br>upload_to_play_store(json_key_data: json_key_data,<br>                     track: &#39;internal&#39;,<br>                     version_name: release_name)<br>rescue =&gt; e<br>  puts &quot;An error occurred: #{e.message}&quot;</pre><p>Next Step : <a href="https://medium.com/@supersami/supercharge-your-react-native-deployment-with-fastlane-8f27dca00c38"><strong>Crafting a pipeline to be able to run Fastlane action to deploy your applicaiton</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34a581abf1e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Supercharge Your React Native Deployment with Fastlane]]></title>
            <link>https://supersami.medium.com/supercharge-your-react-native-deployment-with-fastlane-8f27dca00c38?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f27dca00c38</guid>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 05:11:59 GMT</pubDate>
            <atom:updated>2024-10-03T05:11:59.248Z</atom:updated>
            <content:encoded><![CDATA[<p>We are in the process of crafting a pipeline for both native applications, which will invoke the fastFile function to initiate a build. You can configure your fastFile for iOS using the provided link, and for Android with its respective link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6d02Kco7lf2tNM9_287zqQ.jpeg" /></figure><h4>IOS Pipeline</h4><p>Imagine you’re about to deploy an iOS application. Triggering a pipeline in this scenario requires two inputs and a manual intervention. This is crucial because building for iOS incurs significant costs, making it essential to manage the process carefully.</p><pre>name: IOS Continuous Deployment - Stagging<br>on:<br>  workflow_dispatch:<br>    inputs:<br>      branch:<br>        description: &#39;Branch to deploy&#39;<br>        required: true<br>        default: &#39;stage&#39;<br>      BUILD_NUMBER:<br>        description: &#39;Enter Build Number &#39;<br>        required: true<br>      VERSION_NAME:<br>        description: &#39;Enter Version Number&#39;<br>        required: true</pre><p>To deploy, specify the branch, build number, and version name. Alternatively, you can write a script to fetch this data directly from the App Store.</p><p>The prerequisite environments are presumably</p><pre><br>env:<br>  CI: true<br>  GHP_TOKEN: ${{ secrets.GHP_TOKEN }}<br>  APP_CONNECT_AUTH : ${{ secrets.APP_CONNECT_AUTH }}<br>  MATCH_PASSWORD: &quot;mobile development&quot;</pre><p>The prerequisite dependencies required for iOS builds include:</p><p>- xcodebuild<br>- NodeJS<br>- Fastlane<br>- CocoaPods</p><pre><br>jobs:<br>  build:<br>    runs-on: macos-latest<br><br>    steps:<br>    - name: Checkout repository<br>      uses: actions/checkout@v3<br>      with:<br>        ref: ${{ github.event.inputs.branch }}<br><br>    - name: Check Xcode version<br>      run: xcodebuild -version<br><br>    - name: Set up Node.js<br>      uses: actions/setup-node@v3<br>      with:<br>        node-version: &#39;18.19.1&#39; <br><br>    - name: Install Fastlane<br>      run: gem install fastlane<br><br>    - name: Install CocoaPods<br>      run: brew install cocoapods<br><br>    - name: Set up Ruby<br>      uses: ruby/setup-ruby@v1<br>      with:<br>        ruby-version: &#39;3.0&#39;<br></pre><p>Now lets write the app dependency installation process and start app getting started process.</p><pre>    - name: Create .env file<br>      run: |<br>        echo &quot;${{ secrets.ENVS }}&quot; &gt; .env<br><br>            <br>    - name: Install npm dependencies<br>      run: npm ci<br><br>    - name: Install Pods<br>      run: pod install<br>      working-directory: ./ios <br><br>    - name: Add AuthKey.json<br>      run: echo &quot;${{ secrets.APP_CONNECT_AUTH }}&quot; &gt; key.p8<br><br>    - name: Run Fastlane beta<br>      run: fastlane beta --verbose<br>      env:<br>        API_KEY_PATH: ${{ format(&#39;{0}/key.p8&#39;, github.workspace) }}<br>        BUILD_NUMBER: ${{ github.event.inputs.BUILD_NUMBER }}<br>        VERSION_NAME: ${{ github.event.inputs.VERSION_NAME }}<br>      working-directory: ./ios</pre><p>From the code snippets provided, it’s evident that I prefer to store my environmental variables in a single GitHub secret. If you know of a better method to retrieve and load environmental variables, feel free to implement that process. This approach is somewhat subjective.</p><p>Additionally, for Fastlane authentication, a .p8 file is required, which can be obtained from Users And Access -&gt; Integrations -&gt; App Connect keys. In the subsequent steps of the Fastlane beta process, as illustrated, I convert the key obtained from secrets into a file named key.p8. This file’s absolute path is then used in the Fastlane process.</p><p>The remaining steps are quite straightforward. I hope this has been useful in your journey of creating a CD pipeline for React Native (IOS).</p><h4>Android IOS :</h4><p>Now lets talk about writing a CD for android that will trigger yoru fastlane build, setting up fastlane build is on this article. Moving on, lets talk writing the pipleline for it. Lets start with the prerequsites.</p><ul><li>NodeJS</li><li>FastLane</li><li>JDK</li></ul><p>Lets write a pipleline that runs on ubuntu-latest And download these dependencies.</p><pre>name: Android Continuous Deployment - Stage<br>on:<br>  workflow_dispatch:<br>    inputs:<br>      branch:<br>        description: &#39;Branch to deploy&#39;<br>        required: true<br>        default: &#39;stage&#39;<br><br>env:<br>  CI: true<br>  ANDROID_JSON_DATA: ${{ secrets.ANDROID_JSON_DATA }}<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>    - name: Checkout repository<br>      uses: actions/checkout@v3<br>      with:<br>        ref: ${{ github.event.inputs.branch }}<br><br>    - name: Set up Node.js<br>      uses: actions/setup-node@v3<br>      with:<br>        node-version: &#39;18.19.1&#39; # Specify the Node.js version you need<br>            <br>    - name: Install Fastlane<br>      run: sudo gem install fastlane -NV<br><br>    - name: Set up JDK 17<br>      uses: actions/setup-java@v3<br>      with:<br>        distribution: &#39;temurin&#39;<br>        java-version: &#39;17&#39;</pre><p>Let’s discuss the basic requirement, which is environmental variables. You can easily retrieve your environmental variables from GitHub secrets and load them into the environment.</p><pre><br>- name: Create .env file<br> run: |<br> echo “${{ secrets.ENVS }}” &gt; .env<br> <br>- name: Load .env file<br> run: |<br> export $(xargs &lt; .env)<br></pre><p>Next, we might need a keystore, which is a requirement. Since they are usually encrypted, my plan is to convert the keystore into base64.</p><pre>base64 -i path/to/keystore -o key.txt</pre><p>You can then upload this base64-encoded file into Secrets with ease. During the pipeline execution, you need to retrieve it and save it in the Android folder.</p><pre>- name: Write Keystore<br>  run: echo “${{ secrets.KEYSTORE }}” | base64 — decode &gt; ./android/app/app.keystore<br></pre><p>You might have some variables that your keystore requires, so you would perform that step like this:</p><pre>- name: Set up Gradle properties<br>  run: |<br>  echo “APP_UPLOAD_STORE_FILE=${{ secrets.APP_UPLOAD_STORE_FILE }}” &gt;&gt; ./gradle.properties<br>  working-directory: ./android<br></pre><p>With that completed, let’s address the inputs we did for iOS. To update the build_number and version_name, we would proceed as follows:</p><pre>- name: Set GEM_HOME and install plugins<br>  run: |<br>  echo ‘GEM_HOME=$HOME/.gem’ &gt;&gt; $GITHUB_ENV<br>  gem install fastlane-plugin-android_versioning — user-install<br>  gem install fastlane-plugin-increment_version_code — user-install<br>  working-directory: ./android</pre><p>And finally, just execute the steps like this:</p><pre>- name: Run Fastlane beta<br>  run: fastlane beta — verbose<br>  working-directory: ./android</pre><p>To learn how to write a Fastlane beta function, it is quite straightforward. Simply read more on the topic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f27dca00c38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GPT Models Can Do More Than Just Talk: How to Make Them Brew You Coffee ☕ — Node.js]]></title>
            <link>https://ai.plainenglish.io/gpt-models-can-do-more-than-just-talk-how-to-make-them-brew-you-coffee-5c9556651555?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c9556651555</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[node-js-development]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Tue, 13 Jun 2023 12:50:54 GMT</pubDate>
            <atom:updated>2023-06-20T03:25:34.142Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Da27RAnT_G3bzWlSwpZLg.jpeg" /></figure><p>Imagine having a GPT model that can not only generate amazing natural language, but also interact with your own data sources, APIs, or actions. How cool would that be? You could ask it to do anything you want, from booking a flight to ordering a pizza to playing a game. Well, you don’t have to imagine anymore, because, in this article, I will show you how I made it happen using a simple yet powerful approach based on intent classification and a rule-based system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d23UD_OMKKiv2qpsHDL1Rw.png" /></figure><h3>Intent Classification 🎯</h3><p>Intent classification is the task of figuring out what the user wants to achieve or do from their natural language input. For example, if the user says “Can you make me a coffee?”, the intent could be “Make a coffee”. This way, we can map the user’s input to a specific action or function that we want our GPT model to perform.</p><p>To do this, I used Ada Models, <a href="https://medium.com/javascript-in-plain-english/how-to-embed-search-with-text-embedding-ada-002-in-node-js-5605c8d08815">which I wrote about in a previous article.</a> Ada Models are models that return the embedding of the text, which is a numerical representation of its meaning. The embedding captures the semantic and syntactic features of the text, such as the words, phrases, and context.</p><p>By using a simple formula, we can find the most relatable of the embedding among a set of predefined categories, which indicates the most likely intent. The formula is based on the Euclidean distance, which measures how close two vectors are in a multidimensional space. The smaller the distance, the more similar the vectors are.</p><p>For example, if we have three categories: “Make a coffee”, “Make a tea”, and “Make a sandwich”, and we have an embedding for each category, we can compare the embedding of the user’s input with each category embedding and find the one with the smallest distance. If the user says “Can you brew me a coffee?”, the embedding of their input will be closer to the embedding of “Make a coffee” than to the other two categories, so we can infer that their intent is “Make a coffee”.</p><p>A sample of how we can find the intent can be found by categorizing the intents into actions. So for example, if you have an action like “Make a coffee”, you can define it as a category with a user-provided prompt and a function to execute:</p><pre>Make a coffee =&gt; (User Provided Prompt = “Can you make me a coffee?”) =&gt; MakeACoffee()</pre><p>However, to increase the accuracy and flexibility of the system, we don’t just define one category for each action, but more different ways of expressing the same intent. For example:</p><pre>Make me a coffee =&gt; (User Provided Prompt = “Can you make me a coffee?”) =&gt; MakeACoffee()<br>Bring me a coffee =&gt; (User Provided Prompt = “Can you bring me a coffee?”) =&gt; MakeACoffee()<br>Buy me a coffee =&gt; (User Provided Prompt = “Can you buy me a coffee?”) =&gt; MakeACoffee()</pre><p>As you can see, all these categories will trigger the same function: MakeACoffee().</p><h3>Rule-Based System 📜</h3><p>The rule-based system is like any other chatbot system, but ours will be very dynamic and powerful and use AI from start to end. The concept is to make a list of categories as keys and objects as values:</p><pre><br>const intents = {<br>  categories: {<br>    &quot;Make a coffee&quot;: MakeACoffee,<br>    &quot;Make me a coffee&quot;: MakeACoffee,<br>    &quot;Bring me a coffee&quot;: MakeACoffee,<br>    &quot;Buy me a coffee&quot;: MakeACoffee,<br>  },<br>};</pre><p>Each object has an action, which can be either an API call or something else, a URL to call if it’s an API call and a response function to handle the result of the call. For example:</p><pre><br>const MakeACoffee = {<br>  action: &quot;LOCAL_ACTION&quot;,<br>  response: () =&gt; &quot;Your Expresso coffee is here!&quot;,<br>};</pre><p>A function would make a fetch request and return the response. You can customize the response as much as you like.</p><p>Now whenever you ask for, Make me a coffee Your result would be your coffee is here.</p><p>But what if you have follow-up questions or options? How would you handle that?</p><p>For example, when you ask the system to makeACoffee, you might want to handle what kind of coffee use case. To do that, we will have a recursive approach.</p><p>Each object can also have an ask function to generate a follow-up question and a categories object to define the possible options for the user. For example:</p><pre>const MakeACoffee = {<br>  action: &quot;API_CALL&quot;,<br>  url: &quot;http://localhost:3000/coffees&quot;,<br>  ask: [<br>    (coffees) =&gt; {<br>      return `What kind of coffee would you like ${coffees.map(<br>        (coffee) =&gt; coffee<br>      )}?`;<br>    },<br>  ],<br>  categories: () =&gt; ({<br>    Mocha: MochaCoffee,<br>    Karak: KarakCoffee,<br>    Espresso: EspressoCoffee,<br>  }),<br>};</pre><p>Now with this approach, we will have a list of coffees in the response with a follow-up question and another object to handle the user’s choice.</p><pre>const MochaCoffee = {<br>  action: &quot;LOCAL_ACTION&quot;,<br>  response: (response) =&gt; &quot;Your mocha coffee is here!&quot;,<br>};</pre><p>And that’s it! You have successfully integrated your GPT model with your own data sources and actions. You can now enjoy your coffee while chatting with your AI friend. ☕</p><h3>Behind the Scenes 🕵️‍♂️</h3><p>Now let’s look at the behind the scene working of this application. I showed you the configuration, but let’s look at the internals.</p><p>The second part of this article is here : <a href="https://rajaosama.me/blogs/gpt-models-can-do-more-than-just-talk-how-to-make-them-brew-you-coffee">GPT Models Can Do More Than Just Talk: How to Make Them Brew You Coffee ☕</a></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>.</em></p><p><em>Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c9556651555" width="1" height="1" alt=""><hr><p><a href="https://ai.plainenglish.io/gpt-models-can-do-more-than-just-talk-how-to-make-them-brew-you-coffee-5c9556651555">GPT Models Can Do More Than Just Talk: How to Make Them Brew You Coffee ☕ — Node.js</a> was originally published in <a href="https://ai.plainenglish.io/">Artificial Intelligence in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blazing Fast Search with text-embedding-ada-002 in Node.js ]]></title>
            <link>https://javascript.plainenglish.io/how-to-embed-search-with-text-embedding-ada-002-in-node-js-5605c8d08815?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5605c8d08815</guid>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Sat, 03 Jun 2023 13:25:36 GMT</pubDate>
            <atom:updated>2024-08-06T04:58:29.877Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Do you want to create amazing applications that can search, cluster, recommend, and classify text and code? Do you want to use a powerful and cost-effective embedding model that can handle long documents and diverse tasks? Do you want to learn how to use text-embedding-ada-002 in Node.js with ease and simplicity? If you answered yes to any of these questions, then this article is for you! 😍</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GosCCvRDEpm1j0EDgrR5xw.gif" /></figure><p>In this article, we will show you how to use text-embedding-ada-002, a new and improved embedding model from OpenAI, in Node.js. We will explain what embeddings are, why they are useful, and how text-embedding-ada-002 outperforms previous models. We will also show you how to install the OpenAI library, and make requests to the /createEmbedding endpoint. Finally, we will give you one examples of how to use text-embedding-ada-002 for different use cases, such as search.</p><blockquote>Complete Article can be found here <a href="https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada">https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada</a></blockquote><h3>What are embeddings?</h3><p>Embeddings are numerical representations of concepts converted to number sequences, which make it easy for computers to understand the relationships between those concepts. For example, the word “cat” can be represented by a vector of numbers, such as [0.2, -0.5, 0.7 …]. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7I29YAmeDP_sussPL2t7A.gif" /></figure><p>Embeddings are commonly used for:</p><ul><li>Search (where results are ranked by relevance to a query string)</li><li>Clustering (where text strings are grouped by similarity)</li><li>Recommendations (where items with related text strings are recommended)</li><li>Anomaly detection (where outliers with little relatedness are identified)</li><li>Diversity measurement (where similarity distributions are analyzed)</li><li>Classification (where text strings are classified by their most similar label)</li></ul><blockquote><em>💡</em> <strong>Learn how to organize your Node.js Express.js project for scalability and maintainability:</strong></blockquote><p><a href="https://differ.blog/p/ultimate-guide-to-structuring-your-backend-code-in-node-js-f5bd29">Node.js Backend Code Structure Guide</a></p><blockquote><em>👉</em> To read more such acrticles, <a href="https://differ.blog/"><strong>sign up for free on Differ</strong></a>.</blockquote><h3>Why text-embedding-ada-002? 🙌</h3><p>Text-embedding-ada-002 is a new embedding model from OpenAI that replaces five separate models for text search, text similarity, and code search. It outperforms the previous most capable model, Davinci, at most tasks, while being priced 99.8% lower¹. Here are some of the advantages of text-embedding-ada-002:</p><ul><li>Stronger performance. text-embedding-ada-002 outperforms all the old embedding models on text search, code search, and sentence similarity tasks and gets comparable performance on text classification¹.</li><li>Unification of capabilities. text-embedding-ada-002 simplifies the interface of the /embeddings endpoint by merging the five separate models into a single new model. This single representation performs better than the previous embedding models across a diverse set of text search, sentence similarity, and code search benchmarks¹.</li><li>Longer context. The context length of text-embedding-ada-002 is increased by a factor of four, from 2048 to 8192 tokens¹, making it more convenient to work with long documents.</li><li>Smaller embedding size. The new embeddings have only 1536 dimensions¹, one-eighth the size of davinci embeddings², making them more cost effective in working with vector databases.</li><li>Reduced price. The price of text-embedding-ada-002 is reduced by 90% compared to old models of the same size². The new model achieves better or similar performance as Davinci at a 99.8% lower price¹.</li></ul><p>Overall, text-embedding-ada-002 is a much more powerful tool for natural language processing and code tasks. It can help you create even more capable applications in your respective fields.</p><blockquote>Complete Article can be found here <a href="https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada">https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada</a></blockquote><h3>Search 🔎</h3><p>One common use case for embeddings is search, where you want to rank results by relevance to a query string. For example, suppose you have a collection of documents about animals, and you want to find the most relevant ones for a given query.</p><p>To do this, you can follow these steps:</p><ol><li>Get embeddings for all your documents using text- embedding- ada- 002 and store them in a vector database, such as Elasticsearch⁸.</li><li>Get an embedding for your query string using text- embedding- ada- 002 and send it to your vector database.</li><li>Retrieve the documents with the smallest distances (or highest similarities) to your query embedding and display them as your search results.</li></ol><p>Here is some pseudocode that illustrates this process:</p><pre>// Import libraries<br>const { Configuration, OpenAIApi } = require(&quot;openai&quot;);<br>const { Client } = require(&quot;@elastic/elasticsearch&quot;);<br>const client = new Client({<br>  node: &quot;http://localhost:9200&quot;,<br>  auth: {<br>    username: &quot;elastic&quot;,<br>    password: process.env.ELASTIC_SEARCH,<br>  },<br>});<br>// Test the connection<br>client.ping((err, res) =&gt; {<br>  if (err) {<br>    console.error(&quot;Connection failed:&quot;, err);<br>  } else {<br>    console.log(&quot;Connection successful:&quot;, res);<br>  }<br>});<br>// Create instances<br>const OPENAI_API_KEY = process.env.OPENAI_API_KEY;<br>const configuration = new Configuration({<br>  apiKey: OPENAI_API_KEY,<br>});<br>const openai = new OpenAIApi(configuration);<br>const createIndices = async () =&gt; {<br>  await client.indices.create({<br>    index: &quot;pets&quot;,<br>    body: {<br>      mappings: {<br>        properties: {<br>          // The document field stores the text of the animal<br>          document: {<br>            type: &quot;text&quot;,<br>          },<br>          // The embedding field stores the vector representation of the animal<br>          embedding: {<br>            type: &quot;dense_vector&quot;,<br>            dims: 1536,<br>            index: true,<br>            similarity: &quot;cosine&quot;,<br>          },<br>        },<br>      },<br>    },<br>  });<br>};<br>const createIndexs = () =&gt; {<br>  // // Get embeddings for documents<br>  const documents = [<br>    &quot;A cat is a domesticated animal that likes to sleep.&quot;,<br>    &quot;A dog is a loyal companion that likes to play.&quot;,<br>    &quot;A bird is a feathered creature that likes to fly.&quot;,<br>    &quot;A fish is an aquatic animal that likes to swim.&quot;,<br>    &quot;A lion is a wild animal that likes to hunt.&quot;,<br>  ]; // sample documents<br>  documents.forEach((document, index) =&gt; {<br>    const input = { input: document, model: &quot;text-embedding-ada-002&quot; };<br>    openai<br>      .createEmbedding(input)<br>      .then((response) =&gt; {<br>        const embedding = response.data.data[0].embedding; // extract embedding array<br>        client.index({<br>          // store document and embedding in Elasticsearch<br>          index: &quot;pets&quot;,<br>          //   type: &#39;document&#39;,<br>          //   id: index,<br>          body: {<br>            document: document,<br>            embedding: embedding,<br>          },<br>        });<br>      })<br>      .catch((e) =&gt; {<br>        throw new Error(&quot;Failed once, dont try again&quot;);<br>        console.log(e.message);<br>      });<br>  });<br>};<br>const query = () =&gt; {<br>  // Get embedding for query<br>  const query = &quot;What animal likes water?&quot;; // sample query<br>  const input = { input: query, model: &quot;text-embedding-ada-002&quot; };<br>  openai.createEmbedding(input).then((response) =&gt; {<br>    const query_embedding = response.data.data[0].embedding; // extract query embedding array<br>    // Search documents by query embedding<br>    client<br>      .search({<br>        index: &quot;pets&quot;,<br>        body: {<br>          knn: {<br>            field: &quot;embedding&quot;,<br>            query_vector: query_embedding,<br>            k: 5, // Return the top 3 nearest neighbors<br>            &quot;num_candidates&quot;: 10<br>          },<br>        },<br>      })<br>      .then((result) =&gt; {<br>        const hits = result.hits.hits; // get the matched documents<br>        hits.forEach((hit) =&gt; {<br>          console.log(hit._source.document); // print the document text<br>          console.log(hit._score); // print the similarity score<br>        });<br>      });<br>  });<br>};<br>const main = () =&gt; {<br>  createIndices();<br>  createIndexs()<br>  query()<br>};<br>main();</pre><p>The output of this code might look something like this:</p><pre>A fish is an aquatic animal that likes to swim.<br>1.9999999<br>A bird is a feathered creature that likes to fly.<br>1.0000001<br>A dog is a loyal companion that likes to play.<br>0.99999994<br>A cat is a domesticated animal that likes to sleep.<br>0.9999999<br>A lion is a wild animal that likes to hunt.<br>0.9999998</pre><p>As you can see, the fish document is the most relevant one for the query, followed by the bird document. The other documents have lower similarity scores and are less relevant.</p><blockquote>More Examples and usecases of using text-embedding-ada-002 can be found here <a href="https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada">https://rajaosama.me/blogs/blazing-fast-search-with-embedding-model-ada</a></blockquote><p>Thank you.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <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://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5605c8d08815" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-embed-search-with-text-embedding-ada-002-in-node-js-5605c8d08815">Blazing Fast Search with text-embedding-ada-002 in Node.js 🚀</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Life-Changing Year in Dubai As a Javascript Software Engineer: Discovering the Unmatched Charm…]]></title>
            <link>https://supersami.medium.com/my-life-changing-year-in-dubai-discovering-the-unmatched-charm-of-the-city-4e94dbb53189?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e94dbb53189</guid>
            <category><![CDATA[career-in-dubai]]></category>
            <category><![CDATA[life-in-dubai]]></category>
            <category><![CDATA[beauty-of-dubai]]></category>
            <category><![CDATA[job-search]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 21:49:12 GMT</pubDate>
            <atom:updated>2023-06-06T04:54:37.074Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Life-Changing Year in Dubai As a Javascript Software Engineer: Discovering the Unmatched Charm of the City</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXeapAJRRz8uBrUZ59vEzA.jpeg" /><figcaption>The photo was taken from one central — WeWork</figcaption></figure><p>Dubai, United Arab Emirates, is a destination that needs no introduction. It is one of the world’s most renowned tourist destinations, and rightfully so! As someone who had the chance to live in this remarkable city for a year, I can attest to the fact that Dubai’s allure is unparalleled. Dubai is a city that never ceases to amaze me. It is one of the world’s most innovative and vibrant tech hubs, and I’m lucky to be a part of it. As a Javascript Software Engineer who lived and worked in this incredible city for a year, I can tell you that Dubai’s tech scene is second to none. In this article, I will share my extraordinary experience living in Dubai and my unique experience as a Javascript Software Engineer in Dubai and offer some advice for anyone interested in following a similar path.</p><h3>Studying in Dubai During a Pandemic</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w2l4WNYJLGttzEnWM_I8_g.png" /><figcaption>Middlesex university</figcaption></figure><p>In February 2022, I made the decision to relocate to Dubai to pursue my Bachelor’s in Information Technology. It was a challenging decision given the COVID-19 pandemic, but I chose to take a leap of faith. Although I had the option to study from home, I wanted to experience the city’s beauty, diversity, and infrastructure in person. Moreover, with Dubai’s booming tech industry and countless opportunities, I was confident I could find a rewarding job as a Javascript Software Engineer.</p><h3>The Unmatched Beauty of Dubai</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uy6GKnLxVtBAGVod7kROSA.jpeg" /></figure><p>Dubai had me under its spell from the moment I arrived. The architecture, people, and laws were all impeccable, making it easy to fall in love with the city. Safety and security were a top priority, which was a relief coming from Karachi. I knew I was in for an unforgettable experience. The iconic Burj Al Arab and Burj Khalifa blew me away with their stunning design and views. And the lively Souk Madinat with its traditional Arabic vibes was a sensory delight. Oh, and the beaches were simply heavenly, with crystal clear waters and amazing infrastructure. I spent hours taking in the gorgeous scenery and soaking up the sun. Dubai truly has it all, and I’m grateful for the chance to experience it firsthand.</p><p>Dubai impressed me with its cutting-edge technology, diverse talent pool, and supportive ecosystem. The city is home to some of the world’s leading tech companies, such as Amazon, Microsoft, and IBM, as well as many startups and local businesses. The tech community is also very active and welcoming, with events, meetups, and workshops happening regularly. I had the chance to network with other Javascript Software Engineers, learn from experts, and showcase my skills. And the best part? The city is stunningly beautiful, with breathtaking landmarks, cultural attractions, and natural wonders. I enjoyed every moment of living and working in Dubai.</p><h3>Building a Career in Dubai</h3><p>In my last semester, I struck gold by landing an amazing job and making some great friends in Dubai. But let me tell you, getting hired in Dubai is tough. You’ve got to make yourself look like a million bucks by highlighting your skills, experience, and killer communication and presentation skills. To really stand out, I made a standout LinkedIn profile and portfolio with some of my best projects. Believe me, it makes all the difference in getting your dream job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLVRbzvtOOBoUpiGV570Kg.jpeg" /></figure><p>Thanks to my incredible colleagues and the top-notch company I worked with in Dubai, my career took off. The culture was supportive, caring, and passionate, which made all the difference. I felt inspired to do my best every day, and it showed in my career trajectory. Looking back, I’m so grateful for the experience and the growth it brought to my career.</p><h3>Accomplishing Dreams in Dubai</h3><p>Living in Dubai for a year enabled me to accomplish things I never thought possible. I got my apartment, earned my driver’s license on the first try, and learned how to be independent. One year in Dubai gave me the chance to realize my dreams, and I am grateful for every opportunity that came my way. One year in Dubai gave me the opportunity to fulfill my potential and live my dreams.</p><h3>Experience Dubai’s Unique Charm</h3><p>Dubai is a city that has something to offer everyone. It is a place where dreams come true and where you can be the best version of yourself. I urge everyone to visit this remarkable city at least once in their lifetime. As the saying goes, “If you can dream it, you can achieve it.” Dubai is proof that dreams can come true.</p><p>In conclusion, Dubai is an exceptional city that I will forever cherish. Its unparalleled beauty, opportunities, and experiences make it a destination like no other. If you are considering a move to Dubai, my advice to you is to go for it! You may just find yourself accomplishing things you never thought possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e94dbb53189" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most scalable Next Js Folder Structure]]></title>
            <link>https://supersami.medium.com/most-scalable-next-js-folder-structure-3595424b4810?source=rss-c7c048bd85b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3595424b4810</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Raja Osama]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 05:51:27 GMT</pubDate>
            <atom:updated>2022-11-28T05:51:27.535Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m2U19s206CZyqySW.png" /><figcaption><a href="https://rajaosama.me/blogs/nextjs-folder-structure">Most scalable Next Js Folder Structure (rajaosama.me)</a></figcaption></figure><h3>The Idea</h3><p>The team recently switched from Normal Create React App to Next JS. After that choice, I was given the assignment to make a Template for the Backstage. Not simply a template but also one that will scale effectively in the future. Since it is common knowledge that as applications get bigger, their folder and code structures get more complicated over time, and eventually, it all starts to look intimidating, therefore, the objective was to develop a Directory structure that can grow over time while remaining manageable.</p><p>After performing much research, I developed a Next JS Structure, and we are now using it in all of our projects. Making our application as scalable as possible is the goal. This lesson will put a lot of emphasis on the front-end portion of our program, keeping in mind that the backend of our application is primarily built using Spring boot.</p><p>Read Full article on : <a href="https://rajaosama.me/blogs/nextjs-folder-structure">Most scalable Next Js Folder Structure (rajaosama.me)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3595424b4810" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>