<?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 Thomas Wu on Medium]]></title>
        <description><![CDATA[Stories by Thomas Wu on Medium]]></description>
        <link>https://medium.com/@wu.thomas?source=rss-9aef47402a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*08NBtnCJKpaaJ2O_XZ99tQ.png</url>
            <title>Stories by Thomas Wu on Medium</title>
            <link>https://medium.com/@wu.thomas?source=rss-9aef47402a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:30:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wu.thomas/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[Max Stack problem and solution]]></title>
            <link>https://medium.com/geekculture/max-stack-problem-and-solution-a1cd2b088e83?source=rss-9aef47402a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1cd2b088e83</guid>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[binary-search-tree]]></category>
            <dc:creator><![CDATA[Thomas Wu]]></dc:creator>
            <pubDate>Mon, 17 Oct 2022 08:56:38 GMT</pubDate>
            <atom:updated>2022-10-18T05:46:07.145Z</atom:updated>
            <content:encoded><![CDATA[<h4>Software Engineer Survival Diary</h4><h4>Practical Data Structure in Action</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/0*pEfwNuuMdRd7HbjR.jpg" /><figcaption>source: etsy.com</figcaption></figure><p>In the previous article, I talked about <a href="https://medium.com/@wu.thomas/hacktoberfest-is-live-e322d29a782f">HacktoberFest</a> this year. Today I would like to talk about some popular coding interview questions. And at the same time a little walkthrough on the data structure topic. Let’s get started.</p><p>Max stack problem is something that can test a candidate’s logical thinking on data structure and big O concepts when hiring some developer role. Here’s the question statement:</p><p><em>Design a max stack data structure that supports the stack operations and supports finding the stack’s maximum element.</em></p><blockquote>Implement the MaxStack class:</blockquote><blockquote>MaxStack() Initializes the stack object.</blockquote><blockquote>void push(int x) Pushes element x onto the stack.</blockquote><blockquote>int pop() Removes the element on top of the stack and returns it.</blockquote><blockquote>int top() Gets the element on the top of the stack without removing it.</blockquote><blockquote>int peekMax() Retrieves the maximum element in the stack without removing it.</blockquote><blockquote>int popMax() Retrieves the maximum element in the stack and removes it. If there is more than one maximum element, only remove the <strong>top-most</strong> one.</blockquote><blockquote>You must come up with a solution that supports O(1) for each top call and O(logn) for each other call.</blockquote><p>The requirement is important, here it requires us to have O(log N) for each other call, including the popMax. Therefore, a traditional solution like using a stack to store will not work, since the popMax operation would require O(N) time. <a href="https://blog.devgenius.io/how-to-solve-max-stack-using-two-stacks-c4ac4cc77922">Link</a></p><p>Re-visiting Data Structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/0*3olOo095SOkIaj0F.png" /><figcaption>source: mygreatlearning.com</figcaption></figure><p>If it is to implement a Stack, one can do it with one of the linear data structures, such as Array or LinkedList. However, for this case we also need to fulfill pop/peek the max ( the value) from the stack, somehow additional thoughts must be considered. When it comes to getting the Max out of some items, you can go for non-linear data structures, and some kinds of tree data structures are the proper way to go. To quickly answer this question I will suggest having 2 data structures in my class, one is for normal stack operations (e.g. push/pop with its natural order), and one is for the max operations (peekMax, popMax with respect to the values). I would implement each using a balanced tree data structure, such as the TreeSet offered by Java Collection. A balanced tree is perfect for keeping all elements sorted in some specified order <strong>dynamically</strong>. So, now one is for Order and one is for Values.</p><h4>Algorithm</h4><p>As discussed, we need to maintain two balanced trees: one is in pushing order (orderTree), and another is sorted by values (valueTree).</p><p>To implementpush , we need to push the element into both two balanced trees, orderTree and valueTree</p><p>To implementtop and peekMax, we only need to return the last element value of orderTree for top query, and the last element value of valueTree for peekMax, since orderTree and valueTree are sorted by the order and values.</p><p>To implementpop and popMax, we call the TreeSet’s remove method, which is a find and remove method of performace O(log N), for the returned element in both two balanced trees. For pop, we first remove the last element in orderTree, and then remove the element in valueTree. Whereas for popMax, we first remove the last element in valueTree, and then remove the element in orderTree.</p><p><strong>Conclusion</strong></p><p>I hope my article helps you in more thinking about data structure design. If you like this article, please subscribe and follow my medium as it will help grow to reach a broader scope of audience. Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1cd2b088e83" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/max-stack-problem-and-solution-a1cd2b088e83">Max Stack problem and solution</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacktoberfest is Live]]></title>
            <link>https://medium.com/geekculture/hacktoberfest-is-live-e322d29a782f?source=rss-9aef47402a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e322d29a782f</guid>
            <category><![CDATA[hacktoberfest]]></category>
            <dc:creator><![CDATA[Thomas Wu]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 03:16:40 GMT</pubDate>
            <atom:updated>2022-10-18T05:46:08.719Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*k2UBD5jWsyZlCWAhANJ_ow.png" /><figcaption>HacktoberFest</figcaption></figure><p><strong>Hacktoberfest 2022 — </strong>the <strong>most</strong> <strong>awaited open source community</strong> <strong>festival</strong> is already in full swing! The month-long event started on <strong>26th September </strong>and will go on till <strong>31st October.</strong></p><p>With only <strong>18-days</strong> left — you can now participate in exciting events, workshops, and webinars by Industry leaders. You also get to explore the latest open source trends and emerging tech ideas with leading open source communities.</p><p>Some of the most popular projects are listed below:</p><h3><a href="https://github.com/freeCodeCamp">freeCodeCamp </a>/ <a href="https://github.com/freeCodeCamp/freeCodeCamp">freeCodeCamp</a>, <a href="https://github.com/TheAlgorithms">TheAlgorithms </a>/ <a href="https://github.com/TheAlgorithms/Python">Python</a>, <a href="https://github.com/microsoft">microsoft </a>/ <a href="https://github.com/microsoft/vscode">vscode</a>, <a href="https://github.com/axios">axios </a>/ <a href="https://github.com/axios/axios">axios</a>, <a href="https://github.com/storybookjs">storybookjs </a>/ <a href="https://github.com/storybookjs/storybook">storybook</a>, <a href="https://github.com/ansible">ansible </a>/ <a href="https://github.com/ansible/ansible">ansible</a>, <a href="https://github.com/nestjs">nestjs </a>/ <a href="https://github.com/nestjs/nest">nest</a>, <a href="https://github.com/strapi">strapi </a>/ <a href="https://github.com/strapi/strapi">strapi</a></h3><p>Here’s how you can participate:</p><ol><li>Which Open-Souce Project/ Community I can contribute to?</li></ol><p>You can choose any project which falls under Hacktoberfest guidelines to contribute to.</p><p>2. Where can I check the Hacktoberfest event guidelines?</p><p>Please visit the URL to refer the event guidelines — <a href="https://hacktoberfest.com/participation">https://hacktoberfest.com/participation</a></p><p>3. What is public Github URL?</p><p>This will be your Github Profile URL, something like this : <a href="https://github.com/thomas-wu2">https://github.com/thomas-wu2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e322d29a782f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/hacktoberfest-is-live-e322d29a782f">Hacktoberfest is Live</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical Middle Tier Design]]></title>
            <link>https://medium.com/geekculture/practical-middle-tier-design-519e290644bf?source=rss-9aef47402a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/519e290644bf</guid>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Thomas Wu]]></dc:creator>
            <pubDate>Sun, 09 Oct 2022 19:01:49 GMT</pubDate>
            <atom:updated>2022-10-09T19:01:49.161Z</atom:updated>
            <content:encoded><![CDATA[<h4>Here’s how</h4><h4>A sharing of a real-life integration project</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*hVXyz3Tub-7nE9P4RHaxPg.png" /><figcaption>source: microsoft.com</figcaption></figure><p>Setting the scene:</p><p>For a recent client project on migrating a backend server to another vendor, it inspires me to have an article for a re-visit of middle-tier design.</p><p><a href="https://learn.microsoft.com/en-us/azure/architecture/guide/architecture-styles/n-tier">N-tier architecture style</a> from microsoft gives the background and here I will concentrate on the middle-tier. It also explains the difference between layer and tier, the pros and cons and challenges for N-tier, etc.</p><p>I will borrow from the article <a href="https://www.freecodecamp.org/news/what-is-middleware-with-example-use-cases/">here</a>, for some definition and user cases.</p><p>First for <strong>translator</strong>: In my case, we implement <strong>translation for below:</strong></p><ol><li>from the incoming xml request and the outgoing json request (to backend remote service),</li><li>translate project/enterprise specific error codes/description from products error codes. For example, the backend server response HTTP error codes (404, 500,etc), while the client expects enterprise-specific error codes (e.g. 1000 for File Not Found, 3000 for Internal Server Error etc)</li></ol><p>Second for <strong>accumulating</strong>: when receive 1 incoming request, we need to do multiple outgoing requests to downstream backend service, for example when doing upload for a new document/photo consist of 4 backend requests: a metadata create request must be sent first, and then an upload url request to request an upload URL, followed by one or more multipart upload requests for the payload, then at last by a finalization request.</p><p>Third for <strong>duplicating</strong>: sometimes we can store data at the middle layer for fast retrieval without querying backend servers. In my case, we haven’t implemented it because of the scope and complexity.</p><p>Fourth for <strong>API Security</strong>: There are many options to implement security for the API, in particular, to provide authentication and authorization to our APIs. Short-lived token-based approach should be used for authenticating client request. In addition, since middleware is used, this provided flexibility as it can use any authentication method supported by middleware. In my case, my middleware can adapt and keep token authentication unchanged from client side, while the middleware talking with backend using some API Keys supported by the backend.</p><p><strong>Solution challenges and Problems faced:</strong></p><ol><li>Coupling to backend uptime</li></ol><p>Since the backend experienced some downtime we need to consider some solution to duplicating the data in the middle-tier, so as to minimise service outage to client.</p><p>2. Middle-tier retry and caching</p><p>Due to intermittent downtime, and also due to some constraints we cannot change the legacy front-end logic, it turns out additional application <strong>retry </strong>logic and <strong>caching </strong>mechanism are implemented in the middle-tier to fulfill the functional and performance requirement.</p><p><strong>Conclusion:</strong></p><p>I hope my article to help you in more thinking about the middleware design. If you like this article, please subscribe and follow my medium as it will help grow reach to a broader scope of audience. Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=519e290644bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/practical-middle-tier-design-519e290644bf">Practical Middle Tier Design</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to do data visualisation for your data science research?]]></title>
            <link>https://medium.com/geekculture/how-to-do-data-visualisation-for-your-data-science-research-a2d8b32bafdc?source=rss-9aef47402a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2d8b32bafdc</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[plotting]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-representation]]></category>
            <category><![CDATA[charting]]></category>
            <dc:creator><![CDATA[Thomas Wu]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 15:39:19 GMT</pubDate>
            <atom:updated>2022-04-21T07:25:50.112Z</atom:updated>
            <content:encoded><![CDATA[<h4>Practical Data Science in Python</h4><h3>How to do practical data science research?</h3><h4>Put together principles of data representation, basic charting techniques for a research</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*y-vMvknfsExJGIyGyMlfrA.png" /><figcaption>image from seaborn.pydata.org</figcaption></figure><p>In the previous post I discussed some <a href="https://medium.com/geekculture/using-personal-access-token-in-sourcetree-to-connect-to-github-3702a29554d3">github tutorials</a>. In this post, I will talk about some data science topics: How to do data visualisation in python for your dataset. So, let’s get started.</p><p>In a traditional data science research, it has 3 steps: 1. define the dataset and your source, 2. define the research question you would like to explore, and 3. do the coding and produce the result, optionally in a data representation to justify your result.</p><ol><li><em>Datasets</em>: State the region and the domain category that your data sets are about :</li></ol><p>For example, in my example here, I will explore the data in Hong Kong. And the domain category here is Real Estate, I can choose from many datasets. In the example here the data set is set to be (1) Mortgage Loans Outstanding and (2) Property Price Indices.</p><p>2. <em>Research Question</em>: Formulate a statement about the domain category and region that you identified.</p><p>The research question is defined to be: <em>How have the residential mortgage loans outstanding and property price indices changed over the past twenty years?</em></p><p>To be more objective, we should provide the source links to publicly accessible datasets. These could be links to files such as CSV or Excel files, or links to websites which might have data in tabular form, such as Wikipedia pages. Here are the links:</p><p>Link 1 (<em>Private Domestic — Prices indices by Class</em>): <a href="https://www.rvd.gov.hk/doc/en/statistics/his_data_4.xls">https://www.rvd.gov.hk/doc/en/statistics/his_data_4.xls</a></p><p>Link 2 (<em>Residential mortgage survey results</em>): <a href="https://www.hkma.gov.hk/media/eng/doc/market-data-and-statistics/monthly-statistical-bulletin/T0307.xlsx">https://www.hkma.gov.hk/media/eng/doc/market-data-and-statistics/monthly-statistical-bulletin/T0307.xlsx</a></p><p>3. <em>Coding</em>: From here, all is set except to get you hand dirty for some coding. We will use python and some of the libraries like pandas, matplotlib and numpy mainly. The coding process will invovle 3 parts: Preparation, Data Processing, and plan for data representation.</p><p><strong>(i)</strong> <em>Preparation</em> : Take a look at the datasets, to have an idea of : a. what the data look like, and b. any missing data or outliner c. any data cleansing needed to be done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*doqlwaPWdqGrNWaP02W-tA.png" /><figcaption>Use Python pandas library to read excel data</figcaption></figure><p><strong>(ii)</strong> <em>Data processing</em>: It invovle firstly reading the data to variable like Pandas Dataframe in python,</p><p>Let’s take Link 1 data as an Example. For example we can filter out header and footer and irrelevant columns and rows and store only the relevant data in a Dataframe using some built-in support of pandas</p><pre>df1sh1 = pd.read_excel(r’./T0307.xlsx’, “T3.7”, usecols=[0,1,3], skiprows=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,30,43,56,69], skipfooter=10)<br>df1sh2 = pd.read_excel(r’./T0307.xlsx’, “T3.7 (old)” , usecols=[0,1,3], skiprows=62, skipfooter=4)<br></pre><p>Rename the columns in dataframe:</p><pre>df1sh1.rename(columns={‘Unnamed: 0’:’Year’,’Unnamed: 1&#39;:’Month’,’(百萬港元)’:’Amount’}, inplace=True)<br></pre><p>Concat two dataframe (originating from 2 source excel worksheet etc.)</p><pre>df1 = pd.concat([df1sh2, df1sh1])</pre><p>Secondly do the transformations, groupings, etc. <br>Grouping time series data (e.g. monthly to yearly):</p><pre>df1 = df1.groupby(‘Year’).agg({‘Amount’:sum}).reset_index()</pre><p>Changing the metric units (e.g. from millions to billions)</p><pre>df1[‘Amount’] = df1[‘Amount’]/1000 #in billions</pre><p>We should then apply the same data processing to another dataset from Link 2, and I leave it for you as an exercise.</p><p><strong>(iii)</strong> <em>Think of how to represent the data</em>. As a data scientist we should strive to show the inter-relationship and find out any insights from the dataset. I recommend Alberto Cairo’s <a href="https://www.oreilly.com/library/view/the-truthful-art/9780133440492/">work </a>when it comes to the principles of truthly represent data. Pay attention to <a href="https://faculty.ucmerced.edu/jvevea/classes/Spark/readings/Cairo2015_Chapter_GraphicsLiesMisleadingVisuals.pdf">Graphic Lies, Misleading Visuals</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*LdqVo1WI1Q2NnPhaaXXiWw.png" /><figcaption>Use of Visualisation Wheel tool to plan you visuals</figcaption></figure><p>The basic tools for plotting in Python is Matplolib, and the <a href="https://matplotlib.org/stable/api/index">reference website</a> is remarkable for finding resources needed. There are three main layers in matplotlib architecture. From top to bottom, they are <strong>Scripting layer</strong> (matplotlib.pyplot module), <strong>Artist layer </strong>(matplotlib.artist module), and <strong>Backend layer </strong>(matplotlib.backend_bases module), respectively. We will mainly use the top level scripting layer to the basic plotting:</p><p>Plotting a bar chart, and setting some ticks and labels on axis:</p><pre>bars = plt.bar(year, outstandings, align=’center’, linewidth=0, width = 0.5, color=’black’)</pre><pre>plt.xticks(year)<br>plt.xlabel(‘Year’)<br>plt.ylabel(‘Total Loans Outstanding (in $ Billions)’, color = ‘green’)</pre><p>We will sometimes coding on the middle artist layer to do some customisations, like : Rotating the labels by 45 degrees:</p><pre>ax1.set_xticklabels(ax1.get_xticks(), rotation = 45)</pre><p>and setting some axes to be invisible:</p><pre>ax1.spines[‘top’].set_visible(False)<br>ax1.spines[‘left’].set_visible(False)</pre><p>Finally, we can have our own work on the proposed research question:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_slFRrNG2NAy4txBmNw9sw.png" /></figure><p>In summary, this post discuss a general approach to create data representation for a data science research. I hope you learn something and Thanks for supporting my articles. If I have time later I am going to publish more on other data science topics like other basic chartings like heatmaps, boxplot, or machine learning topic, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2d8b32bafdc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-do-data-visualisation-for-your-data-science-research-a2d8b32bafdc">How to do data visualisation for your data science research?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Sourcetree to connect to Github without password]]></title>
            <link>https://medium.com/geekculture/using-personal-access-token-in-sourcetree-to-connect-to-github-3702a29554d3?source=rss-9aef47402a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3702a29554d3</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[sourcetree]]></category>
            <category><![CDATA[personal-access-tokens]]></category>
            <category><![CDATA[token-based]]></category>
            <dc:creator><![CDATA[Thomas Wu]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 18:47:01 GMT</pubDate>
            <atom:updated>2022-03-25T05:58:20.707Z</atom:updated>
            <content:encoded><![CDATA[<h4>Here’s the trick</h4><h4>How to use Personal Access Token in Sourcetree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*WT8g9ZieiZz2W8kYM7Ufiw.png" /></figure><p>In this article, I am going to show 2 ways using PAT (Personal Access Token ) in Sourcetree to login to connect to GitHub after GitHub no longer supports authentication by username and password.</p><h4><strong>Background</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3bP0dd4I-nIbb2kzo7bYg.png" /><figcaption>Error Message when using Sourcetree to push to GitHub</figcaption></figure><p>If you encountered authentication issue during clone/push like below, please continue to read as I will show how to solve it. The error message says that the password authentication was removed already on August 13, 2021, it also provide a <a href="https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/">link</a> with more information. It contains an annoucement titled ‘Token Authentication Requirement for Git Operations’. If you read through you will find ‘Sourcetree’ is affected because it is under one of the affected workflows: ‘Any apps/services that access Git repositories on GitHub.com directly using your password’.</p><h4><strong>Pre-requisite: Generating PAT Token:</strong></h4><p>Now, I will show how to generate the Personal Access Token in GitHub first:</p><ol><li>In GitHub.com page, Go to Settings -&gt; Developer Settings -&gt; Personal Access Token, click ‘Generate new token’</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebFAfaT8-BCqgBLoJrqbJw.png" /><figcaption>Click ‘Generate new token’</figcaption></figure><p>2. In the scope, check ‘repo’ for full control of private repositories, and give a name for the token e.g. sourcetree access. Click ‘Generate token’ button at the bottom of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06NayeYi_Qn3YcFQVbldCA.png" /><figcaption>check ‘repo’ scope and click ‘Generate token’</figcaption></figure><p>3. The token is created, the token value is shown only once in this page, please copy it to secure place for later use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ETydWz8XqsiLNE_3mdvi6A.png" /><figcaption>the token value will be shown only once, copy to secure place for use later</figcaption></figure><h4><strong>Method 1: Use PAT token in the git clone URL:</strong></h4><p>One way to do authentication in a per-repository (URL) basis is to put it in the git clone URL in the repository settings. In Sourcetree, Go to Repository -&gt; Repository Settings, go to Remote tab, and click on the URL with remote you would like to connect (e.g. origin), modify the URL with the pattern:</p><p><a href="https://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@github.com/thomas-wu2/coding-problem.git">https://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@github.com/&lt;user-id&gt;/&lt;repository-name&gt;.git</a></p><p>(here in my example, my PAT is <a href="https://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@github.com/thomas-wu2/coding-problem.git">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</a> )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dkP4sQ5zBi6rdYQPso_sGg.png" /><figcaption>in Repo Setting, Adding PAT with @ followed by repo URL</figcaption></figure><p>Try pushing to Repo again, this time it completed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0Bm98seKAKp3tiqt2RdlA.png" /></figure><h4><strong>Method 2: Setting in Sourcetree Account, and valid for All Repositories</strong></h4><p>In method 1, we need to setup the repo URL per each repository. This time I would like to show a more convenient approach: to set once for the authentication and work for all repositories in the sourcetree.</p><p>The idea for Method 2 is based on the special usage of <a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line">Using token on the command line</a></p><p>First, we undo the repo setting in method 1. And then, I make sure it is not working by failing to push after making some commits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3bP0dd4I-nIbb2kzo7bYg.png" /><figcaption>Error Message when using Sourcetree to push to GitHub</figcaption></figure><p>With the authentication not working, now we can do the settings: Go to Sourcetree -&gt; Preferences -&gt; Account , click ‘add’. Then, in the Host dropdown choose ‘GitHub’; in AuthType dropdown choose ‘Basic’ (OAuth will not work); in Username, type your github account name; in <strong>Password</strong>, paste in the value of the Personal Access Token (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 in my case); in Protocol dropdown, choose HTTPS, click ‘Save’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yf-b9xOe-1EqJREXRz1RAQ.png" /></figure><p>An Account is created as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0s_R8JMeXe_0dDCK6cz-nA.png" /><figcaption>an account is created</figcaption></figure><p>Hooray! We successfully pushed the change!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rh0TzAbDQWXDCgPPzpXCuw.png" /></figure><h4><strong>Summary</strong></h4><p>In this article, I showed how to use PAT to connect to GitHub in Sourcetree.</p><p>Hope you enjoy and like it and I will have other sharing later.</p><h4><strong>Reference:</strong></h4><ol><li>Token Authentication Requirements for Git Operations : <a href="https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/">https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/</a></li></ol><p>2. Using token on the command line: <a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line">https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3702a29554d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/using-personal-access-token-in-sourcetree-to-connect-to-github-3702a29554d3">Using Sourcetree to connect to Github without password</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>