<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jing Xue</title>
    <description>The latest articles on DEV Community by Jing Xue (@jingxue).</description>
    <link>https://dev.to/jingxue</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F196473%2Fa9978cdc-7543-4d0a-b621-84a2a73f63a7.png</url>
      <title>DEV Community: Jing Xue</title>
      <link>https://dev.to/jingxue</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jingxue"/>
    <language>en</language>
    <item>
      <title>How to manage your local changes with git</title>
      <dc:creator>Jing Xue</dc:creator>
      <pubDate>Sun, 30 Jan 2022 05:32:23 +0000</pubDate>
      <link>https://dev.to/jingxue/how-to-manage-your-local-changes-with-git-6ke</link>
      <guid>https://dev.to/jingxue/how-to-manage-your-local-changes-with-git-6ke</guid>
      <description>&lt;p&gt;When we are working a project, often we need to make changes specific only to the local development environment we are working in. For example, point to some development or even personal database, or plug in our own credentials. Those are truly local only changes that we don't want to push to the remote repo or merge to any team level branches. On the other hand, we don't want to have to manually make these changes every time when we start working on a new feature branch, or even when we have just pulled from the remote repo.&lt;/p&gt;

&lt;p&gt;That is not a problem if the changes can be isolated to a local-only small file, or externalized into environment variables, because we can simply ignore the local configuration file in git.&lt;/p&gt;

&lt;p&gt;However, when circumstances don't allow local changes to be isolated or ignored, e.g. when it's a couple lines of changes in a large config file that's always tracked, or the project does not have the infrastructure to support environment specific configuration files, here is the workflow I often use:&lt;/p&gt;

&lt;p&gt;First I create the feature branch that will contain the commits implementing the feature, and will be pushed to the remote repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout -b my-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I create the local branch I will actually be working on. It will always be the feature branch plus the commit containing my local changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout -b my-feature-local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming &lt;code&gt;A&lt;/code&gt; is the current tip of &lt;code&gt;master&lt;/code&gt;, so this is the commit graph we are starting with:&lt;br&gt;
&lt;code&gt;A(master,my-feature,my-feature-local,HEAD)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I make whatever local changes necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git commit -am "LOCAL ONLY, DO NOT MERGE"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the graph looks like (where L is the "LOCAL ONLY" commit):&lt;br&gt;
&lt;code&gt;A(master,my-feature) - L(my-feature-local,HEAD)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I start hacking away at the actual task, to a good saving point. I may have created a couple more commits, B and C, containing actual coding for the new feature by now.&lt;br&gt;
&lt;code&gt;A(master,my-feature) - L - B - C(my-feature-local,HEAD)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I'm ready to push my work to the remote repo. But I don't want to push my local changes, so I do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git rebase -i my-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During the interactive rebase, I move the "LOCAL ONLY" commit to the top, so now the graph looks like:&lt;br&gt;
&lt;code&gt;A(master,my-feature) - B - C - L(my-feature-local,HEAD)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now I have moved the commits for implementing the feature to before the local commit, and onto the my-feature branch from which I'll actually do the push:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git rebase my-feature-local~ my-feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The graph at this point:&lt;br&gt;
&lt;code&gt;A(master) - B - C(my-feature,HEAD) - L(my-feature-local)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I'm ready to push:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push -u my-feature
$ git checkout my-feature-local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I'm back on my local branch. After I make some more commits, I just repeat the rebase-and-push process above.&lt;/p&gt;

&lt;p&gt;When I am working with other people on a feature, and we all push code to the &lt;code&gt;my-feature&lt;/code&gt; branch, there is just one extra step after every time I have pulled &lt;code&gt;my-feature&lt;/code&gt; from the remote repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git rebase my-feature my-feature-local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the cost of a couple of extra steps, this workflow has some advantages, compared to manual changes and/or git-ignore the files locally changed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changes, even though local, are still tracked and controlled properly by git. If the same files are changed as part of the implementation, by you or the rest of the team, git will merge them with your local changes during the rebase.&lt;/li&gt;
&lt;li&gt;No need to make the same manual changes again and again. Simply create a "local" branch on top of whichever branch you need to work on, cherry pick the "local only" commit over, and you are good to go.&lt;/li&gt;
&lt;li&gt;Local changes don't have to be limited to one commit. They can be organized into a series of "local" commits and allow more advanced use cases by manipulating the series in git.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Why You Don't Want to Use the S3 Referer Only Policy</title>
      <dc:creator>Jing Xue</dc:creator>
      <pubDate>Tue, 15 Dec 2020 19:02:50 +0000</pubDate>
      <link>https://dev.to/jingxue/why-you-don-t-want-to-use-the-s3-referer-only-policy-3d3l</link>
      <guid>https://dev.to/jingxue/why-you-don-t-want-to-use-the-s3-referer-only-policy-3d3l</guid>
      <description>&lt;p&gt;When you have an S3 bucket configured as a static web site, S3 allows you to restrict access to the objects in the bucket only when the requests came from a particular referrer, using &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html#example-bucket-policies-use-case-4"&gt;a condition in the bucket policy&lt;/a&gt;. For instance, in cases where you want visitors to get to some images only via links on your own web site.&lt;/p&gt;

&lt;p&gt;Well, the problem is, the "referrer" comes in the HTTP request header, so a client can fake any referrer and easily bypass this condition.  For example, with curl, it's as easy as &lt;code&gt;--referer http://url.to.the.referer.page&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I wish AWS would at least put up a warning next to the sample policy (linked to above), because it really just adds some false sense of security.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
    </item>
    <item>
      <title>My Tags Missing Upon Going Back to dev.to Front Page</title>
      <dc:creator>Jing Xue</dc:creator>
      <pubDate>Wed, 29 Jul 2020 23:12:57 +0000</pubDate>
      <link>https://dev.to/jingxue/my-tags-missing-upon-going-back-to-dev-to-front-page-14p2</link>
      <guid>https://dev.to/jingxue/my-tags-missing-upon-going-back-to-dev-to-front-page-14p2</guid>
      <description>&lt;p&gt;when I load up the dev.to front page, my tags show up correctly:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imgur.com/a/jRBETVe" rel="noopener noreferrer"&gt;https://imgur.com/a/jRBETVe&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I click into an article, read it, and come back out, my tags are gone:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imgur.com/a/jia09RY" rel="noopener noreferrer"&gt;https://imgur.com/a/jia09RY&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I reload the page, they are shown correctly again.&lt;/p&gt;

&lt;p&gt;Anybody else having this issue?&lt;/p&gt;

&lt;p&gt;(Also inline image in the post editor apparently doesn't work for me for some reason. When I put the image links above into the inline image tag like ![my tags](&lt;a href="https://imgur.com/a/jRBETVe%5C" rel="noopener noreferrer"&gt;https://imgur.com/a/jRBETVe\&lt;/a&gt;), I get broken links to res.cloudinary.com.)&lt;/p&gt;

</description>
      <category>meta</category>
    </item>
    <item>
      <title>List to Tuple: a Little Compilation Optimization</title>
      <dc:creator>Jing Xue</dc:creator>
      <pubDate>Sat, 04 Jul 2020 23:17:16 +0000</pubDate>
      <link>https://dev.to/jingxue/list-to-tuple-a-little-compilation-optimization-1gn0</link>
      <guid>https://dev.to/jingxue/list-to-tuple-a-little-compilation-optimization-1gn0</guid>
      <description>&lt;p&gt;I was reading Julien Maury's &lt;a href="https://dev.to/jmau111/python-pro-tips-27cb"&gt;Python pro tips&lt;/a&gt;, and ran into this code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if myvar in [9,1,7]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I was about to leave a comment to suggest using a tuple instead, because instinctively you would think tuples should be faster than lists, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if myvar in (9,1,7)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And then I decided not to trust my instinct and take a look at the bytecode first. Well, what do you know... both code compiles to exactly the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 LOAD_FAST                0 (myvar)
2 LOAD_CONST               1 ((9, 1, 7))
4 COMPARE_OP               6 (in)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So the compiler is smart enough to realize that even though I am creating a mutable list, I won't actually make any changes to it, and will use it only once, so it converts the list to a tuple.&lt;/p&gt;

&lt;p&gt;Taking one step further, I changed the code to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;l = [9, 1, 7]
if myvar in l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the compiler creates a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 LOAD_CONST               1 (9)
2 LOAD_CONST               2 (1)
4 LOAD_CONST               3 (7)
6 BUILD_LIST               3
8 STORE_FAST               1 (l)

10 LOAD_FAST                0 (myvar)
12 LOAD_FAST                1 (l)
14 COMPARE_OP               6 (in)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Although I suppose one could argue that in this case the compiler should still have detected that &lt;code&gt;l&lt;/code&gt; is never changed, and converted it to a tuple.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Missing 'distutils.util' after upgrading from Python 3.7 to 3.8</title>
      <dc:creator>Jing Xue</dc:creator>
      <pubDate>Mon, 25 May 2020 21:08:11 +0000</pubDate>
      <link>https://dev.to/jingxue/missing-distutils-util-after-upgrading-from-python-3-7-to-3-8-5adg</link>
      <guid>https://dev.to/jingxue/missing-distutils-util-after-upgrading-from-python-3-7-to-3-8-5adg</guid>
      <description>&lt;p&gt;I recently upgraded to Pop OS(essentially Ubuntu) 20.04, which had Python upgraded to 3.8. My ongoing AWS Lambda project build is broken right away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Running PythonPipBuilder:ResolveDependencies

Build Failed
Error: PythonPipBuilder:ResolveDependencies - Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "/usr/lib/python3/dist-packages/pip/_internal/main.py", line 14, in main
    from pip._internal.utils.entrypoints import _wrapper
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/entrypoints.py", line 3, in &amp;lt;module&amp;gt;
    from pip._internal.cli.main import main
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in &amp;lt;module&amp;gt;
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in &amp;lt;module&amp;gt;
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in &amp;lt;module&amp;gt;
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in &amp;lt;module&amp;gt;
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All the solutions from googling the error message seems to be "make sure to run 'apt sudo install python3-distutils'. However, I do have &lt;code&gt;python3-distutils&lt;/code&gt; installed under &lt;code&gt;/usr/lib/python3.8&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I noticed that the traceback above was produced by pip from &lt;code&gt;python3/dist-packages&lt;/code&gt;, however I do have a later version of pip installed under my &lt;code&gt;.local/lib/python3.8/site-packages&lt;/code&gt;. So why did that not get picked up? The two symptoms together made me think that when SAM runs pip, it's not using the Python 3.8 search path which would contain all the 3.8 packages.&lt;/p&gt;

&lt;p&gt;After a couple of hours of pouring through SAM source code and debugging, it turns out SAM was using python 3.7 to build my project, including running pip in, because when I upgraded I only remembered to update &lt;code&gt;Pipfile&lt;/code&gt; to use '3.8', but (completely) forgot to update the '3.7' references in the CloudFormation template file.&lt;/p&gt;

&lt;p&gt;While I should obviously take the bulk of the blame for this silly trip, it would have helped if SAM could somehow print something more obvious then the error message I got.&lt;/p&gt;

</description>
      <category>python</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
