<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Difan Chen</title>
    <description>The latest articles on DEV Community by Difan Chen (@dfchen6).</description>
    <link>https://dev.to/dfchen6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F723889%2Fbc2d70fa-2fcb-43b4-80ed-372c76fc59fe.jpeg</url>
      <title>DEV Community: Difan Chen</title>
      <link>https://dev.to/dfchen6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dfchen6"/>
    <language>en</language>
    <item>
      <title>Leetcode 451. Sort Characters By Frequency</title>
      <dc:creator>Difan Chen</dc:creator>
      <pubDate>Fri, 22 Oct 2021 19:27:10 +0000</pubDate>
      <link>https://dev.to/dfchen6/leetcode-451-sort-characters-by-frequency-12m9</link>
      <guid>https://dev.to/dfchen6/leetcode-451-sort-characters-by-frequency-12m9</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/sort-characters-by-frequency/"&gt;https://leetcode.com/problems/sort-characters-by-frequency/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.&lt;/p&gt;

&lt;p&gt;Return the sorted string. If there are multiple answers, return any of them.&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;Input: s = "tree"&lt;br&gt;
Output: "eert"&lt;br&gt;
Explanation: 'e' appears twice while 'r' and 't' both appear once.&lt;br&gt;
So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public String frequencySort(String s) {
        Map&amp;lt;Character, Integer&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
        for (char ch : s.toCharArray()) {
            if (map.containsKey(ch)) {
                map.put(ch, map.get(ch) + 1);
            } else {
                map.put(ch, 1);
            }
        }
        List&amp;lt;Map.Entry&amp;lt;Character,Integer&amp;gt;&amp;gt; list = new LinkedList&amp;lt;Map.Entry&amp;lt;Character,Integer&amp;gt;&amp;gt;(map.entrySet());
        Collections.sort(list, (a, b) -&amp;gt; b.getValue() - a.getValue());
        StringBuilder sb = new StringBuilder();
        for (Map.Entry&amp;lt;Character, Integer&amp;gt; entry : list) {
            for (int i = 0; i &amp;lt; entry.getValue(); i++) {
                sb.append(entry.getKey());
            }
        }
        return sb.toString();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>leetcode</category>
    </item>
    <item>
      <title>API Gateway</title>
      <dc:creator>Difan Chen</dc:creator>
      <pubDate>Sun, 17 Oct 2021 05:49:56 +0000</pubDate>
      <link>https://dev.to/dfchen6/api-gateway-basics-56jk</link>
      <guid>https://dev.to/dfchen6/api-gateway-basics-56jk</guid>
      <description>&lt;h2&gt;
  
  
  What is API Gateway
&lt;/h2&gt;

&lt;p&gt;An API Gateway is an API management tool that sits between a client and a collection of backend services. An API gateway acts as a reverse proxy to accept all application programming interface (API) calls, aggregate the various services required to fulfill them, and return the appropriate result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why using it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction level for the clients. With microservice architecture, if you add some API services and retire others, clients can still find all your services in the same place.&lt;/li&gt;
&lt;li&gt;Protect your APIs from overuse and abuse.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What public clouds offers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://aws.amazon.com/api-gateway/"&gt;Amazon API Gateway&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RkI6ZDyw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d1.awsstatic.com/serverless/New-API-GW-Diagram.c9fc9835d2a9aa00ef90d0ddc4c6402a2536de0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RkI6ZDyw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d1.awsstatic.com/serverless/New-API-GW-Diagram.c9fc9835d2a9aa00ef90d0ddc4c6402a2536de0d.png" alt="Alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Uisng Amazon API Gateway, you can create RESTful APIs and Websockets APIs. AWS provides benefits like monitoring (integrates with &lt;a href="https://aws.amazon.com/cloudwatch/"&gt;Amazon CloudWatch&lt;/a&gt;), authentication, authorization, throttling, etc. With an API Requests price as low as $0.90 per million requests at the highest tier.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://cloud.google.com/api-gateway"&gt;GCP API Gateway&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;GCP provides API gateway service, which can create, secure and monitor APIs for Google Cloud serveless backends, including Cloud functions, Cloud Run and App Engine. Looks like the supported services behind the api gateway are still limited.&lt;/p&gt;

&lt;p&gt;The billing model is similar to AWS, which is charged by number of API calls. The price seems to be cheaper than AWS gateway though.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;API calls per month per billing account&lt;/th&gt;
&lt;th&gt;Cost per million API calls&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0-2M&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2M-1B&lt;/td&gt;
&lt;td&gt;$3.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1B+&lt;/td&gt;
&lt;td&gt;$1.50&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Open source solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://konghq.com/kong/"&gt;Kong Gateway&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Kong Gateway is the most popular open-source cloud-native API gateway built on top of a lightweight proxy. It is written in Lua running with the help of the Nginx.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://tyk.io/open-source-api-gateway/"&gt;Tyk&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Tyk is an enterprise-ready open-source API gateway. You have an option to either go for self-hosted or managed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/eolinker/goku_lite"&gt;Goku&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Goku API Gateway is an umbrella project of EOLINK Inc. It is a Golang-based microservice gateway that enables high-performance dynamic routing, service orchestration, multi-tenancy management, API access control, etc.&lt;/p&gt;

</description>
      <category>systems</category>
      <category>cloud</category>
    </item>
    <item>
      <title>[Design Pattern in Go] Proxy</title>
      <dc:creator>Difan Chen</dc:creator>
      <pubDate>Tue, 12 Oct 2021 03:00:36 +0000</pubDate>
      <link>https://dev.to/dfchen6/design-pattern-in-go-proxy-57bd</link>
      <guid>https://dev.to/dfchen6/design-pattern-in-go-proxy-57bd</guid>
      <description>&lt;h2&gt;
  
  
  What is Proxy pattern
&lt;/h2&gt;

&lt;p&gt;A proxy, in its most general form, is a class functioning as an interface to something else. A proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes.&lt;/p&gt;

&lt;h2&gt;
  
  
  When using this pattern
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The access to an object should be controlled&lt;/li&gt;
&lt;li&gt;Additional functionality should be provided when accessing an object.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example in Go
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
)

type Car interface {
    drive()
}

type Driver struct {
   age int
}

type RealCar struct {
    driver Driver
}

func (c RealCar) drive() {
   fmt.Println("I am driving!")
}

type ProxyCar struct {
    driver Driver
    car RealCar
}

func (c ProxyCar) drive() {
   if c.driver.age &amp;lt; 20 {
      fmt.Println("Too young, cannot drive")
   } else {
      c.car.drive()
   }
}

func main() {
    driver := Driver{1}
    car := ProxyCar{driver, RealCar{}}
    car.drive()

    driver = Driver{40}
        car = ProxyCar{driver, RealCar{}}
    car.drive()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://play.golang.org/p/SK10EKL_iXF"&gt;https://play.golang.org/p/SK10EKL_iXF&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>design</category>
    </item>
  </channel>
</rss>
