<?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 Andrew Red on Medium]]></title>
        <description><![CDATA[Stories by Andrew Red on Medium]]></description>
        <link>https://medium.com/@Andrew.Red?source=rss-8273140d8f57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vc58zO1dCNZNpr0yGz1PtQ.jpeg</url>
            <title>Stories by Andrew Red on Medium</title>
            <link>https://medium.com/@Andrew.Red?source=rss-8273140d8f57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:09:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Andrew.Red/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[How to use custom tag with React-based application]]></title>
            <link>https://medium.com/@Andrew.Red/how-to-use-custom-tag-with-react-based-application-79f552a04976?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/79f552a04976</guid>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 11:50:16 GMT</pubDate>
            <atom:updated>2024-04-15T11:50:16.879Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35pCgnE1fIUHzgwNKN5AYQ.png" /></figure><p>Recently, I encountered trouble integrating the Google Generative App into a React-based application. The main issue was that the Google Generative App is a web component, which should be used as a custom tag. Since I have a Next.js application, I faced a problem during the build process: it failed, citing the use of an unknown custom tag.</p><p>Here is a way to bypass the build issue and inform the application about the custom tag.</p><pre>// better to add this into d.ts file or in the original component<br>declare global {<br>  namespace JSX {<br>    interface IntrinsicElements {<br>      &#39;gen-search-widget&#39;: React.DetailedHTMLProps&lt;<br>        React.HTMLAttributes&lt;HTMLElement&gt; &amp; {<br>        configId: string;<br>        location: string;<br>        triggerId: string;<br>      },<br>        HTMLElement<br>      &gt;;<br>    }<br>  }<br>}<br><br>// component with custom tag<br>export const CustomTagComponent = () =&gt; {<br>  return (<br>    &lt;gen-search-widget<br>      configId=&quot;***&quot;<br>      location=&quot;eu&quot;<br>      triggerId=&quot;***&quot;<br>    /&gt;<br>  );<br>};</pre><p>After adding this fix, Webpack no longer complains during the build process, allowing you to successfully deliver your custom tag.</p><p>Find out more useful content at:</p><ul><li><a href="https://twitter.com/AndrewRedUK">Twitter</a></li><li><a href="https://github.com/mazahaca">Github</a></li></ul><p>Any feedback, contribution, or help is highly appreciated.</p><p>Thanks for your time and happy coding! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79f552a04976" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Promise with timeout in JavaScript]]></title>
            <link>https://medium.com/@Andrew.Red/how-to-use-promise-with-timeout-in-javascript-44830baa5767?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/44830baa5767</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Wed, 10 Jan 2024 23:55:30 GMT</pubDate>
            <atom:updated>2024-01-10T23:55:30.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8svTa0qPLw5n7DpTQn4ZlQ.png" /></figure><p>JavaScript is amazing with Promises and async support. However, it comes without native support of timeouts for Promises.</p><p>Here is how it can be implemented with Promise.race:</p><pre>const awaitWithTimeout = (p, timeout) =&gt;<br>  Promise.race([<br>    p,<br>    new Promise((_, err) =&gt;<br>      setTimeout(() =&gt; err(<br>        new Error(`Execution timeout ${timeout} reached`)<br>      ), timeout)<br>    )<br>  ]);<br><br>// some long operation that can raise a timeout<br>const operation = new Promise(() =&gt; {});<br>const timeout = 1000;<br>await awaitWithTimeout(operation, timeout);</pre><p>In the code above, a first promise to resolve or reject will be returned from the function awaitWithTimeout. Therefore, if the operation can finish within the defined deadline, it will return value from the promise. Otherwise, it will raise a timeout error.</p><p>Find out more useful content at:</p><ul><li><a href="https://twitter.com/AndrewRedUK">Twitter</a></li><li><a href="https://github.com/mazahaca">Github</a></li></ul><p>Any feedback, contribution, or help is highly appreciated.</p><p>Thanks for your time and happy coding! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44830baa5767" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to load GitHub projects with GraphQL in Gatsby]]></title>
            <link>https://medium.com/@Andrew.Red/how-to-load-github-projects-with-graphql-in-gatsby-95754e351a54?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/95754e351a54</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[gatsby]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 10:27:38 GMT</pubDate>
            <atom:updated>2022-04-21T10:27:38.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Alt" src="https://cdn-images-1.medium.com/max/1024/0*iLPuVG9Z894GH0f3.png" /></figure><p>Hi there 👋</p><p>I’m Andrew, a Software Engineer, and a person who contributes to open source a lot. I have a blog based on <a href="https://www.gatsbyjs.com/">gatsby</a> and forked from <a href="https://github.com/alxshelepenok/gatsby-starter-lumen">lumen</a> — the fast and flexible framework that makes building websites with any CMS, API, or database fun again.</p><p>Today I’m having fun with GraphQL for the first time in my life.</p><h4>What is GraphQL?</h4><p>GraphQL is a query language for your API and a server-side runtime for executing queries using a type system you define for your data. GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data.</p><h4>Playing with GraphQL</h4><p><strong>Goal</strong>: fetch 10 public repositories, sorted by stars, descending order.</p><p>Here is <a href="https://docs.github.com/en/graphql/overview/explorer">Github GraphQL Explorer</a>, it will help us with testing GraphQL queries.</p><p>First of all, take a look at a <a href="https://docs.github.com/en/graphql/reference/objects#repository">reference to API objects</a> to determine what we need to use for pulling repositories. Let’s try to run the easiest query — fetch the first 10 repositories using explorer.</p><pre>viewer {<br>  repositories(first: 10) {<br>    edges {<br>      node {<br>        id<br>        name<br>        url<br>      }<br>    }<br>  }<br>}</pre><p>Now, add a bit more complexity to the filtering. I want to see only public repositories I created and repositories from organizations I’m in. The following block into the repositories filter:</p><pre>ownerAffiliations: [OWNER, ORGANIZATION_MEMBER], privacy: PUBLIC, isFork: false, isLocked: false</pre><p>Adding ordering by stars:</p><pre>orderBy: { field: STARGAZERS, direction: DESC }</pre><p>Adding more data for fetching: stars, forks, owner, description, and the first 3 languages used in the repository. So, here is the final query we have:</p><pre>viewer {<br>    repositories(ownerAffiliations: [OWNER, ORGANIZATION_MEMBER], privacy: PUBLIC, isFork: false, isLocked: false, first: 10, orderBy: { field: STARGAZERS, direction: DESC }) {<br>      edges {<br>        node {<br>          id<br>          name<br>          url<br>          owner {<br>            login<br>          }<br>          description<br>          stargazers {<br>            totalCount<br>          }<br>          forkCount<br>          languages(first: 3) {<br>            nodes {<br>              id,<br>              name<br>            }<br>          }<br>        }<br>      }<br>    }<br>  }</pre><p>For now, we have the GraphQL query, and the last thing is to adapt it to gatsby’s website.</p><h4>Gatsby</h4><p>For running GraphQL queries outside our website, we need to install and configure <a href="https://www.gatsbyjs.com/plugins/gatsby-source-graphql/">gatsby-source-graphql</a>.</p><p>The next step is extending Gatsby with a new page, we need to add a new template under ./src/templates folder. Let&#39;s call it projects-template.js with the following content:</p><pre>import React from &#39;react&#39;;<br>import { graphql } from &#39;gatsby&#39;;<br><br>const ProjectsTemplate = ({ data }) =&gt; {<br>  const { title: siteTitle, subtitle: siteSubtitle } = useSiteMetadata();<br>  const { html: pageBody } = data.markdownRemark;<br>  const { frontmatter } = data.markdownRemark;<br>  const {<br>    viewer: {<br>      repositories: { edges },<br>    },<br>  } = data.github;<br>  const { title: pageTitle, description: pageDescription = &#39;&#39;, socialImage } = frontmatter;<br>  const metaDescription = pageDescription || siteSubtitle;<br>  const socialImageUrl = socialImage?.publicURL;<br><br>  return (<br>    &lt;Layout title={`${pageTitle} - ${siteTitle}`} description={metaDescription} socialImage={socialImageUrl} &gt;<br>      &lt;Sidebar /&gt;<br>      &lt;Page title={pageTitle}&gt;<br>        &lt;div dangerouslySetInnerHTML={{ __html: pageBody }} /&gt;<br>        &lt;Projects edges={edges}/&gt;<br>      &lt;/Page&gt;<br>    &lt;/Layout&gt;<br>  );<br>};<br><br>export const query = graphql`<br>  query ProjectsPage($slug: String!) {<br>    markdownRemark(fields: { slug: { eq: $slug } }) {<br>      id<br>      html<br>      frontmatter {<br>        title<br>        date<br>        description<br>        socialImage {<br>          publicURL<br>        }<br>      }<br>    }<br>    github {<br>      viewer {<br>        repositories(ownerAffiliations: [OWNER, ORGANIZATION_MEMBER], privacy: PUBLIC, isFork: false, isLocked: false, first: 10, orderBy: { field: STARGAZERS, direction: DESC }) {<br>          edges {<br>            node {<br>              id<br>              name<br>              url<br>              owner {<br>                login<br>              }<br>              description<br>              stargazers {<br>                totalCount<br>              }<br>              forkCount<br>              languages(first: 3) {<br>                nodes {<br>                  id,<br>                  name<br>                }<br>              }<br>            }<br>          }<br>        }<br>      }<br>    }<br>  }<br>`;<br><br>export default ProjectsTemplate;</pre><p>After creating the template, we also need to extend Gatsby’s createPages method, I have it located in ./gatsby/create-pages.js.</p><p>Inside the section where gatsby iterates over the content pages, let’s add the following code:</p><pre>const { edges } = result.data.allMarkdownRemark;<br><br>  _.each(edges, (edge) =&gt; {<br>    // ...<br>    if (_.get(edge, &#39;node.frontmatter.template&#39;) === &#39;projects&#39;) {<br>      createPage({<br>        path: edge.node.fields.slug,<br>        component: path.resolve(&#39;./src/templates/projects-template.js&#39;),<br>        context: {<br>          slug: edge.node.fields.slug,<br>          projectsCount: siteConfig.author.projects.count * 2,<br>        },<br>      });<br>    }<br>  });</pre><p>Since that, we have 3 different markdown templates: post, page, and the new one projects.</p><p>It’s time to create a new markdown page with content for the projects page in the path ./content/pages/projects.md:</p><pre>---<br>title: &quot;Projects&quot;<br>template: &quot;projects&quot;<br>socialImage: &quot;/media/robo-andrew.jpg&quot;<br>---<br><br>Here is the list of github projects I&#39;ve contributed to:</pre><p>The following part template: &quot;projects&quot; defines for createPages method what template should be used, therefore Gatsby needs to load the projects template from ./src/templates/projects-template.js</p><p>Okay, now all the bits are connected to each other. Let’s see the result 👇</p><p>Public GitHub projects from my profile are pulled using GraphQL API and integrated into Gatsby’s blog.</p><figure><img alt="Github Projects Example at andrew.red" src="https://cdn-images-1.medium.com/max/1024/0*O0yOictuu4S6AF3_.png" /></figure><p>Check out the live version on the <a href="https://andrew.red/pages/projects/">projects page</a>.</p><h4>Interested in more Gatsby or GraphQL?</h4><p>Find out useful content at:</p><ul><li><a href="https://twitter.com/AndrewRedUK">Twitter</a></li><li><a href="https://github.com/mazahaca">Github</a></li></ul><p>Any feedback, contribution, or help is highly appreciated.</p><p>Thanks for your time and happy coding! 👋</p><h4>Resources</h4><ul><li><a href="https://graphql.org/learn/queries/">GraphQL Queries</a></li><li><a href="https://docs.github.com/en/graphql/overview/explorer">Github GraphQL Explorer</a></li><li><a href="https://docs.github.com/en/graphql/reference/objects#repository">Reference to API objects</a></li><li><a href="https://www.gatsbyjs.com/docs/recipes/pages-layouts/">Gatsby Page Layouts</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95754e351a54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Github action for adding a markdown post to Medium]]></title>
            <link>https://medium.com/@Andrew.Red/github-action-for-adding-a-markdown-post-to-medium-5ef1b1c58c33?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ef1b1c58c33</guid>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[blogger]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Fri, 15 Apr 2022 09:15:09 GMT</pubDate>
            <atom:updated>2022-04-15T09:15:09.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Alt" src="https://cdn-images-1.medium.com/max/1024/0*tvBlcQTmR_rZYFxU.png" /></figure><h4>Share your posts on Medium</h4><p>Here is another yet article about automation of the blogging process with a self-hosted website.</p><p>Today we’re going to explore the medium API and take a look at GitHub action, which copies your website’s blog post to the medium in no pain.</p><p>The following <a href="https://github.com/InfraWay/post-medium-action">code snippet</a> publishes a blog post written in markdown using <a href="https://github.com/features/actions">Github Actions</a> directly to Medium.</p><h4>Use cases</h4><p>You may ask “How this could be applied in the real world?”</p><p>It really could if you automate your blog with <a href="https://github.com/features/actions">Github Actions</a>.</p><p>Here are a couple of examples of where to use it:</p><ul><li>blogging system, to automate the process of publishing</li><li>exporting your existing blog to medium</li></ul><h4>Setup steps</h4><ul><li>Go to medium’s profile settings <a href="https://medium.com/me/settings">here</a> &gt; Integration tokens.</li><li>Enter “token name” and press <strong>Get integration token</strong>.</li><li>Now you need to get into a Github repository</li><li>Go to the repository settings page and secrets with previously saved keys.</li></ul><pre>MEDIUM_ACCESS_TOKEN=&quot;generated token&quot;</pre><ul><li>Now it’s the moment to expand <a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions">Github Action yaml</a> file for your blog. Here is a quick example:</li></ul><pre>name: publish-to-medium<br>on: [push]<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - id: files<br>        uses: jitterbit/get-changed-files@v1<br>      - id: posts<br>        name: Detecting posts from the changes<br>        run: |<br>          i=0<br>          for changed_file in ${{ steps.files.outputs.added_modified }}; do<br>            echo &quot;Do something with ${changed_file}.&quot;<br>            if [[ &quot;${changed_file}&quot; == &quot;content/posts&quot;* ]];<br>            then<br>              echo &quot;File ${changed_file} matched post.&quot;<br>              echo &quot;::set-output name=post${i}::${changed_file}&quot;<br>              ((i=i+1))<br>            fi<br>          done<br>      - if: steps.posts.outputs.post0<br>        name: Publish to medium<br>        uses: infraway/post-medium-action@main<br>        with:<br>          app_id: ${{ secrets.MEDIUM_APP_ID }}<br>          app_secret: ${{ secrets.MEDIUM_APP_SECRET }}<br>          access_token: ${{ secrets.MEDIUM_ACCESS_TOKEN }}<br>          markdown_file: ${{ steps.posts.outputs.post0 }}<br>          base_url: https://andrew.red<br>          post_url: <a href="https://andrew.red/posts">https://andrew.red/posts</a></pre><ul><li>When the following code snippet is added, you can push anything into the repo and see a blog post also added to your Medium account.</li></ul><h4>Interested in giving it a try?</h4><p>Find more useful DevOps automation tools at:</p><ul><li><a href="https://twitter.com/AndrewRedUK">Twitter</a></li><li><a href="https://github.com/infraway">Github</a></li></ul><p>Of course, all <a href="https://github.com/InfraWay/post-medium-action">the source code is open-sourced</a>.</p><p>Any feedback, contribution, or help is highly appreciated.</p><p>Thanks for your time and have a nice coding! :wave:</p><h4>Resources</h4><ul><li><a href="https://github.com/features/actions">Github Actions</a></li><li><a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions">Github Actions YAML configuration</a></li><li><a href="https://github.com/InfraWay/post-medium-action">Post Medium Action</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ef1b1c58c33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deeper dive into gRPC and creating own micro-service architecture in Node.js]]></title>
            <link>https://medium.com/@Andrew.Red/deeper-dive-into-grpc-and-creating-own-micro-service-architecture-in-node-js-6ff308133510?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ff308133510</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Tue, 15 Mar 2022 10:54:00 GMT</pubDate>
            <atom:updated>2022-03-17T10:31:26.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2GGwVAIoqG0PYEfabDRmw.png" /></figure><p>Co-Author: <a href="https://medium.com/u/4e3af1f8d9a6">Alex Korzhikov</a></p><h3>What is GRPC?</h3><p>gRPC Remote Procedure Calls, of course!</p><p><a href="https://grpc.io/docs/what-is-grpc/faq/">gRPC</a> is a <em>modern, open source</em> <em>remote procedure call (RPC)</em> framework that can run anywhere. It enables <em>client and server</em> applications to communicate transparently and makes it easier to build connected systems</p><p><strong>History</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oGWRisnu1PZ8W626.png" /></figure><ul><li>March 2015 🗓</li><li>Google ➡️ Open Source</li><li>Standardize Microservices Architecture, Framework &amp; Infrastructure</li><li>SPDY (HTTP/2)</li><li>QUIC (HTTP/3)</li><li>Stubby</li><li>Part of <a href="https://www.cncf.io/projects/grpc/">Cloud Native Computing Foundation</a></li><li><a href="https://grpc.io/blog/principles/">Motivation</a>, FAQ, Tutorials</li></ul><p><strong>RPC</strong></p><p>A <em>distributed computing technique</em> when</p><ul><li>A client program sends a request to a known remote server to execute a specified procedure</li><li>The remote server executes the local procedure and sends a response back to the client</li><li>The client continues to run</li></ul><p>More steps are involved in the process:</p><ul><li>local client stub</li><li>marshaling parameters into a message</li><li>remote server call</li><li>local server stub</li><li>unpacking or unmarshalling message parameters</li></ul><p><strong>Questions</strong></p><ul><li>How does a client service calls a remote service?</li><li>How to expose a remote service?</li><li>How data is serialized for the network?</li><li>How does communication happen?</li><li>Authentication?</li></ul><p>Client 😀 ⬅️ ➡️ 💻 Server Communication</p><p><strong>Web Protocols</strong></p><ul><li>SOAP</li><li>REST</li><li>GraphQL</li></ul><p>Or even more generic</p><ul><li>HTTP/1.1</li><li>HTTP/2</li><li>TCP</li><li>UDP</li><li>WebSockets</li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events">Server-Sent Events</a></li></ul><blockquote><em>We always need a client library to communicate to a server!</em></blockquote><h4>Features</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtBlq8Mw_paWBCfDzJwf3Q.png" /></figure><ul><li>Service Definitions (Protocol)</li><li>Strong Typed</li><li>Protocol Buffers ⏭</li></ul><p><strong>Client &amp; Server</strong></p><ul><li>Generated Code (Stubs)</li><li><a href="https://grpc.io/docs/languages/">10+ Languages</a></li><li><a href="https://grpc.io/docs/platforms/">Platforms &amp; Environments</a> — Android, Web, Flutter</li><li><a href="https://github.com/grpc/grpc">Core version 1.43.0</a></li><li>Extension Points</li></ul><p><strong>Communication</strong></p><ul><li>HTTP/2</li><li>Serialization</li><li>Message Ordering</li><li>Streams</li><li>Sync/Async</li></ul><p><strong>Authentication</strong></p><pre><em>// http://protobuf-compiler.herokuapp.com/</em><br>syntax <strong>=</strong> &quot;proto3&quot;;<br><br><strong>package</strong> hello;<br><br><strong>service</strong> HelloService {<br>  <strong>rpc</strong> JustHello (HelloRequest) <strong>returns</strong> (HelloResponse);<br><br>  <strong>rpc</strong> ServerStream(HelloRequest) <strong>returns</strong> (stream HelloResponse);<br><br>  <strong>rpc</strong> ClientStream(stream HelloRequest) <strong>returns</strong> (HelloResponse);<br><br>  <strong>rpc</strong> BothStreams(stream HelloRequest) <strong>returns</strong> (stream HelloResponse);<br>}<br><br><strong>message</strong> <strong>HelloRequest</strong> {<br>  <strong>string</strong> greeting <strong>=</strong> 1;<br>}<br><br><strong>message</strong> <strong>HelloResponse</strong> {<br>  <strong>string</strong> reply <strong>=</strong> 1;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*xdd4A6LIlCwqn_Rg.png" /></figure><h3>What are Protocol Buffers?</h3><p><em>An efficient technology to serialize structured data</em></p><pre><strong>message</strong> <strong>Person</strong> {<br>  <strong>string</strong> name <strong>=</strong> 1;<br>  <strong>int32</strong> id <strong>=</strong> 2;<br>  <strong>bool</strong> has_ponycopter <strong>=</strong> 3;<br>}</pre><blockquote><em>Does anyone know what numbers on the right side mean?</em></blockquote><p><strong>History</strong></p><ul><li><a href="https://developers.google.com/protocol-buffers/">Protocol Buffers — Google Developers</a></li><li><a href="https://github.com/protocolbuffers/protobuf/commit/40ee551715c3a784ea6132dbf604b0e665ca2def">July 2008</a> 🗓</li><li>Google ➡️ Open Source</li></ul><p><strong>Features</strong></p><ul><li>Typed .proto format</li><li>Code Generation</li><li>protoc - the protocol buffers compiler</li><li><a href="https://github.com/protocolbuffers/protobuf#protobuf-runtime-installation">10+ Languages</a></li><li><a href="https://github.com/protocolbuffers/protobuf/blob/master/docs/third_party.md">Third-Party Add-ons for Protocol Buffers</a></li><li>Services Description</li></ul><p><strong>Advanced</strong></p><pre><em>// rule type name tag</em><br><strong>repeated</strong> <strong>uint64</strong> vals <strong>=</strong> 1;</pre><ul><li>Fields &amp; Types</li><li>Message</li><li>Scalar</li><li>Enums</li><li>Repeated</li><li>No void type, no scalar types in arguments</li><li>Packages</li><li>Services — not used by protobuf directly</li></ul><pre>syntax <strong>=</strong> &quot;proto3&quot;;</pre><pre><strong>package</strong> hello;</pre><pre><strong>service</strong> HelloService {<br>  <strong>rpc</strong> SayHello (HelloRequest) <strong>returns</strong> (HelloResponse);<br>}</pre><pre><strong>message</strong> <strong>HelloRequest</strong> {<br>  <strong>string</strong> greeting <strong>=</strong> 1;<br>}</pre><pre><strong>message</strong> <strong>HelloResponse</strong> {<br>  <strong>string</strong> reply <strong>=</strong> 1;<br>}</pre><ul><li>Plugins</li><li>Compiler Options</li><li>Nested Types</li><li>Required, Optional</li><li><a href="https://developers.google.com/protocol-buffers/docs/overview#updating">No versioning</a></li><li>Don’t change tags for existing fields</li><li>package mypackage.v1, package mypackage.v2beta1</li><li>Maps, oneOf, allOf</li></ul><h3>Crypto 🦄 Currency Converter</h3><h3>Prerequisites</h3><h4>1. Checkout demo project</h4><p>Let’s get started from cloning demo mono-repo</p><pre>git clone git@github.com:x-technology/mono-repo-nodejs-svc-sample.git</pre><h4>2. Install protoc</h4><p>For efficient work with .proto format, and to be able to generate TypeScript-based representation of protocol buffers we need to install protoc library.</p><p>If you’re a MacOS user and have <a href="https://brew.sh/">brew</a> package manager, the following command is the easiest way for installation:</p><pre>brew install protobuf<br><em># Ensure it&#39;s installed and the compiler version at least 3+</em><br>protoc --version</pre><p>For Linux users, run the following commands:</p><pre>PROTOC_ZIP<strong>=</strong>protoc-3.14.0-linux-x86_64.zip<br>curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP<br>sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc<br>sudo unzip -o $PROTOC_ZIP -d /usr/local &#39;include/*&#39;<br>rm -f $PROTOC_ZIP</pre><p>Alternately, manually download and install protoc from <a href="https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip">here</a>.</p><h4>3. Prepare environment</h4><p>Make sure we have Node.js v14+ installed. If not, <a href="https://github.com/nvm-sh/nvm#installing-and-updating">nvm</a> is a very good tool to install multiple node versions locally and easily switch between them.</p><p>Then we need to install dependencies and bootstrap lerna within the monorepo.</p><pre>yarn install<br>yarn lerna bootstrap</pre><p>Yay! 🎉 Now we’re ready to go with the project.</p><h3>Monorepo structure</h3><p>For better mono-repo project management we used <a href="https://github.com/lerna/lerna">Lerna</a> &amp; <a href="https://classic.yarnpkg.com/lang/en/docs/workspaces/">Yarn Workspaces</a></p><p>The project shapes into the following structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*uurc2NfKHOKvUsbc.png" /></figure><ul><li>./packages/common folder contains common libraries used in other project’s services.</li><li>./packages/services/grpc folder contains gRPC services we build to share the product.</li><li>./proto folder contains proto files, which describe protocol of input/output and communication between the services.</li><li>./node_modules - folder with dependencies, shared between all microservices.</li><li>./lerna.json - lerna’s configuration file, defining how it should work with monorepo.</li><li>./package.json - description of our package, containing the important part:</li></ul><pre><strong>&quot;workspaces&quot;</strong>: [<br>  &quot;packages/common/*&quot;,<br>  &quot;packages/services/grpc/*&quot;<br>]</pre><p>Let’s move on 🚚</p><h3>Using Lerna</h3><p>Lerna brings to the table a few commands which can be easily executed across all/or filtered packages.</p><p>We use our common modules compiled to JavaScript, so before using it in services we need to build it first.</p><p>Following command executed build command against all common packages filtered with flag --scope=@common/*</p><pre>yarn lerna run build --scope<strong>=</strong>@common/<strong>*</strong></pre><h3>Common &amp; Services</h3><p>Let’s look into ./packages/common. It contains common libraries used in other places of the system. One of such libraries is @common/grpc, it contains proto generated into TypeScript/JavaScript formats as well as common gRPC server.</p><p>Following command is required to be run if we’re changing proto’s:</p><pre>cd ./packages/common/go-grpc <strong>&amp;&amp;</strong> yarn build</pre><pre><em># OR using lerna</em></pre><pre>yarn lerna run build --scope<strong>=</strong>@common/<strong>*</strong></pre><p>For this particular task, we implement only gRPC services which are stored in the folder ./packages/services/grpc. But if we decide to add rest, ./packages/common/rest is a good place to add it.</p><h3>What we’re building</h3><p>We’re building a currency converter, which can be used over gRPC calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCSpgkR69-8wOdAjp80XTw.png" /></figure><p>Our intention is to send a request similar to convert 0.345 ETH to CAD and as a result, we want to know the final amount in CAD and conversion rate. We also assume that it could be more than one currency provider, e.g.</p><ol><li>Europe Central Bank rates</li><li>Bank of England rates</li><li>Crypto Rates</li></ol><p>Here is how it works:</p><ul><li>Currency Converter fetches each of the provider, accumulates, and uses for conversion rates received from providers.</li><li>Currency Provider is a proxy to gain single source of rates, it also converts rates into the common format defined in proto’s.</li></ul><h3>A deeper look into *.proto files</h3><p>In the proto folder, according to our schema, we created the following files:</p><ul><li>currency-converter.proto - converter interface</li><li>currency-provider.proto - provider interface</li><li>ecb-provider.proto and crypto-provider.proto - implementation of two particular providers.</li></ul><p>In the implementation provider, we could just import an existing proto file and use its definitions.</p><pre><strong>import</strong> &quot;currency-provider.proto&quot;;</pre><pre><strong>package</strong> ecbProvider;</pre><pre><strong>service</strong> EcbProvider {<br>  <strong>rpc</strong> GetRates(currencyProvider.GetRatesRequest) <strong>returns</strong> (currencyProvider.GetRatesResponse) {}<br>}</pre><p>Let’s take a deeper look at how proto’s are generated from .proto to JavaScript.</p><p>Going back to @common/go-grpc module, we can find ./bin/build.mjs.</p><p>Here is the main command we could find there:</p><pre>protoc --plugin<strong>=</strong>&quot;protoc-gen-ts=`pwd`/node_modules/.bin/protoc-gen-ts&quot; --ts_out<strong>=</strong>&quot;service=grpc-node:`pwd`/src/proto&quot; --proto_path<strong>=</strong>&quot;`pwd`/../../../proto/&quot; `pwd`/../../../proto/<strong>*</strong>.proto</pre><h3>How to create new common lib</h3><p>We use <a href="https://www.hygen.io/">hygen</a> for templating our new services and common libraries.</p><ol><li>For example, we want to create a new logger library.</li><li>In the root directory run command yarn bootstrap:common and follow starter.</li><li>Go to the new folder in the terminal</li></ol><pre>cd ./packages/common/logger</pre><p>4. Install dependencies</p><pre>yarn install</pre><p>5. Make sure to define appropriate name in the package.json file:</p><pre><strong>&quot;name&quot;</strong>: &quot;@common/logger&quot;,</pre><p>Let’s follow a rule all common libraries have a prefix @common/</p><p>6. Create our library in a src/index.js</p><pre>export const debug <strong>=</strong> <strong>(</strong>message: string<strong>)</strong> <strong>=&gt;</strong> console.debug<strong>(</strong>message<strong>)</strong>;<br>export const info <strong>=</strong> <strong>(</strong>message: string<strong>)</strong> <strong>=&gt;</strong> console.info<strong>(</strong>message<strong>)</strong>;<br>export const error <strong>=</strong> <strong>(</strong>message: string<strong>)</strong> <strong>=&gt;</strong> console.error<strong>(</strong>message<strong>)</strong>;<br>export default <strong>{</strong> debug, info, error <strong>}</strong>;</pre><p>7. Make sure it builds successfully withing a command:</p><pre>yarn build</pre><p>8. Let’s connect our newly created library somewhere in the existing service:</p><pre>yarn lerna add @common/logger --scope<strong>=</strong>@grpc/ecb-provider</pre><p>9. In the final step, we need to use the library inside ecb-provider service. Let’s amend the file ./src/index.ts:</p><pre><strong>import</strong> logger <strong>from</strong> &#39;@common/logger&#39;;<br><br>logger.debug(&#39;service has started&#39;);</pre><p>10. Re-build ecb-provider to ensure there is no issues</p><pre>yarn build</pre><p>Yay! 🎉 It works!</p><h3>How to create new service</h3><ol><li>For example, we want to create a new crypto-compare-provider service, which is another currency rate provider returning cryptocurrencies.</li><li>Create a folder under ./packages/services/grpc/crypto-compare-provider path. For simplicity, just copy an existing ecb-provider and rename it.</li><li>Go to the folder in the terminal</li></ol><pre>cd ./packages/services/grpc/crypto-compare-provider</pre><p>4. Install dependencies</p><pre>yarn install</pre><p>5. Make sure to define appropriate name in the package.json file:</p><pre><strong>&quot;name&quot;</strong>: &quot;@grpc/crypto-compare-provider&quot;,</pre><p>Let’s follow a rule — all grpc services have a prefix @grpc/.<br>6. Create a service method file packages/services/grpc/crypto-provider/src/services/getRates.ts</p><pre>import <strong>{</strong> currencyProvider <strong>}</strong> from &#39;@common/go-grpc&#39;;<br><br>export default async <strong>(</strong><br>  _: currencyProvider.GetRatesRequest,<br><strong>)</strong>: Promise&lt;currencyProvider.GetRatesResponse&gt; <strong>=&gt;</strong> <strong>{</strong><br>  <strong>return </strong>new currencyProvider.GetRatesResponse<strong>({</strong><br>    rates: <strong>[]</strong>,<br>    baseCurrency: &#39;USD&#39;,<br>  <strong>})</strong>;<br><strong>}</strong>;</pre><p>8. So next we need to use this method inside server.ts</p><pre><strong>import</strong> { Server, LoadProtoOptions, currencyProvider } <strong>from</strong> &#39;@common/go-grpc&#39;;<br><strong>import</strong> getRates <strong>from</strong> &#39;./services/getRates&#39;;<br><br><strong>const</strong> { PORT <strong>=</strong> 50051 } <strong>=</strong> process.env;<br><strong>const</strong> protoOptions: LoadProtoOptions <strong>=</strong> {<br>  path: `${__dirname}/../../../../../proto/crypto-compare-provider.proto`,<br>  <em>// this value should be equvalent to the one defined in *.proto file as &quot;package cryptoCompareProvider;&quot;</em><br>  package: &#39;cryptoCompareProvider&#39;,<br>  <em>// this value should be equvalent to the one defined in *.proto file as &quot;service CryptoCompareProvider&quot;  </em><br>  service: &#39;CryptoCompareProvider&#39;,<br>};<br><br><strong>const</strong> server <strong>=</strong> <strong>new</strong> Server(`0.0.0.0:${PORT}`, protoOptions);<br>server<br>  .addService<strong>&lt;</strong>currencyProvider.GetRatesRequest,<br>    Promise<strong>&lt;</strong>currencyProvider.GetRatesResponse<strong>&gt;&gt;</strong>(&#39;GetRates&#39;, getRates);<br><strong>export</strong> <strong>default</strong> server;</pre><p>9. Make sure it builds successfully withing a command:</p><pre>yarn build</pre><p>10. Start the service with the command:</p><pre>yarn start</pre><p>Yay! 🎉 It works!</p><h3>How to test services</h3><p>We use <a href="https://jestjs.io/docs/getting-started">jest</a> as a test framework and decided to write integration tests for our services. This is the best way to understand different situations, which could happen with services on the particular input/output.</p><ol><li>Let’s begin from creating a test file test/services/index.spec.ts</li></ol><pre>mkdir -p test/services<br>touch test/services/index.spec.ts</pre><p>2. First of all in the test we need to define a server, which is imported from src folder and start it in the section beforeAll</p><pre><strong>import</strong> { ecbProvider, currencyProvider, createInsecure } <strong>from</strong> &#39;@common/go-grpc&#39;;<br><strong>import</strong> server <strong>from</strong> &#39;../../src/server&#39;;<br><br><strong>const</strong> testServerHost <strong>=</strong> &#39;localhost:50061&#39;;<br>beforeAll(<strong>async</strong> () <strong>=&gt;</strong> {<br>   <strong>await</strong> server.start(testServerHost);<br>});<br>afterAll(<strong>async</strong> () <strong>=&gt;</strong> {<br>   <strong>await</strong> server.stop();<br>});</pre><p>3. Next, let’s create a client which will invoke the server’s methods via gRPC protocol</p><pre><strong>import</strong> { ecbProvider, createInsecure } <strong>from</strong> &#39;@common/go-grpc&#39;;<br><br><strong>const</strong> client <strong>=</strong> <strong>new</strong> ecbProvider.EcbProviderClient(<br>  testServerHost,<br>  createInsecure(),<br>);</pre><p>4. Let’s add first test suite in here and expect some particular result from the service’s method</p><pre>describe(&#39;GetRates&#39;, () <strong>=&gt;</strong> {<br> it(&#39;should return currency rates&#39;, <strong>async</strong> () <strong>=&gt;</strong> {<br>    <strong>const</strong> response <strong>=</strong> <strong>await</strong> client.GetRates(<strong>new</strong> currencyProvider.GetRatesRequest());<br><br>    expect(response.toObject()).toEqual({<br>      baseCurrency: &#39;EUR&#39;,<br>      rates: [<br>        { currency: &#39;USD&#39;, rate: 1.1348 },<br>      ],<br>    });<br>  });<br>});</pre><p>5. Now it’s time to try it out with a command:</p><pre>yarn test</pre><p>Brilliant! 🎉 It works!</p><h3>How to run this magic 🪄?</h3><p>How could we run this magic to convert for us some currency?</p><pre>export PORT<strong>=</strong>50052 <strong>&amp;&amp;</strong> cd ./packages/services/grpc/ecb-provider/ <strong>&amp;&amp;</strong> yarn start<br>export PORT<strong>=</strong>50051 <strong>&amp;&amp;</strong> cd ./packages/services/grpc/currency-provider/ <strong>&amp;&amp;</strong> yarn start</pre><p>Here is a tool <a href="https://github.com/fullstorydev/grpcurl#installation">grpcurl</a> for sending a test request to gRPC service from the terminal.</p><pre><em># list all services</em><br>grpcurl -import-path ./proto -proto ecb-provider.proto list<br><br><em># list all methods of service</em><br>grpcurl -import-path ./proto -proto ecb-provider.proto list ecbProvider.EcbProvider<br><br><em># call method GetRates</em><br>echo &#39;{}&#39; | grpcurl -plaintext -import-path ./proto -proto ecb-provider.proto -d @ 127.0.0.1:50052 ecbProvider.EcbProvider.GetRates</pre><p>Hurray! 🚀</p><h3>Summary</h3><p>We’ve discovered gRPC, Lerna, Yarn Workspaces, and the configuration of tools for the mono-repo project which increase speed and quality while developing microservice architecture from scratch.</p><h3>Links</h3><ul><li><a href="https://developers.google.com/protocol-buffers">Protocol Buffers — Developers Google</a></li><li><a href="https://www.grpc.io/">gRPC</a></li><li><a href="https://www.youtube.com/watch?v=xsIwYL-N4vI">Scalable Microservices with gRPC, Kubernetes, and Docker by Sandeep Dinesh, Google</a></li><li><a href="https://www.youtube.com/watch?v=OuyxRE9xLw4">NestJS Microservices — 4 — Using gRPC</a></li><li><a href="https://www.youtube.com/watch?v=fl9AZieRUaw">Getting Started with gRPC and JavaScript — Colin Ihrig, Joyent</a></li><li><a href="https://youtu.be/46O73On0gyI">Protocol Buffers Crash Course</a></li><li><a href="https://www.youtube.com/watch?v=Yw4rkaTc0f8">gRPC Crash Course — Modes, Examples, Pros &amp; Cons and more</a></li><li><a href="https://www.grpc.io/docs/languages/node/basics/">A basic tutorial introduction to gRPC in Node</a></li><li><a href="https://speedscale.com/2021/07/20/choosing-an-api-technology-grpc-rest-graphql/">Choosing An API Technology: GRPC, REST, GraphQL — Jura Gorohovsky</a></li><li><a href="https://www.youtube.com/watch?v=l_P6m3JTyp0">GraphQL, gRPC or REST? Resolving the API Developer’s Dilemma — Rob Crowley</a></li><li><a href="https://www.youtube.com/watch?v=fMq3IpPE3TU">The Story of Why We Migrate to gRPC and How We Go About It — Matthias Grüter, Spotify</a></li><li><a href="https://www.youtube.com/watch?v=kUz2zjkKxFg">Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 first by Mete Atamel</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ff308133510" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to load dotenv (.env) file from shell]]></title>
            <link>https://medium.com/@Andrew.Red/how-to-load-dotenv-env-file-from-shell-c656c810c11?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/c656c810c11</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[100daysofcode]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Wed, 01 Dec 2021 23:39:02 GMT</pubDate>
            <atom:updated>2022-03-09T23:30:28.357Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi, there!</p><p>Today I was doing a microservice crafted on top of TypeScript, gRPC, CockroachDb and got a need to build and run it locally.</p><p>For development purposes, I use <a href="https://www.npmjs.com/package/dotenv">.env</a> which is one of the most popular. It provides a capability to keep env variables in the file and load it in development mode.</p><p>Here is an example for using dotenv:</p><pre>const dotenv = require(&#39;dotenv&#39;);<br>dotenv.config();</pre><p>Where the .env file could look as follows:</p><pre>PORT=50051<br>API_URL=https://andrew.red</pre><p>Everything looks smooth and easy for development. However, for production build I don’t really want this to be loaded from a file and instead provided from env variables.</p><p>At the same moment for the local run I don’t want to do export variable=&quot;value&quot; manually multiple times.</p><p>So, I’ve just used the same .env file to load env variables into the shell:</p><pre>set -a; source .env; set +a<br>node ./index.js</pre><p>If we go deeper in attempts to understand this code, let’s see commands one by one.</p><p>Builtin set allows you to change the values of shell options and set the positional parameters.</p><p>The source command reads and executes commands from the file specified as its argument in the current shell environment. It is useful to load functions, variables, and configuration files into shell scripts.</p><p>Overall, it does the magic 🧙</p><p>Share your thoughts</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c656c810c11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to convert IPv4 and IPv6 to integer]]></title>
            <link>https://medium.com/@Andrew.Red/how-to-convert-ipv4-and-ipv6-to-integer-c2f92cdf36b9?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2f92cdf36b9</guid>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[ip2int]]></category>
            <category><![CDATA[ip2long]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 00:17:10 GMT</pubDate>
            <atom:updated>2021-11-23T00:17:10.142Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e4iwuyZp74IE3SmW4qz3HA.png" /></figure><p>Sometimes we need to convert IPv4/IPv6 to integer/decimal for storing purposes. It allows the creation of more efficient database indexes and filter values faster.</p><p>Here is how we could do it in a few lines of code in golang:</p><pre>package main<br><br>import (<br>	&quot;fmt&quot;<br>	&quot;math/big&quot;<br>	&quot;net&quot;<br>)<br><br>func Ip2Int(ip net.IP) *big.Int {<br>	i := big.NewInt(0)<br>	i.SetBytes(ip)<br>	return i<br>}<br><br>func main() {<br>	fmt.Println(Ip2Int(net.ParseIP(&quot;20.36.77.12&quot;)).String())<br>	fmt.Println(Ip2Int(net.ParseIP(&quot;2001:0db8:85a3:0000:0000:8a2e:0370:7334&quot;)).String())<br>}</pre><p><a href="https://go.dev/play/p/PGpXaPBg5p1">Play with code</a></p><p>Share your thoughts ;)</p><p>Happy coding! :rocket:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2f92cdf36b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cleaning a string in golang with Buffer and Scanner]]></title>
            <link>https://medium.com/@Andrew.Red/cleaning-a-string-in-golang-with-buffer-and-scanner-3e9834d96349?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e9834d96349</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Sat, 07 Aug 2021 18:39:10 GMT</pubDate>
            <atom:updated>2021-08-07T18:39:10.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Alt" src="https://cdn-images-1.medium.com/max/1024/0*YYipBbastsGiLEXp.png" /></figure><p>I was looking for a while for different ways of cleaning a string in Golang from listed symbols and did find anything fast. Therefore as a regular developer, I’m just reinventing a wheel.</p><p>And here is the solution:</p><pre>func ClearString(str string, symbols []string) string {<br>	scanner := bufio.NewScanner(strings.NewReader(str))<br>	scanner.Split(bufio.ScanRunes)<br>out:<br>	var buf bytes.Buffer<br>	for scanner.Scan() {<br>		t := scanner.Text()<br>		for _, s := range symbols {<br>			if s == t {<br>				continue out<br>			}<br>		}<br>		buf.WriteString(scanner.Text())<br>	}<br>	return buf.String()<br>}</pre><h4>Benchmarking</h4><pre>BenchmarkClearString<br>BenchmarkClearString-16    	  200814	      5116 ns/op	    4416 B/op	       5 allocs/op<br>PASS</pre><p>Share your thoughts 😜</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e9834d96349" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing GooseOps — a handy toolset for adopting DevOps practices]]></title>
            <link>https://medium.com/@Andrew.Red/introducing-gooseops-a-handy-toolset-for-adopting-devops-practices-83c25671e8a?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/83c25671e8a</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 14:04:27 GMT</pubDate>
            <atom:updated>2021-02-22T14:04:27.378Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="GooseOps" src="https://cdn-images-1.medium.com/max/1024/0*MVVxFiqGlEEduW1d.png" /></figure><h4>Hello World!</h4><p>Hi, I’m Andrew. For the last 10+ years, I was a developer working with multiple languages, such as C++, C#, Java, PHP, JavaScript, Node.js. Over this time I participated in different projects from garage startups to FinTech giants and banking software. For now, I’m mostly concerned about cloud computing and golang development.</p><p>I will be sharing my discoveries about Docker, Kubernetes, Terraform and using DevOps for automation build, test, deploy flows in an opensource project. So, please stay tuned!</p><h4>GooseOps</h4><p>Every time I come into a new company or start a new project, I experience the same problems about making infrastructure and CI/CD for it. That’s why I decided to create a common template, which helps us to kick off projects faster. Let’s create it here together! Most of the developers use Docker and Kubernetes in their daily tasks. Could we make it better? You never know, so let’s try!</p><p>What might we need for a DevOps project to start with?</p><ul><li>access to any cloud provider: AWS, DigitalOcean, Google Cloud.</li><li>basic understanding of Docker, Kubernetes, Terraform.</li><li>one of the commonly used CI/CD: Github Actions, Gitlab CI, Bitbucket.</li></ul><p>During the event we will cover the following topics:</p><ul><li>Starting to work with Docker for local development.</li><li>Tips to save your time with Docker.</li><li>Diving into Kubernetes, k8s annotations, kubectl tricks.</li><li>Introducing Infrastructure As Code with Terraform.</li><li>Start using Terraform to set up a private Kubernetes cluster.</li></ul><h4>Interested in giving it a try?</h4><p>The first meetup “Introducing GooseOps — a handy toolset for adopting DevOps practices” to happen on 27th February at 10:00 CET. It will be about introducing the project, in which we will overview the scope, and take a deeper dive into the technologies stack: Docker, Kubernetes, Terraform, and more.</p><p>Register now on <a href="https://www.youtube.com/watch?v=3ofIaeM4nls">Youtube</a> or <a href="https://www.eventbrite.co.uk/e/introducing-gooseops-a-handy-toolset-for-adopting-devops-practices-tickets-142214434201">Eventbrite</a>!</p><p>In short,</p><ul><li>Do you want to learn and have experience with infrastructure automation?</li><li>Do you want to participate in the open-source project, developed step by step in Agile methodology?</li><li>Do you enjoy experimenting with cool things and want to have fun writing code for the community?</li></ul><p>Then the project is for you! We’ve just started, feel free to join us on:</p><ul><li><a href="https://twitter.com/XTechnology5">Twitter</a></li><li><a href="https://youtu.be/V6naUYo1Wdk">Youtube</a></li><li><a href="https://www.eventbrite.com/organizations/info/profile/32181547901">Eventbrite</a></li><li><a href="https://t.me/xtechn">Telegram</a></li></ul><p>Of course, all <a href="https://github.com/x-technology/GooseOps">the source code is open sourced</a>.</p><p>Any feedback, contribution, or help is highly appreciated. Thanks for your time and have a nice coding!</p><figure><img alt="Emoji-Clap" src="https://cdn-images-1.medium.com/max/80/0*SC9QchiClG8-madd.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83c25671e8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Github action for adding a post to Twitter]]></title>
            <link>https://medium.com/@Andrew.Red/github-action-for-adding-a-post-to-twitter-47ef747d40cd?source=rss-8273140d8f57------2</link>
            <guid isPermaLink="false">https://medium.com/p/47ef747d40cd</guid>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[blogger]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andrew Red]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 08:29:23 GMT</pubDate>
            <atom:updated>2021-02-22T08:29:23.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABlljuthYYwt93ZmgXsOJg.png" /></figure><h4>Tweet with ease</h4><p>I’ve just published a new <a href="https://github.com/InfraWay/tweet-action">CI code snippet</a>, which helps to make a tweet directly from <a href="https://github.com/features/actions">Github Actions</a>.</p><h4>Use cases</h4><p>The good question — Why I need <a href="https://github.com/InfraWay/tweet-action">tweet-action</a>? Here are several use cases where it can be applied:</p><ul><li>blogging system, to automate the process of tweeting of new articles</li><li>release updates, when a new release (tag) is created it can tweet a news message about it</li></ul><h4>Setup steps</h4><ul><li>Register as a Twitter app developer in <a href="https://developer.twitter.com/en/apply-for-access">here</a>. Usually, it takes up to 1 week. If you already have access, go to the next step.</li><li>Create a new Twitter application in <a href="https://developer.twitter.com/en/portal/apps/new">this section</a>. Copy API key, API secret key somewhere.</li><li>At the bottom of the page, press <strong>get user tokens</strong>, and then press <strong>Access token &amp; secret for @username</strong> generate button. Copy Access token, Access token secret somewhere.</li><li>Go to the app settings section and change <strong>App permissions</strong> over there to Read and Write</li><li>Now you need to get into a Github repository</li><li>Go to the repository settings page and add secrets with previously saved keys.</li></ul><pre>TWITTER_API_KEY=&quot;API key&quot;<br>TWITTER_API_KEY_SECRET=&quot;API secret key&quot;<br>TWITTER_ACCESS_TOKEN=&quot;Access token&quot;<br>TWITTER_ACCESS_TOKEN_SECRET=&quot;Access token secret&quot;</pre><ul><li>Now is the moment to extend <a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions">Github Action yaml</a> file. Here is a quick example:</li></ul><pre>name: Tweeting from Gtihub Actions<br><br>on: push<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - uses: infraway/tweet-action@v1.0.1<br>        with:<br>          status: &quot;Hello World, delivered from Github Actions :rocket:&quot;<br>          api_key: ${{ secrets.TWITTER_API_KEY }}<br>          api_key_secret: ${{ secrets.TWITTER_API_KEY_SECRET }}<br>          access_token: ${{ secrets.TWITTER_ACCESS_TOKEN }}<br>          access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}</pre><ul><li>When the following code snippet is added, you can push anything into the repo and see the tweet delivered to Twitter.</li></ul><h4>Interested in giving it a try?</h4><p>Find more useful DevOps automation tools at:</p><ul><li><a href="https://twitter.com/mazahaco">Twitter</a></li><li><a href="https://github.com/infraway">Github</a></li></ul><p>Of course, all <a href="https://github.com/InfraWay/tweet-action">the source code is open-sourced</a>.</p><p>Any feedback, contribution, or help is highly appreciated. Thanks for your time and have a nice coding!</p><figure><img alt="Clap" src="https://cdn-images-1.medium.com/max/80/0*SMZ3rXCySpGO0HRc.png" /></figure><h4>Resources</h4><ul><li><a href="https://github.com/features/actions">Github Actions</a></li><li><a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions">Github Actions YAML configuration</a></li><li><a href="https://github.com/InfraWay/tweet-action">Tweet Action</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47ef747d40cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>