<?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 Eden Chen on Medium]]></title>
        <description><![CDATA[Stories by Eden Chen on Medium]]></description>
        <link>https://medium.com/@dacozai?source=rss-c599ee183cd6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ob4BWb3OwwFJCviyL6swhw.jpeg</url>
            <title>Stories by Eden Chen on Medium</title>
            <link>https://medium.com/@dacozai?source=rss-c599ee183cd6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:36:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dacozai/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[Tips for F1 Fans about my first-time Singapore Grand Prix]]></title>
            <link>https://dacozai.medium.com/tips-for-f1-fans-about-my-first-time-singapore-grand-prix-3f647e965681?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f647e965681</guid>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[experience-sharing]]></category>
            <category><![CDATA[f1]]></category>
            <category><![CDATA[singapore-grand-prix]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Tue, 24 Sep 2024 12:15:04 GMT</pubDate>
            <atom:updated>2024-09-24T12:15:04.390Z</atom:updated>
            <content:encoded><![CDATA[<p>I attended the 2024 Singapore Grand Prix with a three-day ticket, and it was my first time at an F1 race event. For those considering attending, I would like to share some insights structured into the following sections: Reflections, Must Bring, Optional Bring, and Event Tips.<br>By the way, I only attended the Track and Fans events in Zones 1 and 2. So, if you’re looking for information on music events, this article may not be for you. My apologies!</p><h3>Reflectins</h3><p>It’s my first time attending an F1 event, and it’s awesome! Although the race was a bit tedious this year, the atmosphere never let me down. <strong>During FP2, when I first smelled the scorched metal and plastic along with the roaring engines, I was blown away — these are sensations you can never experience through TV! </strong>So, please allow me to lure you to participate in this event!!!</p><h3>MUST Bring</h3><ol><li><strong>Power bank</strong><br>This is very important because you will have Location Services (and possibly 5G) turned on all the time. As a result, your phone battery will drain quickly. <br>If you have your ticket stored on your phone, this is crucial as <strong>you will need to show your ticket every time you enter and exit the venue</strong>.</li><li><strong>Singapore GP app</strong><br>This app is incredibly helpful for staying engaged during the event. Besides F1 racing, there are many other activities happening in and around the track. You can also upload your ticket to the app, so you won’t need to carry a physical copy — just make sure to bring a power bank for your phone!</li><li><strong>Umbrella/ raincoat(depends)</strong><br>Bring an umbrella, but only use it when necessary. You might be tempted to arrive early to secure specific spots around the track. However, if it starts raining, wear a raincoat instead — using an umbrella will block others’ view of the race, and people won’t appreciate it.</li></ol><h3>OPTIONAL Bring</h3><ol><li><strong>backpack</strong><br>People don’t mind carrying things in their hands, but given the essential items, it’s difficult to bring everything without a backpack. Ultimately, it’s your choice — if my suggestions don’t resonate with you, feel free to carry as little as possible. Just keep in mind that it will be extremely crowded, especially on race day!</li><li><strong>sunglasses</strong><br>The sunlight is very strong, so it’s a good idea to bring sunglasses to protect your eyes.</li><li><strong>your own bottle</strong><br>There are many vendors and water dispensers around the track. If you don’t mind spending money on water, feel free — it’s 5 SGD per bottle in 2024.</li></ol><h3>Events</h3><h4>FansForum</h4><p>This event takes place from around 3:50 to 4:20, and all the drivers will make an appearance. I was lucky to be i<strong>n the front 10 rows</strong>. <strong>I arrived at the Wharf Stage at 1:50</strong>, which I think is a good reference for when you should get there. If you’re around 160 cm tall, like my girlfriend, it might be a bit challenging to record videos, but you’ll still be able to enjoy the event.</p><p><strong>Be sure to prepare a large sign for your favourite driver — make it as big and funny as possible so they can see it!</strong></p><h4>Which hot spots to stand?</h4><p>I bought a ticket at turn 5 and, in the end, I did not sit there. So … buying a ticket is another thing that you have to think harder. Anyway, I will show you the best locations for you and explain why for the premier walkabout.</p><h4>Turn 1 to 3</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xMf4wEaMfVHeAf5OJfPicg.png" /></figure><p>The best viewing spots (ranked 1: best, 2: nice, 3: okay) will already be crowded by around 15:00. So, I suggest getting there earlier than 15:00. This location is elevated compared to others, giving you a better view.</p><p>Why is this spot great? Typically, the SG GP sees the most position changes during the first three turns of the first lap, which happens right here. Additionally, the pit exit is next to location 3, so you’ll be able to see and record any undercut manoeuvres as they occur.</p><h4>Turn 18 and 19</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yNBdKRHZ7POhLgnje6A3dg.png" /></figure><p>Location 1 is extremely hot, so I didn’t try to go there. Before 18:00, there’s a long straight where some car accidents tend to happen. Aside from that, you can also see the champion’s celebration with fireworks from here!<br>This year(2024), we even had a surprise with a <a href="https://x.com/F1/status/1837586791500591529">lizard alert</a> at this spot! 😂</p><p>Location 2 is a great spot to take close-up photos of the cars as they slow down for Turn 18 or enter the pit. Plus, you can even catch the distinct smell of scorched metal and plastic!</p><h4>In front of Paddock</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BTwNTy5_nLmQpIwEEAzWig.png" /></figure><p>Locations 1 and 2 are similar, but Location 1 is slightly better. Let me explain in reverse:</p><p>At Location 2, you’re near Turns 18–19, where you can also see the fireworks and top-tier pit stop operations.</p><p>Location 1 offers a similar view, but you’ll mostly see pit work from less competitive teams. However, if you’re interested in joining the post-race run to the podium, Location 1 is ideal as it’s right next to the gate.</p><h4>Running to Podium</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5M9nLOcB6gI0JA1ob6bHFg.png" /></figure><p>If you’re interested in running to the podium, this is the spot for you! While you can also access the podium from Turns 18–19, it opens much later than here.</p><p><strong>I arrived one lap before the race ended and managed to be in the front 10 rows</strong> (maybe it was fate? 😁). However, my friends told me they went to the podium after the race by starting at Turn 2, crossing the bridge, and cutting through many bushes. When they arrive, the podium ceremony is over. Again, this is a strong reference for you I reckon.</p><p>Alright, that’s all the stuff that IU can share with you. Let me know if anything you want to know. If I can help, I will answer you and then update this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f647e965681" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust Application Boilerplate]]></title>
            <link>https://dacozai.medium.com/rust-application-boilerplate-37fb02c95f2?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/37fb02c95f2</guid>
            <category><![CDATA[boilerplate]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[actix-web]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 13:55:32 GMT</pubDate>
            <atom:updated>2022-12-20T13:55:32.556Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to share how to use <strong>Rust</strong> to build a moderately structured application through <strong>Actix</strong>.</p><p>First of all, I want to introduce my design spirit. First, every project starts simple and wants to ace to catch eyeballs. Based on this assumption, I fancy the MVC design more than others. This is the reason that I build this boilerplate for you <strong>to build your concept/ logic quickly</strong>. In my opinion, when it comes to that complex/ big application, it is not a call for just one person, at least, in my career life.</p><p>The pure backend does not have View, so I’d say the router is the V to us. But, yes, it’s different. <strong>I don’t want to write any explanation on Rust mechanism or crates because I just learn to write Rust</strong>. I believe others would explain far better than I do. Or please study Rust&#39;s official cookbook <a href="https://doc.rust-lang.org/rust-by-example/index.html">CLICK_ME</a>.</p><blockquote><em>I will explain what I consider and feel free to disagree with me and then make it better. Please do let me know and learn from you thanks 😊 🙏<br>My design spirit focuses on readability 😎</em></blockquote><p><a href="https://github.com/dacozai/rust_boilerplate">GitHub - dacozai/rust_boilerplate</a></p><h3>Folder Structure Explanation</h3><h4>src/cfg/</h4><p>put configuration setting here</p><p>FAQs<br><strong>1. why not env?</strong><br>I don’t like to use env because I <strong>already store tons of env vars</strong> and alias for operations. Therefore, I don’t want to store more applications related which gets me confused. Secondly, I want the env could be used directly through the developer. The other frequently used practice is to store env vars through configmap in Kubernetes but it is not straightforward for developers. What’s worse, it creates <strong>communication costs</strong>. <br><strong>2. why toml? </strong><br>toml structures the <strong>readability</strong> although in this demo I use a very simple style. Please read config-rs doc and you will understand.</p><h4>src/db</h4><p>just put database-related functionalities inside this folder</p><p>FAQs<br>1. why <strong>singleton</strong><br>I think the best DB handler, in a small app, is the singleton design. It is straightforward and <strong>easy</strong> to understand. Once people get to understand what lazy_static means, they know how to write their app.</p><h4>src/err</h4><p>To be honest, this part I did not design that much. But it is obvious you should all err related info/ constants/ variables in this folder. I will improve this folder but might not update this project for you. Please let me apologise to you in advance 😔</p><h4>src/middleware</h4><p>put middleware. The greeting middleware is the demo version to let you copy-paste if you want to do other kinds of middleware.</p><p>FAQs<br>1. why one layer?<br><strong>Readability</strong></p><h4>src/pkg</h4><p>This folder contains the third-party library/ services. One point for this pkg folder is that everything here is independent. They don’t rely on others for initialisation.</p><h4>src/internal</h4><p>This folder also contains the third-party library/ services. I did not put this folder into the project but I will. Good guess! The difference between internal and pkg is dependencies. internal will rely on others such as pkg/ internals. Distinguishing is important when your project reaches a certain level.</p><h4>src/router</h4><p>this is obvious that all router functions are put inside that folder.</p><p>FAQs<br>1. the purpose of the router function?<br>I usually handle request logic and re-format arguments for our business logic here. Lastly, the final error verification and checking should be done here.</p><h4>src/service</h4><p>business logics. YES! Here is the dirty location that you are seeking. I like to handle everything in the controller and let the router and model become really simple 😳</p><p><strong>FAQs<br></strong>1. why?<br>Normally, when we write business logic, we want everything to be in our hands. I don’t want to switch to other folders to find some logic in somewhere. I want <strong>everything</strong> to be <strong>here</strong>. Besides, anything related to business logic will change frequently so it is highly likely that this folder will become a mess. Therefore, to me, it is <strong>pointless to optimise in the early stage</strong>.</p><p>Other files and folders are typical Rust folder structures so please read Rust book you will understand it 👌🏻</p><p><strong>FAQs<br></strong>1. WAIT! why add lib.rs?<br>In lib.rs, I import all mods and separate main.rs. By doing so, main.rs could focus on its logic instead of increasing tons of lines for adding mods, which is not readable to me. Because … I am lazy to scroll down 😏✌🏻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37fb02c95f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build Prefect for Work Orchestration]]></title>
            <link>https://blog.devgenius.io/how-to-build-prefect-for-work-orchestration-1d824bd7893f?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d824bd7893f</guid>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[prefect]]></category>
            <category><![CDATA[gke]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 08:58:36 GMT</pubDate>
            <atom:updated>2022-11-17T08:54:19.246Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the 101 tutorial for people who wants to use the following spec<br>1. GCP<br>2. Prefect 2.6.5<br>3. dbt 1.3.9</p><p>I find the GCP+Prefect2.0 tutorial is relatively few. Therefore, I’d like to write the Guideline here. Please visit <a href="https://github.com/dacozai/demo-gcp-prefect-dbt">GithubRepo</a></p><p><strong>Please create a google account with the free trial for 300USD provided by GCP. Then, you don’t need to worry about receiving bills. </strong>And, YES, I am using this free tier to survey this infra. This is the purpose of this tutorial.</p><blockquote><strong><em>Goal: help people to use this tutorial for their GCP PoC to decide whether they should use Prefect or not</em></strong></blockquote><h3>Step 1 create Prefect workspace and login</h3><p>Please login to Prefect Cloud <a href="https://app.prefect.cloud/">HERE</a> <br><strong>As Prefect </strong><a href="https://medium.com/the-prefect-blog/modular-data-stack-build-a-data-platform-with-prefect-dbt-and-snowflake-part-2-cf753708a19e"><strong>promised</strong></a><strong>, we don’t need to set up a credit card here.</strong> Therefore, no bills here. After going through the tutorial, I believe you will understand how to build Orion on your own. BUT, I will not demo this part.</p><ol><li>create a workspace called demo</li><li>Then, fill up the commands below then copy &amp; paste &amp; enter 🙌</li></ol><pre>API_KEY=[please_fill_your_api_token]<br>YOUR_ACCOUNT=[please_fill_your_account]<br>WORKSPACE=demo<br># EXAMPLE<br># API_KEY=pnu_AAq8ZJvEfzXIspHxsYha1hn6BJTXKc1DX75q [No worries it is deprecated]<br># YOUR_ACCOUNT=edenhiveventuresio<br># WORKSPACE=demo<br><br>prefect profile create demo<br>prefect profile use demo<br>prefect config set PREFECT_LOGGING_LEVEL=DEBUG<br>prefect config set PREFECT_API_KEY=$API_KEY<br>prefect cloud workspace set --workspace &quot;${YOUR_ACCOUNT}/${WORKSPACE}&quot;</pre><p><strong>CHECK_POINT</strong><br>Please execute hello.py to see if the setting is correct.<br>There are two places to check whether it works or not.<br>1. Your terminal. You should be able to see 👋 on your terminal<br>2. Click Flow Runs you can see foo/xxxxx <strong>completed</strong></p><h3>Step 2 create GKE cluster</h3><h4>Create a service account</h4><p>I create one called prefect-demo <br>Grant the following permission to the service account.<br>1. Workload Identity User<br>2. BigQuery Admin<br>3. Storage Admin<br>Note. <strong>2 and 3 is very dangerous settings</strong>. I set the service account as admin level because it is easier to write the 101 tutorial. Otherwise, it will cost me more time on this tutorial 😫 Please DOmodify them after the demo to follow <strong>the principle of least privilege (PoLP)</strong> addressed <a href="https://cloud.google.com/iam/docs/using-iam-securely#least_privilege">HERE</a>.</p><h4>Create GKE cluster</h4><p>1. select standard [if you wish, you could use autopilot. It’s just about the expense 😅] -&gt; click configure<br>2. use name — demo <br>3. left-hand side click default-pool -&gt; nodes -&gt; select n1-standard-1 as the machine type.<br>4. cluster/ecurity -&gt; <strong>enable the workload identity</strong></p><pre># Please fill your information below<br>CLUSTER_NAME=demo<br>COMPUTE_REGION=us-central1-c<br>PROJECT_ID=[======== YOUR_PROJECT_ID ========] <br># ex. PROJECT_ID=abcd-1234567<br>NODEPOOL_NAME=default-pool<br>SVC_ACCOUNT_NAME=prefect-demo<br>NAMESPACE=example<br><br># IF YOU FORGET to enable workload identity, PLEASE use the commands below<br># Please stick with me!<br># <br># # setup workload identity and its pool<br># gcloud container clusters update $CLUSTER_NAME \<br>#     --region=$COMPUTE_REGION \<br>#     --workload-pool=$PROJECT_ID.svc.id.goog<br># # GKE metadata for the node pool<br># gcloud container node-pools update $NODEPOOL_NAME \<br>#     --cluster=$CLUSTER_NAME \<br>#     --region=$COMPUTE_REGION \<br>#     --workload-metadata=GKE_METADATA<br><br>gcloud iam service-accounts add-iam-policy-binding \<br> $SVC_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \<br> --role roles/iam.workloadIdentityUser \<br> --member &quot;serviceAccount:${PROJECT_ID}.svc.id.goog[${NAMESPACE}/${SVC_ACCOUNT_NAME}]&quot;<br><br># DON&#39;T WORRY about k8s annotation<br># This will be set while creating our deployment</pre><p><strong>CHECK_POINT</strong></p><pre># first connect to your GKE cluster<br>gcloud container clusters get-credentials $CLUSTER_NAME \<br>  --zone $COMPUTE_REGION --project $PROJECT_ID<br><br>kubectl create ns example<br>#&gt;&gt;&gt; namespace/example created</pre><h3>Step 3 create the Prefect agent for our k8s</h3><p>If you want to do this on your own, please have a look at Prefect helm in <a href="https://github.com/PrefectHQ/prefect-helm">here</a>. If you want to do Kustomize, please follow me.</p><pre>prefect kubernetes manifest agent</pre><p>Then, copy-paste the deploymentoutput into the deployment.yaml. If you don’t know k8s, I would suggest you understand k8s first. This tutorial assumes that people, at least, know how to operate k8s.<br>Remember that we will demo in the namespace example which was created by us before. Then fill up the following command lines from deployment.yaml in spec.template.spec.env</p><h4>optional</h4><pre>PREFECT_API_URL=https://app.prefect.cloud/api/accounts/583890cb-6790-47ac-9989-1bc8edc6a0ba/workspace/d8f7d359-21bb-42f5-b3a1-215d4e03e531<br>PREFECT_API_KEY=pnu_AAq8ZJvEfzXIspHxsYha1hn6BJTXKc1DX75q<br>kubectl create secret generic mysecret \<br>  --from-literal=PREFECT_API_URL=$PREFECT_API_URL \<br>  --from-literal=PREFECT_API_KEY=$API_KEY \<br>  -n example --dry-run=client -o yaml</pre><p>😏 Please copy-paste the output directly into secret.yaml <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/secret#using_a_secret">REFERENCE</a><br>Note. This demo will not use secret here.</p><p><strong>CHECK_POINT</strong><br>NOW it is the exciting PART. If you set it all correctly, you could see kubernetes in Work Queues tab on Prefect.</p><h3>Step 4 create an image for Container Registry</h3><p>Please follow the guideline <a href="https://cloud.google.com/container-registry/docs/quickstart#before-you-begin">here</a> for the pre-requisite. Use the below commands to create images for GCR image.</p><pre>docker build -t gcr.io/$PROJECT_ID/prefect_gcp_demo .<br>docker push gcr.io/$PROJECT_ID/prefect_gcp_demo</pre><p>Make sure the image has been put into the Container Registry tab</p><h3>Step 5 Check up on our worker</h3><p>This is a section to check whether our workers could work with Prefect Cloud properly. But, theoretically, it should work.<br>1. time to create the required blocks for running our worker 😃 Please run create_blocks.py <br>[<strong>NOTE</strong>] do change anything you like especially the GCS bucket name!!!<br>2. create a deployment for an agent to execute</p><pre>prefect deployment build hello.py:foo -q kubernetes \<br>  -n &quot;demo-test&quot; -sb gcs/demo -ib kubernetes-job/kk -a</pre><p>Go to the Deployment panel to click a run</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftQNLWFL019EXLwrIygzXQ.png" /></figure><p>And then you can see the job is executed through either website/k9s or other k8s monitor interfaces.</p><h3>Step 6 download dbt demo repo — jaffle_shop</h3><p>I put jaffle_shop<em> </em>directly into the GitHub <a href="https://github.com/dacozai/demo-gcp-prefect-dbt">repository</a>. I think it is better to understand dbt how to set up the profiles.yml <br>Therefore, please replace the project by your PROJECT_ID</p><p>To check your dbt is working, please get into the folder <strong>dbt-jaffle-shop </strong>place dbt seed . If your dbt setting works, you can see three tables created in your Bigquery</p><p>After that, we want to verify whether your service account could work for Prefect and GCP.</p><pre>prefect deployment build dbt_build.py:dbt_build -q kubernetes \                                              ✔  data <br>  -n &quot;dbt-build-test&quot; -sb gcs/demo -ib kubernetes-job/kk -a</pre><p>Then, go to the deployment to trigger this flow runs manually.</p><p>If it does!!! Congratulation!!! Have fun with Prefect/dbt and our old friend — GKE 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d824bd7893f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-build-prefect-for-work-orchestration-1d824bd7893f">How to build Prefect for Work Orchestration</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCP Workload Identity Federation]]></title>
            <link>https://dacozai.medium.com/gcp-workload-identity-federation-51583bf71810?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/51583bf71810</guid>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Sun, 23 Oct 2022 06:28:41 GMT</pubDate>
            <atom:updated>2022-10-23T06:42:35.996Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>這邊想分享一下 <a href="https://cloud.google.com/iam/docs/workload-identity-federation">Workload Identity Federation</a> 的做法, 這個功能 GCP 在2020年9月推出[<a href="https://cloud.google.com/iam/docs/release-notes#September_21_2020">reference</a>] 之前, 沒有注意到過, 但最近用完了之後, 真心覺得是個好東西. 而 Github workflow OpenID Connection(<a href="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect">OIDC</a>) 的部分則是到 2021年10月推出[<a href="https://github.blog/changelog/label/oidc/">reference</a>]</p><h3>Scenarios</h3><p>簡單講一下情境, <strong>我們想要利用 GithubActions 來做 CI, 但是 CI 會需要去拿 Workload Identity 來去 access GCP 上面的資源</strong>. 那過去的作法基本上就是會產生 key.json. 生產出來 key file 就產生了以下兩個問題 😱 : <br>1. <strong>管理問題</strong>: 產生了一堆 key files, 我不知道用了哪些以及哪些 key files 又該去哪裡 🤔<br>2. <strong>資訊安全問題</strong>: 如果有人一起加入, 這總是會給出去. 那我們做的 service account 就又會產生風險. 又得面臨重新生產 keys 😫<br>[<a href="https://cloud.google.com/iam/docs/workload-identity-federation#why">Why Workload Identity Federation Reference</a>]</p><p>那這邊就不去講原理了, 直接進入簡單的作法, 我認為, 文件是很詳盡了. 但這邊還是提供手把手教學給各位看官. 原理的部分大家可以在上述的 references 裡面找到.</p><h3>How to Implement?</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f59479a67609ae2f30abb19f10ae63b4/href">https://medium.com/media/f59479a67609ae2f30abb19f10ae63b4/href</a></iframe><p>最後, 我們需要在你的 workflow 裡面使用以下, 我這邊使用 GithubActions 為例子. 看到上面第63行的部分. 請將該輸出以及您的 service account貼到後面 workflow.yaml 裏面.</p><pre>projects/123456789098/locations/global/workloadIdentityPools/agent-pool/providers/agent-pool-provider</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc12dc5f59ec47cdb88b547a2a30c11e/href">https://medium.com/media/dc12dc5f59ec47cdb88b547a2a30c11e/href</a></iframe><p>好基本上, 這邊就完成了!!! 非常快速簡單 😲, 而且也不需要再次產生 key file 更不用面臨可能要傳什麼 key file 的問題. 完全沒有煩惱了 😋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51583bf71810" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I learnt from The Midnight Library]]></title>
            <link>https://dacozai.medium.com/what-i-learnt-from-the-midnight-library-3cd57a7b1115?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cd57a7b1115</guid>
            <category><![CDATA[book-review-writing]]></category>
            <category><![CDATA[the-midnight-library]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 13:03:34 GMT</pubDate>
            <atom:updated>2022-09-27T13:09:38.968Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>This is what I learnt and reflect on myself after reading The Midnight Library. This article is not an actual review of the book. Instead, I focused more on some prevalent problems that I encountered. Some thoughts might sabotage your thinking for reading this masterpiece — The Midnight Library. Therefore, before diving into my review, I highly suggest people read the book first 😏</p><p>There are three significant questions that I’d like to discuss</p><ol><li>Why should I live?</li><li>What’s the point of connection?</li><li>What should I do for the future?</li></ol><p>To be honest, these three questions haunt me. I think the last question troubles everyone or probably any living creatures. But it might vary in my opinion and I put it to the last one on purpose. Like the book, the main character learns how to do, in terms of the last question, in the last few chapters. So do I.</p><h3><strong>Summary</strong></h3><p>Nora tried to kill herself and then she found that she could try other possible lives. After that, she did then she found the answer in the end. I know this is crap and I know the ending is very sure. Even if I don&#39;t need to read the book, I probably can infer the possible outcomes of this book. It is tedious but meaningful just like ourselves. Life.</p><p>The best part is the journey itself instead of the destination. I know this is commonplace to argue that we always want the ideal results instead of failures.</p><p>Somehow, we know we have to try. We know we should try with something at stake so that we can succeed in something. But, if we don’t walk through the path, how do we know, in the end, what our lives will look like? We don’t.</p><p>Regret is the first and foremost force that prompts us to do the next moves or do the daydreams at least. This is the first connection for Nora to find other lives. So do we. Because something happened, we want to make some changes. How cliche this could go far away? Then, please try to answer the first question — Why should I live?</p><h3>Why should I live?</h3><p>To me, there is no point to live, trust me, only when we have any motivation. We have no choice but to be brought into the world and then we probably put the blame on our parents. After growing up, people would say we have to pay back to parents. But, what if there is no need? We simply want to go back to where we are. I don’t know where but not this world for sure. To this world, this act means dead, for sure again.</p><p>From the perspective of Physics, we have to live hard and then die hard. Let me elaborate on how this journey will go.</p><ol><li>Learn many things — <strong>to take part in the world</strong></li><li>Study and try very hard to compete with others as they are doing the same things —<strong> to become so-called successful</strong></li><li>Doing exercises — <strong>to avoid illness as we tried too hard for work</strong></li><li>die in peace</li></ol><p>In the beginning, we don’t have any energy so we have to try very hard to become no energy in the end. Based on what John Nash said, how about jumping to the result if we already know the result? What’s the point of the process?</p><p>Yes. At the end of the story, Nora did find — love. Whatever they come from, first, of course, is from our parents. I shall contend that is a selfish love but it is still love. It might be from different angles so that we could follow and try to find our purposes. It does not necessary to be loving people. I could love so many things based on my interests and curiosities. This is the main motivation for me at least in this world.</p><p>It is so true that without love we barely live. In the book, Nora felt that also and even if she reaches some achievements in some areas, she was still overwhelmed by the hollow/sorrow.</p><p>But why would we play this role just because we are alive? To be honest, I don’t know and this probably is another greater Will behind the scene and I don’t want to dig into it because neither could I prove it nor could I get closer to it. Let it go I suppose. At this point, I only know if I am triggered by the greater Will, I should follow love as the path track to finish my life. I consider this as an action. Curiosity is the main force to prompt us to live.</p><p>Quoted in the book,</p><blockquote>Curiosity and passion are the enemies of anxiety. Even when I fell into anxiety, if I get curious enough about something outside of me it can help pull me out. Music, art, film, nature, conversation, words. Find passion as large as your fear. The way out of your mind is via the world.</blockquote><h3>What’s the point of connection?</h3><p>I’d jump right into the conclusion of the connection — love because it is an obvious answer. As the book said, we have to find some strengths or we could probably go die. There is no correct answer. But if we are still alive, we are either loving something or being loved. Besides, this answer is easy to reach but very hard to understand during the journey.</p><p>Suppose that we are a simple force born in the world, we must find the path to release this force. Direction? Where to? It is no doubt that we have to find motivations or what we love/ are interested in, to be more specific. It is indeed subtle like Nora. Only when we lost something, we would say that I am so regretful that I should’ve done something blah blah blah.</p><p>The regrets of the book.</p><p>It is obvious that we already unconsciously follow something that we treasure and we did not notice until we lost it.</p><blockquote>Never underestimate the big importance of small things</blockquote><p>But, it is obvious that we possibly know what to do already. However, we often merely stand near the river instead of jumping into it — Way of the peaceful warrior; The only way to learn is to live! If we have to go on, we must find what we love in the future, which makes the connection from the past to the future. To me, this is a life-long question. It varies over time because we are making the progress. This is why. I am not afraid of not changing my mind. Instead, I worry I don’t change. It does not have to change what we want to do entirely but change what we think that we should do in certain ways.</p><p>It is an easy question for people to say that they want to become a doctor, an athlete and so on. We want to serve something in concrete so that we can set goals clearly. However, we are complex … The story does not narrate solely how the warrior kills the dragon. Otherwise, it is a truly boring story. We always find that we want to do something conceptually. But, yes, some people have a very clear path and they get stuck at some points I could not imagine. Therefore, it is off-topic here. But, I believe many more people will get stuck at the point like I do. Sometimes, it is not a job or an identity that could simply achieve. Then, it becomes the most difficult part of life. However, it sure does be the most challenging one because we have to try again and again. The analogue in the story says below.</p><blockquote>At the beginning of a game, there are no variations. There is only one way to set up a board. There are nine million variations after the six moves. And after eight moves there are two hundred and eighty-eight billion different positions. And those possibilities keep growing. There are more possible ways to play a game of chess than the amount of atoms in the observable universe. So it gets very messy. And there is no right way to play; there are many ways. In chess, as in life, possibility is the basis of everything. Every hope, every dream, every regret, every moment of living.</blockquote><p>Compared to life, we are all the same at some points. After that, we will gain/lose. The fascinating part to me is that the more we lose the more possibilities we can have in the future. Isn’t that fascinating? How broad and how deep our life tree could grow. I think this is the key to reflecting on myself.</p><p>Last question.</p><h3>What should I do</h3><p>This is the most common problem in our lives. And, from the book, I kind of understand that we need to create our path through …</p><blockquote>The only way to learn is to live</blockquote><p>To me, this sentence represents the gist of the story where Mrs Elem answered Nora. In the end, we still have to try our choice with certain risks. This is an interesting part to me also. As I remember, we will listen to so much advice from so many people from young to old, but we still have to make our own choice. Fortunately, the possibility is infinite! Remember that, your life contains infinite possibilities unless you give it all up.</p><p>Damn. What should I do? The only way to learn is to live. Somehow I just never learn only when I lived. How should we carve the pain and the underwent onto our bones so that we could finally understand what to give it up and what to take all in?</p><p>I don’t know. I think no one knows. But, I think I would just live and make sure that I am doing what I love/ helping who I love. This is the only attitude that we could show. And, the only way to learn is to live.</p><p>Don’t ask. Just enjoy the journey of our lives.</p><h3>Conclusion</h3><p>Don’t bother why living … So far I know some people love me and I love someone/ something. I think this gives me enough brave to continue my journey. Easy to say follow what I love but practise minutely.</p><p>Lastly, don’t hesitate to think about it too much. It’s true that we have to think and plan but REMEMBER, the only way to learn is to live. I think this is the same thing if we are eager to see the future behind the door, we should open the door on our own.</p><h3>Take Away</h3><ol><li>Don’t be afraid to lose, the more you lose the more possibilities you can create</li><li>Your love will lead your path to the answer of your life</li><li>The only way to learn is to live</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cd57a7b1115" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Go] 1. Basic — array and slice]]></title>
            <link>https://dacozai.medium.com/go-1-basic-array-and-slice-afcaf8d27b13?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/afcaf8d27b13</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[slice]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Sun, 14 Feb 2021 07:53:24 GMT</pubDate>
            <atom:updated>2021-02-14T07:54:29.982Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Go] Basic — Array and Slice</h3><h3>Motivation</h3><p>In the beginning, I don’t want to write this article because there are lots of articles to do this. However, I find it’s difficult to gather all information I like so I think it is a good start to write my own notes here.</p><p>The more I write Go the more I like this language though I love Rust and C++ as well. However, Go is more like Python to me because I could use it to prove something quicker than Rust or C++. I think, in the future, I will focus more on Rust … or not. Anyway, let’s get started, shall we?</p><p>Last but not least, my mother language is not English. Therefore, I would like to push myself to write articles. As far as I know, writing an article is one of the best ways not only to refine your thinking but also to offer a better view of language learning.</p><h3>Intro</h3><p>Array is the most common data structure. Hence, I think this is a cliche to introduce more here. However, Go has two array like structures which are <strong>array</strong> and <strong>slice</strong>.</p><h3>Array</h3><p>Speaking of Array, I believe everyone knows that array with the fixed length in C/C++. Hence, the array is <strong>with the fixed size. </strong>You always have to declare the length in advance.</p><pre>//Go<br>var a [10]int<br>// [0 0 0 0 0 0 0 0 0 0]</pre><pre>b := [10]int{1, 2, 3}<br>// [1 2 3 0 0 0 0 0 0 0]</pre><pre>c := [...]int{1, 2, 3}<br>// [1 2 3]</pre><p>There are three hints here</p><ol><li>Once declaring like this format, you would never implement append to achieve dynamic length like Slice, i.e. the fixed length.</li><li>After declaring the length of the array, it will be filled up zeros.</li><li>If we want to dynamically declare the array without knowing its length, we could simple use [...] . I believe every Gopher understands this trick very much, since it is more useful as an argument way.</li></ol><p>Besides, it is important to note that the variable denotes the entire array instead of a pointer like C/C++.</p><h3>Slice</h3><p>It is obvious that slice is dynamic size for this container. Therefore, we could use append to manipulate its size.</p><pre>a := make([]int, 10, 10)<br>b := make([]int, 10)<br>c := []int{}<br>d := []int{1, 2, 3}</pre><p>As you can see, if you want to change your length of the Slice, you could do below.</p><pre>arr := make([]int, 3, 3)<br>// [0,0,0]<br>arr = append(arr, 0)<br>// [0,0,0,0]<br>arr = []int{1,2,3}<br>// [1,2,3,4]</pre><pre>indx := 1<br>copy(arr[indx:], arr[indx+1:])<br>// [1,3,4,4]<br>arr = arr[:len(arr)-1]<br>// [1,3,4]</pre><p>I use the capacity way to declare a slice because I am eager to demonstrate that <strong>it is OK to change the size of the length of the slice with the capacity announcement</strong>.</p><p>Why?</p><p>Slice is a struct with array container like below. You can find the source code <a href="https://github.com/golang/go/blob/41d8e61a6b9d8f9db912626eb2bbc535e929fefc/src/reflect/value.go#L1994">HERE</a>.</p><pre>type SliceHeader struct {<br>  Data uintptr<br>  Len  int<br>  Cap  int<br>} </pre><p>Slice simply is a reference to an array. It is addressed in this <a href="https://medium.com/rungo/the-anatomy-of-slices-in-go-6450e3bb2b94">article</a>. Besides that, append is a <a href="https://gobyexample.com/variadic-functions">variadic function</a>.</p><p>Later, I will collect something from this <a href="https://medium.com/rungo/the-anatomy-of-slices-in-go-6450e3bb2b94">article</a> that I think it is important to address Slice. We, then, jump into the comparison.</p><h4>Danger cases (go1.15.7 &amp;&amp; go1.13.5)</h4><pre>var a [4]int = {1,2,3,4}<br>// a = [1,2,3,4]</pre><pre>s := a[1,3]<br>// s = [2,3]</pre><pre>// [Case 1]<br>s = append(s, 5)<br>// s = [2,3,5]<br>// a = [1,2,3,5]</pre><pre>// [Case 2]<br>a[3] = 4<br>s = a[1,3]<br>ss := append(s, 5)<br>// ss = [2,3,5]<br>// s  = [2,3]<br>// a  = [1,2,3,5]</pre><p>Additionally, it is very important to note that Slice is passed-by-value because struct is passed-by-value! However, the mechanism in Slice is actually passed-by-reference. Ergo, you will find the side effect to Slice!</p><pre>type TestSturct struct {<br>  Num int<br>}</pre><pre>a := [4]int{1,2,3,4}<br>s := a[1:3]<br>test(s)<br>// a = [1,100,3,4]<br>// s = [1,100]</pre><pre>func test(s []int) {<br>  s[1] = 100<br>  // s = [1, 100]<br>}</pre><pre>-------</pre><pre>ts := TestSturct{<br>  Num: 0,<br>}<br>// ts = {0}</pre><pre>testS(ts)<br>// ts = {0}</pre><pre>func testS(ts Hey) {<br>  ts.Yo = 100<br>  // ts = {100}<br>}</pre><h3>Performance</h3><p>I think it is intuitive to say that append is expensive! Obviously, it is a reference from an array. Therefore, we could not dodge from announce an array first. I will adopt the same testing as this <a href="https://medium.com/vendasta/golang-the-time-complexity-of-append-2177dcfb6bad">article</a> did but I am eager to find out more in Capacity. The size will be 1 &lt;&lt; 10</p><p>The result is similar to the previous testing.</p><pre>Append-8          340434   3426 ns/op   16376 B/op   11 allocs/op<br>AppendCapSame-8   757402   1649 ns/op   8192 B/op    1 allocs/op<br>Make-8            753012   1683 ns/op   8192 B/op    1 allocs/op<br>MakeCap-8         139573   8452 ns/op   81920 B/op   1 allocs/op<br>MakeCapSame-8     727317   1672 ns/op   8192 B/op    1 allocs/op</pre><p>As you can see, append is quit expensive process! You definitely wonder what is inside MakeCap . I declare that the capacity with 1 &lt;&lt; 11 . So, it is straightforward that I declare the capacity that is same as the length of the array in MakeCapSame</p><p>In the column of The total number of memory allocations, the last column, we could understand that with the assign method will do the allocation less than simple append However, I have the other case is below</p><pre>func AppendCapSame() {<br>  s := make([]int,0,size)<br>  for i := 0; i &lt; size; i++ {<br>    s = append(s, i)<br>  }<br>  _ = s<br>}</pre><h3>Conclusion</h3><p>The above is all notes about array and slice to me. But, I learn that it is possible to use assign than append, which is of course conclusion. BUT, even if we don’t know the length of the incoming data. We could guess through make with the capacity. Then, we could be benefited from the faster allocation as well!</p><h3>References</h3><ol><li><a href="https://blog.golang.org/slices">The mechanism of append</a></li><li><a href="https://blog.golang.org/slices-intro">Go Slice introduction</a></li><li><a href="https://www.godesignpatterns.com/2014/05/arrays-vs-slices.html">Arrays VS Slices</a></li><li><a href="https://yourbasic.org/golang/delete-element-slice/">2 ways to delete an element in a slice</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afcaf8d27b13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python 深入解析 List 的Append]]></title>
            <link>https://dacozai.medium.com/python-%E6%B7%B1%E5%85%A5%E8%A7%A3%E6%9E%90-list-%E7%9A%84append-3d92e6677ca8?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d92e6677ca8</guid>
            <category><![CDATA[append]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[lists]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Sat, 30 May 2020 01:19:38 GMT</pubDate>
            <atom:updated>2020-10-30T09:34:15.361Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*cLpmzZbkQ40WUR8ef6Tj9g.png" /></figure><p>List可以說是Python最引人入勝的地方！他有所謂的一行操作(List Comprehension). List 是sequence type, 然後就如一般的array來說 … 他可以直接透過index來取用其位置上的值，看個🌰吧</p><pre>```python3<br>a = [1,2,3,4,5]<br>a[0] # 1</pre><pre># another way<br>a = list(range(1,6))<br>a = [elem for elem in range(1,6)]</pre><p>要記得的是，range是一個 iterator, 因此, 要透過list函數來轉換或者直接用for來解 … 否則你直接拿到的就是一個iterator! 請看下面速解.</p><pre><strong>&gt;&gt;&gt; a = range(1,6)<br>&gt;&gt;&gt; a<br>range(1, 6)<br>&gt;&gt;&gt; type(a)<br>&lt;class &#39;range&#39;&gt;</strong></pre><p><a href="https://towardsdatascience.com/how-fast-numpy-really-is-e9111df44347">list很多操作是可以被numpy.array來加速的</a>！但是這裡，誠如標題我們想探討的只有append這個行為！</p><p>請至附錄[<a href="#482c">Code_Test_Append</a>]來看本次驗證的程式碼以及結果. <strong>結論: 不要用numpy.array做append!</strong> 雖然結果會依個人環境而跑出不同的時間 … 但基本上，用numpy.array做append這件事情，確定是不理想的行為.</p><p>至於deque跟list的差距, 我有試過在python2.7.16 deque是比list還要快上許多的！不過, 如果用了Python 3.8.3的話, 將不會有任何的差距！</p><p>另外補充如果在可以跳脫 append的前提下，請盡量的使用list comprehension. 速度上存在顯著的差異！當然，我知道當你如果是在收資料，只能等資料打過來的前提下，還是只能用append.</p><p>接著，說到收資料 … 我想大家會有個疑惑說 … 奇怪append 不是 O 1? 為什麼我會越收越慢? 這是來自於<a href="https://stackoverflow.com/questions/2473783/is-there-a-way-to-circumvent-python-list-append-becoming-progressively-slower">Python的Garbage Collector的問題</a>. 我也做了相仿的測試請至<a href="#a90c">Code_Append_Big_Size</a>來檢閱測試用程式碼, 不過我把時間取了平均分別跑了 10,000/ 100,000/ 1,000,000 次. 雖然，結果並沒有作者做出來那麼可觀的差異(3rd, July, 2020) … 但還是可以清楚的看到是存在著差異的！因此，如果在要做類似的操作想要再加速的話，這是一個<strong>推薦的做法</strong>.</p><p>那篇Stackoverflow的文章作者提到, 當Python GC在做運行的時候, 會去掃過每一個list裡面的object來決定是否要free這個memory. 當然, 他也有提到這篇文章已久，這個bug可能已被修正. 這就是為什麼, 經過測試之後, 還是有差但結果已不顯著像是 899 -&gt; 18.6這樣！另外，這邊補充可以看看<a href="https://docs.python.org/2.0/ext/refcounts.html">append背後GC的模式.</a></p><h3>附錄</h3><h4>Code_Test_Append</h4><pre><strong># ENV<br># Python 3.8.3<br>#[Clang 11.0.3 (clang-1103.0.32.59)] on darwin<br></strong>from collections import deque<br>import numpy as np<br>import time</pre><pre>def testNumpyAppend(num):<br>  arr = np.array([])<br>  for _ in range(num):<br>    np.append(arr, &quot;x0y0&quot;, axis=None)</pre><pre>def testListAppend(num):<br>  arr = []<br>  for _ in range(num):<br>    arr += [&quot;x0y0&quot;]</pre><pre>def testListCompreAppend(num):<br>  arr = [&quot;x0y0&quot; for _ in range(num)]</pre><pre>def testDequeAppend(num):<br>  deq = deque()<br>  for _ in range(num):<br>    deq.append( &quot;x0y0&quot; )</pre><pre>TEST_NUMBER = 100000</pre><pre>print(f&quot;RUN {TEST_NUMBER} times&quot;)<br>startNumpyTime = time.time()<br>testNumpyAppend(TEST_NUMBER)<br>execution_time = time.time() - startNumpyTime<br>print (f&#39;Numpy\t-&gt;  {(execution_time*1000):0.3f}ms&#39;)</pre><pre>startListTime = time.time()<br>testListAppend(TEST_NUMBER)<br>execution_time = time.time() - startListTime<br>print (f&#39;List\t-&gt;  {(execution_time*1000):0.3f}ms&#39;)</pre><pre>startListTime = time.time()<br>testListCompreAppend(TEST_NUMBER)<br>execution_time = time.time() - startListTime<br>print (f&#39;ListCmp\t-&gt;  {(execution_time*1000):0.3f}ms&#39;)</pre><pre>startDequeTime = time.time()<br>testDequeAppend(TEST_NUMBER)<br>execution_time = time.time() - startDequeTime<br>print (f&#39;Deque\t-&gt;  {(execution_time*1000):0.3f}ms&#39;)</pre><pre>&quot;&quot;&quot;<br>@ 1,000 result<br>Numpy   -&gt;  19.252ms<br>List    -&gt;  0.431ms<br>ListCmp -&gt;  0.138ms<br>Deque   -&gt;  0.243ms</pre><pre>@ 5,000 result<br>Numpy   -&gt;  64.615ms<br>List    -&gt;  0.753ms<br>ListCmp -&gt;  0.454ms<br>Deque   -&gt;  0.725ms</pre><pre>@ 10,000 result<br>Numpy   -&gt;  118.736ms<br>List    -&gt;  1.534ms<br>ListCmp -&gt;  0.841ms<br>Deque   -&gt;  1.366ms</pre><pre>@ 100,000 result<br>Numpy   -&gt;  1148.628ms<br>List    -&gt;  11.774ms<br>ListCmp -&gt;  6.079ms<br>Deque   -&gt;  11.760ms<br>&quot;&quot;&quot;</pre><h4>Code_Append_Big_Size</h4><pre>import time<br>import gc</pre><pre>class Test:<br>  def __init__(self):<br>    self.number_one = 1<br>    self.number_two = 2<br>    self.explain = &#39;whatever string you like&#39;</pre><pre>def time_to_append(sz, item_gen):<br>  test_list = []<br>  t0 = time.time()<br>  for _ in range(sz):<br>    test_list.append(item_gen())<br>  return time.time() - t0</pre><pre>def test(append_size, times):<br>  ct = 0<br>  for _ in range(times):<br>    ct += time_to_append(append_size, lambda: Test())<br>  print(f&quot;Average time cost with GC -&gt; {round(ct/times,3)} ms&quot;)</pre><pre>def test_nogc(append_size, times):<br>  ct = 0<br>  for _ in range(times):<br>    gc.disable()<br>    ct += time_to_append(append_size, lambda: Test())<br>    gc.enable()<br>  print(f&quot;Average time cost without GC -&gt; {round(ct/times,3)} ms&quot;)</pre><pre>SIZE = 1000000<br>TIMES = 100<br>test(SIZE, TIMES)<br>test_nogc(SIZE, TIMES)</pre><pre>&quot;&quot;&quot;<br>@ 10,000 result<br>Average time cost with GC    -&gt; 0.011 ms<br>Average time cost without GC -&gt; 0.009 ms</pre><pre>@ 100,000 result<br>Average time cost with GC    -&gt; 0.122 ms<br>Average time cost without GC -&gt; 0.096 ms</pre><pre>@ 1,000,000 result<br>Average time cost with GC    -&gt; 1.668 ms<br>Average time cost without GC -&gt; 1.013 ms</pre><pre>&quot;&quot;&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d92e6677ca8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning ReactJS — Day 1]]></title>
            <link>https://dacozai.medium.com/learning-reactjs-day-1-80bfbbfb95b1?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/80bfbbfb95b1</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 23:13:43 GMT</pubDate>
            <atom:updated>2020-02-07T23:13:43.804Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning ReactJS — Day 1</h3><p>React is here as a library.</p><p>This is the first time that I actually learn ReactJS. After writing a few notes, I decided to write articles on Medium partly because of saving time through typing. But it is easy for me to update any extra information. I try my best to understand everything in-depth. So, feel free to click <a href="#87a6"><strong>Build-Up</strong></a> if you want to find <strong>the practical tutorial</strong>. I am eager to write about more about React from the official site/ talk/ APIs documents to dig into the mechanism/ ideas behind the scene. <strong>To be honest, I am not the guy who has nothing to do, but this is the best way for me to learn a new thing. This is just my way.</strong></p><p>The definition of a term will be put into term: ← this block. But, I will explain it in my way probably with an example 🌰 <a href="#b103">⁰</a>.</p><blockquote>THIS IS THE WAY</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eegsh45DfvJTxvFtiKy71g.jpeg" /></figure><h4>Table of Contents</h4><ol><li><a href="#b8f7">JSX</a></li><li><a href="#f24c">Folder Structure</a></li><li><a href="#4e3b">Components</a><br>1. <a href="#e399">Class component</a><br>2. <a href="#92aa">Functional Component</a><br>3. <a href="#3fc8">Typescript</a></li><li><a href="#4eac">State and LifeCycle</a></li><li><a href="#d8ff">Event Handling</a></li><li><a href="#87a6">Build-Up</a></li></ol><h3>JSX</h3><p><strong>Separation of Concerns</strong><a href="#ca50">¹</a>: reducing <strong>coupling</strong> and increasing <strong>cohesion</strong>. In here, I use the exact definitions introduced by Pete Hunt in JSconf EU because he excellently explained the core idea of these two terms<a href="#d07a">³</a>.</p><pre>Coupling: the degree to which each program module relies on each of the other modules</pre><p>It talks about the dependencies between modules and modules. Think about that when you write ten functions and they use the same object. What if you have to change something for this object? Then, you are going to modify the same thing stupidly for ten times. Hence, this is a fundamental principle in software development.</p><pre>Cohesion: the degree to which elements of a module belong together</pre><p>🌰 We have a classic class called Dog. We build lots of things to this class, but you don’t really want cat’s methods or rabbit’s methods inside Dog class. BECAUSE they do not belong to Dog.</p><p>ReactJs argues that template design suppresses <strong>Soc</strong> because our controller and the template will be bound together as View-Model, which led to the display logic and the markup are inevitably tightly coupled and highly cohesive. However, this separates the technologies, not the concerns, ReactJS argues.</p><p>🌰 When you create a template, it is common to create one, which is a child of another one. What if we are going to change something in one? Then, we inevitably have to change all things are related to this one. What’s the worse, if we miss one thing, the whole thing might screw up! This is good 🌰 to demonstrate how the template design is vulnerable to <strong>Soc</strong> design.</p><p>To sum up, this is the reason that React employs the concept of Component, and this is how React team made the decision. What the benefits of this design are below:<br>1. reusable<br>2. composable (linear complexity)<br>3 .unit testable</p><p>Pete Hunt: Don’t write spaghetti code. We are software engineers.<br>Besides, this is the main motivation of JSX to React. JSX puts the whole makeup in JS<a href="#1b8e">⁴</a>.</p><p>Tips. JSX is closer to JS, so they use camelCase to express HTML tags.<br>🌰 class → className, tabindex → tabIndex</p><p>JSX prevent Injection Attack by converting everything into a string.</p><h3>Folder Strcture</h3><pre>my-app<br>├── build<br>├── node_modules<br>├── public<br>│   ├── favicon.ico<br>│   ├── index.html<br>│   └── manifest.json<br>├── src<br>│   ├── App.css<br>│   ├── App.tsx<br>│   ├── App.test.tsx<br>│   ├── index.css<br>│   ├── index.js<br>│   ├── logo.svg<br>│   └── serviceWorker.js<br>├── .gitignore<br>├── package.json<br>├── tsconfig.json<br>└── README.md</pre><p>I solely write up the structure since the specific explanation of every file and folder is addressed in <a href="https://medium.com/@Charles_Stover/optimal-file-structure-for-react-applications-f3e35ad0a145">this post</a>.</p><p>We know that index.html is the entry page for the website, and you can easily find index.htmlin ./public <br>After that, you could find &lt;div id=&quot;root&quot;&gt;&lt;/div&gt; which is called root DOM node . Everything inside this node is managed by React DOM. Therefore, it is possible to integrate React with Angular. Then you will find multiple root node for React and, of course, Angular if it uses a similar concept.</p><p>To render a component, we are going to use <br>ReactDOM.render(element, document.getElementById(&#39;root&#39;)) <br>In practice, the whole component is rendered once, but you can render a page by setting a time interval.<br>🌰 setInterval(function, 1000) In here, we are going to render the component every second.</p><h3>Components</h3><p>The components could be defined as a function or class, but React currently provide more features in the class component. They receive props(properties) as their object argument with data.</p><p>So, <strong>why do we need to use function component?</strong><a href="#ef90">⁵</a></p><p>Firstly, let us take a look at the writing styles of these two.</p><pre>function Welcome(props) {<br>  return &lt;h1&gt;Hello, {props.name}&lt;/h1&gt;;<br>}</pre><pre>class Welcome extends React.Component {<br>  render() {<br>    return &lt;h1&gt;Hello, {this.props.name}&lt;/h1&gt;;<br>  }<br>}</pre><p>It is clear that the function component has few lines to express and it is more simple.</p><h4>Class component</h4><ol><li>extend <strong>React.Component</strong></li><li>Need to use <strong>render()</strong> method</li><li>can have <strong>local state</strong></li><li><strong>life cycle hooks</strong></li></ol><h4>Function component</h4><ol><li><strong>The simplest way</strong> to define a component</li><li>Receives a `props` object as a parameter</li><li><strong>Not have</strong> local state and <strong>cannot access</strong> lifecycle hooks</li></ol><p>But, in November 2018, React team added hooks into the function component feature<a href="#0b4b">⁶</a>. In the React design, function component would be the major writing style because it presents <strong>Soc</strong> spirit. Let me put this in my way below.<br>🌰 We can consider the class component as the parent component and the functional components as the child nodes. By doing so, we could reduce the coupling of the components.</p><p><strong>Tips</strong>.</p><ol><li>Always start a component name with a capital letter because React treats the start with the lowercase letter as DOM tags.<br>🌰 &lt;div&gt;&lt;/div&gt; is html tag; &lt;Welcome /&gt; is the component.</li><li>Class or function component never modify their props. React has a strict rule shown below! <strong>Props are read-only.</strong></li></ol><blockquote><strong>All React components must act like pure functions with respect to their props.</strong></blockquote><h4>Typescript</h4><p>Before going into further of the Component, I would like to introduce a bit of Typescript. I decided to employ Typescript instead of Javascript because I wanted to write in a static language. I have written Javascript in the past few years, and I found it was vulnerable to the product and it wasted lots of time searching for some craps. This is the way. <br>Note. what I said below is the same as Javascript.</p><p>As you can see, React used the keyword <strong>extends </strong>is the inheritance in Typescript<a href="#3da4">⁷</a>. The other thing is that, after building a component, we would use <strong>export</strong> in the end, which is modularise the class to other files.</p><p>Last but not least, what is document.getElementById(&#39;root&#39;) ? This is the way that we get a DOM element object matching the specified ID<a href="#ebd9">⁸</a>.</p><p>So far, you could understand the way why React calls itself a library instead of a framework because the whole project is just a Javascript project. You write in Javascript way through using many methods provided by React. <br><strong>In here, React team strongly advice developers to use base component classes instead of constructing the inheritance</strong>. This warning is evident.</p><p>Let’s go into an essential topic, shall we?</p><h3>State and LifeCycle</h3><p>It is always important to understand the lifecycle in software development. Below is the cheat sheet in <a href="http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2kLo8Z-L6XEvas5OOA9kw.png" /><figcaption>LifeCycle Diagram [ <a href="http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/">source</a> ]</figcaption></figure><p>As mentioned in the previous section, we cannot modify props, so we need to use a new thing which is called states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*Mbr-8SGlH3tkRwe6Hcak-w.png" /><figcaption>On the left-hand side is the example from React demonstration[<a href="https://reactjs.org/docs/state-and-lifecycle.html">source</a>] Right-hand side is the flow integrating LifeCycle diagram and the demo code.</figcaption></figure><p>In the class, if we would like to use props, we would need to use super(props) . This is how `props` becomes usable. So there are a number of steps for us to understand the lifeCycle in React Component. See the image above. If we are going to rerender the logic of the component, we should use componentDidMount() in the component class. BUT, <strong>be careful of using this method because the performance suffers from this design</strong><a href="#af74"><strong>⁹</strong></a>. setSatat in this method will update as an additional request to React before the browser updating the screen.</p><p>🌰 We create a component(class). We render it, which <strong>React </strong>helps us to put that into HTML DOM. That’s why we build up the view/ part of a webpage. React has its own way to deal with the data flow, so we use setState to do update part.</p><p>There are few tips are provided in the official about using state.</p><ol><li>Use setState instead of modifying the state directly.<br>🌰 (O): this.setState({greet: &#39;Hi&#39;}); (X): this.state.greet = &#39;Hi&#39;;</li><li>Updating is asynchronous in <strong>props</strong> and <strong>states</strong>, so it is a bad idea to rely on the values from updating.</li><li>What is the correct way to update two attributes in the state object?</li></ol><pre>componentDidMount() {<br>  fetchPosts().then(response =&gt; {<br>    this.setState({<br>      posts: response.posts<br>    });<br>  });<br><br>  fetchComments().then(response =&gt; {<br>    this.setState({<br>      comments: response.comments<br>    });<br>  });<br>}</pre><p>In the official document, we should update those variables independently. When we use setState to update a variable, you can think of that you send a request to React. Then, React will deal with those requests.<br><strong>NOTE. setState always leads to re-render!</strong></p><p>Apart from the method setStatein lifeCycle, we could use forceUpdate() to force React to re-rendering. Evidently, it is not the method advocated by the official. <strong>However, I consider this method could be useful when we use a third-party library which cannot communicate with React in a sense.</strong> At that moment, it is necessary to call this method.</p><h4>Handling the error</h4><p>There two error handling methods in a component.</p><ol><li>static getDerivedStateFromError()<br>This lifeCycle of the method is evoked when an error happened. It gets <strong>err</strong> as an argument then return value to update state.</li><li>ComponentDidCatch<br>This method is invoked after receiving the error thrown by a descendant component. It takes <strong>error</strong> and <strong>info</strong> as arguments.</li></ol><h4>Arrow Function ➡️</h4><p>Before going into the last section of Day 1, I would like to dig into the arrow function in javascript. The arrow function is kind of lambda function in Python. Hence, we could express in a way with simple style. <strong>This method is introduced in ES6</strong><a href="#a003"><strong>¹⁰</strong></a><strong>.</strong></p><p><strong>Why do we need an arrow function?</strong></p><blockquote>For sure that Javascript wants to get rid of lots of function keywords inside the callback. Besides, this writing style allows us to utilise the <a href="https://en.wikipedia.org/wiki/Functional_programming">Functional Programming</a> writing style with map and filter. The use of where is elaborated in <a href="https://zendev.com/2018/10/01/javascript-arrow-functions-how-why-when.html"><strong>HERE</strong></a> and its drawbacks are addressed in <a href="https://medium.com/@charpeni/arrow-functions-in-class-properties-might-not-be-as-great-as-we-think-3b3551c440b1"><strong>HERE</strong></a>.</blockquote><h3>Events Handling</h3><p>I am going to skip this part as here is specified in any posts. And it does not come from any surprise in this part. Instead, I am going to build a project to feedback anything to this section.</p><h3>Build-Up</h3><p>Lastly, this is how I initialise the React project</p><pre>npx create-react-app my-app --typescript<br>yarn add redux<br>yarn add -D node-sass @types/node-sass</pre><p>Therefore my package.json looks like below</p><pre>&quot;dependencies&quot;: {<br>    &quot;<a href="http://twitter.com/testing">@testing</a>-library/jest-dom&quot;: &quot;^4.2.4&quot;,<br>    &quot;<a href="http://twitter.com/testing">@testing</a>-library/react&quot;: &quot;^9.3.2&quot;,<br>    &quot;<a href="http://twitter.com/testing">@testing</a>-library/user-event&quot;: &quot;^7.1.2&quot;,<br>    &quot;<a href="http://twitter.com/types/jest">@types/jest</a>&quot;: &quot;^24.0.0&quot;,<br>    &quot;<a href="http://twitter.com/types/node">@types/node</a>&quot;: &quot;^12.0.0&quot;,<br>    &quot;<a href="http://twitter.com/types/react">@types/react</a>&quot;: &quot;^16.9.0&quot;,<br>    &quot;<a href="http://twitter.com/types/react-dom">@types/react-dom</a>&quot;: &quot;^16.9.0&quot;,<br>    &quot;node-sass&quot;: &quot;^4.13.1&quot;,<br>    &quot;react&quot;: &quot;^16.12.0&quot;,<br>    &quot;react-dom&quot;: &quot;^16.12.0&quot;,<br>    &quot;react-scripts&quot;: &quot;3.3.1&quot;,<br>    &quot;redux&quot;: &quot;^4.0.5&quot;,<br>    &quot;typescript&quot;: &quot;~3.7.2&quot;<br>  }</pre><p>The aim here is to build React demo Tic-Tac-Toe in Typescript way. Below is the folder structure of my project. I did not learn Typescript before just as you do. So, I believe when I am panic, you do too. Let me help you to get through this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*IAlK0B0t2ta7lunKvyIpvw.png" /></figure><p>You can find the source code in <a href="https://codepen.io/gaearon/pen/aWWQOG?editors=0010">HERE</a> from React official. I am not going to put on mine because come on, this is just copying and pasting then creating files. I believe you can do it!</p><p>However, I believe you may encounter the same problem at the beginning. Why would I get type error from props? I don’t even know what props is! How could I build up type for it?</p><p>Don’t worry let me help you!</p><p>In React component, we know that it should be written as below</p><pre>class Square extends React.Component</pre><p>It is a generic type, so we will receive an error from visual studio code or whatever editor you use. Basically, it tells you just one thing: xxx does not exist on type &#39;ReadOnly&lt;{}&gt;&amp;Readonly&lt;{children?:ReactNode}&gt;&#39; .what does this mean? 🌰 You gotta define a type here! the solution is below.</p><pre>interface MyProps {<br>  value: string,<br>  onClick: Function;<br>}</pre><pre>class Square extends React.Component&lt;MyProps&gt; </pre><p>If you don’t understand type system in Typescript, please find the document <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html">here</a>. That’s right, we have to define type for everything that we use in this component, isn’t it GREAT! Below is just another example in case of that you suddenly be panic again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*-_1EkmLl2LVr-J0B7xB3_A.png" /></figure><p>In Typescript, it is not easy for a beginner, like me, to handle it quickly. However, it worths people like me to study it because I get more picture to peek React behind the scene.</p><p>Here is my GitHub <a href="https://github.com/dacozai/react-ts-tic-tac-toe"><strong>link</strong></a>. Feel free to see how I build up the project. However, I will continue to update this project. Therefore, it will be different over time. Hope you enjoy everything. I will update Day 2 in the future.</p><p>References</p><p>[0] 🌰 This is an analogy from 例子(example) to 栗子(chestnut) in Chinese. It is like “I don’t like the noise in the washing room and the smell either (Ethanol)”. This is my way.</p><p>[1] Separations of Concerns (Soc)that is created in by <a href="https://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Edsger W. Dijkstra</a> in his 1974 paper “On the role of scientific thought” <a href="#7146">²</a><br><a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a></p><p>[2] On the role of scientific thought<br><a href="https://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD447.html">https://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD447.html</a></p><p>[3] Pete Hunt: React: Rethinking best practices — JSConf EU<br><a href="https://www.youtube.com/watch?v=x7cQ3mrcKaY">https://www.youtube.com/watch?v=x7cQ3mrcKaY</a><br><a href="https://www.slideshare.net/floydophone/react-preso-v2">https://www.slideshare.net/floydophone/react-preso-v2</a></p><p>[4] The intro of React<br><a href="https://reactjs.org/docs/introducing-jsx.html">https://reactjs.org/docs/introducing-jsx.html</a></p><p>[5] The difference between class and function component<br><a href="https://medium.com/@Zwenza/functional-vs-class-components-in-react-231e3fbd7108">https://medium.com/@Zwenza/functional-vs-class-components-in-react-231e3fbd7108</a></p><p>[6] Hooks<br><a href="https://reactjs.org/blog/2018/11/27/react-16-roadmap.html">https://reactjs.org/blog/2018/11/27/react-16-roadmap.html</a></p><p>[7] Typescript<br><a href="https://www.typescriptlang.org/docs/handbook/classes.html">https://www.typescriptlang.org/docs/handbook/classes.html</a></p><p>[8] Documents.getElementById<br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById">https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById</a></p><p>[9] Performance suffers from re-render with multiple setStates<br><a href="https://reactjs.org/docs/react-component.html#componentdidmount">https://reactjs.org/docs/react-component.html#unsafe_componentwillmount</a></p><p>[10] Arrow Function<br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80bfbbfb95b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mac vim setting]]></title>
            <link>https://dacozai.medium.com/mac-vim-setting-ad0ba5044503?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad0ba5044503</guid>
            <category><![CDATA[vim-plugins]]></category>
            <category><![CDATA[dracula]]></category>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[mac]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 17:15:49 GMT</pubDate>
            <atom:updated>2020-02-03T17:27:42.773Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a note to myself and, hopefully, I want to help people out with this short but accurate instructions. (Goal: use Dracula vim in mac Catalina)</p><p>In here, my goal is to utilise <a href="https://github.com/dracula/vim">Dracula colour theme</a> in my vim. This is my first time to set up vim through <a href="https://github.com/junegunn/vim-plug">vim-plug</a>. I like Dracula style after utilising its theme in Visual Studio Code. I believe you can pick any packages you like to replace Dracula package. Let’s start, shall we?</p><h4>vim-plug</h4><p>In mac, you can use the following step to achieve the goal. Please paste my code after $ in your terminal. I didn’t mean to make this complex instead make it crystal clear!</p><pre>$ cd ~<br>$ mkdir .vim<br>$ cd .vim<br>$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \<br>    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim</pre><p>After doing this, you will find the directory looks like the following.</p><p>Please make sure that you are in the path of /Users/yourname/.vimby typingpwd . If not, you can simply type cd ~/.vim . You will see that there is a folder called <strong>autoload</strong> in this directory.</p><h4>vimrc</h4><p>Okay! After that, use cd ~ to go back to the home directory then create the .vimrc file by typing vim .vimrc . You will get into the vim mode. I am pretty sure that you are familiar to this! Otherwise, you will never follow my article. Then, paste everything into the.vimrcfile.</p><pre><strong>call plug#begin(&#39;~/.vim/plugged&#39;)</strong></pre><pre><strong>&quot; Dracula<br>Plug &#39;dracula/vim&#39;, { &#39;as&#39;: &#39;dracula&#39; }</strong></pre><pre><strong>call plug#end()</strong></pre><pre><strong>syntax on<br>colorscheme dracula<br>set nu</strong></pre><p>Then!!! use:to put your command w which is saving the file. After that using this command :PlugInstall. After the installation, you could use q to leave this mode. And then … Enjoy Dracula theme, cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad0ba5044503" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Pointer note in C++]]></title>
            <link>https://dacozai.medium.com/my-pointer-note-in-c-402652b64c64?source=rss-c599ee183cd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/402652b64c64</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Eden Chen]]></dc:creator>
            <pubDate>Fri, 27 Dec 2019 00:51:23 GMT</pubDate>
            <atom:updated>2019-12-30T18:44:01.815Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gibberish</h3><p>This is a very difficult but fundamental topic when anyone wants to jump into C/C++. <strong>I write this article mainly for myself.</strong> I believe there are tons of articles that explain <strong><em>pointer</em></strong> far better than me! Additionally, English is not my first language, so I will try to explain it simple enough!</p><p>Trust me, explain this concept in English is far difficult for me than any English speakers. Why do I want to write in English?! I think if I could articulate the idea through another language, I will not only think the sentence over and over again but also think deeper toward this complex concept — <strong>pointer</strong>.</p><h3>Pointer</h3><p>A pointer is a memory address of a variable. There are two operators that help us to create pointers and read value through pointers.</p><h4>Operators</h4><ol><li>Kleene star(*)<br>There are two functions from *<br>1. Declare a pointer variable<br>2. Deference the value of a pointer variable (Deference Operator)</li><li>Address-of Operator(&amp;)<br>when we use &amp; on a variable, we could acquire the address of the variable.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7f0582aadf7cfd47cacf6662c4c6fcb/href">https://medium.com/media/a7f0582aadf7cfd47cacf6662c4c6fcb/href</a></iframe><p>After the basic understanding of the operators, we can discover deeper about pointer. First, I would like to talk about the relationship between pointer and array. It is clear that when we manipulate data through a variable, we will suffer from the size of the data variable. However, the pointer has only 8 bytes! See below’s examples.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44f878cad4452ad1eae5efd2ce43fba0/href">https://medium.com/media/44f878cad4452ad1eae5efd2ce43fba0/href</a></iframe><p>Quick remind: if we want to create dynamic multi-dimensional arrays, we have to use a pointer to create. When the programme is running, we have to request memory from the heap. However, I am not going to address this topic although this is a good topic to unveil the inner mechanism of C/C++. Below, I am going to show how to create a 2D array in C++.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/768b5a34bb2f931b8242916db5eb9d57/href">https://medium.com/media/768b5a34bb2f931b8242916db5eb9d57/href</a></iframe><h3>An array of Pointers VS Pointer to Array</h3><p>This part is really confusing to me, so I write an example to elaborate on this concept.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f02c35515823eef6996b805000ff1d96/href">https://medium.com/media/f02c35515823eef6996b805000ff1d96/href</a></iframe><h4>Last but not least …</h4><p>In the function, we could return pointer as well!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e40ada6d3cb356f871fac924c998257/href">https://medium.com/media/3e40ada6d3cb356f871fac924c998257/href</a></iframe><p>Multi-layer of the point is a very complex concept … Some cases are still confusing to me. If I understand more, I will update this article in the future.</p><p>[Updated 27th, Dec 2019 Be continued … ]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=402652b64c64" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>