<?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: Bartłomiej Stefański</title>
    <description>The latest articles on DEV Community by Bartłomiej Stefański (@bmstefanski).</description>
    <link>https://dev.to/bmstefanski</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%2F192049%2F7aba7a6c-719a-45b4-8f09-b2aad1b4d474.jpg</url>
      <title>DEV Community: Bartłomiej Stefański</title>
      <link>https://dev.to/bmstefanski</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bmstefanski"/>
    <language>en</language>
    <item>
      <title>🎒 Bringing Back Gitk on macOS</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Tue, 28 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/bringing-back-gitk-on-macos-2g37</link>
      <guid>https://dev.to/bmstefanski/bringing-back-gitk-on-macos-2g37</guid>
      <description>&lt;p&gt;In today's blog post, let's talk about Git GUIs! As someone who has always stuck to the command line and git aliases for Git adventures, it may be surprising to find out there's an instance where even I can't resist the charm of a good ol' GUI! And that's when casually browsing the Git tree to check out the changes made and where they've been sprinkled.&lt;/p&gt;

&lt;p&gt;In the past, the built-in Git tool called gitk was used for this purpose. But it seems like in the latest versions of macOS, it's not included by default, so a little extra effort is needed to get it back.&lt;/p&gt;

&lt;p&gt;To bring &lt;code&gt;gitk&lt;/code&gt; back into action, just run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
brew update 

brew install git

brew install git-gui

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà! The &lt;code&gt;gitk&lt;/code&gt; command should be up and running, ready to help navigate that Git tree with ease.&lt;/p&gt;

</description>
      <category>unix</category>
    </item>
    <item>
      <title>🤖 Installing Pip on macOS</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Mon, 27 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/installing-pip-on-macos-inc</link>
      <guid>https://dev.to/bmstefanski/installing-pip-on-macos-inc</guid>
      <description>&lt;p&gt;In this blog post, I'll discuss a situation where I wanted to install a module using pip (the package installer for Python) but encountered an unexpected error: zsh: command not found: pip. This was quite surprising, as I assumed that Python, along with pip, was installed by default on macOS.&lt;/p&gt;

&lt;p&gt;As it turns out, while Python is indeed installed by default on macOS, pip is not, and you'll need to download it separately. Additionally, the downloaded version is &lt;code&gt;pip3&lt;/code&gt;, so you'll have to create an alias for &lt;code&gt;pip&lt;/code&gt; since some tools or documentation still reference the older command.&lt;/p&gt;

&lt;p&gt;To accomplish this, you can use the following one-liner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python3 -m ensurepip &amp;amp;&amp;amp; echo 'alias pip=pip3' &amp;gt;&amp;gt;~/.bash\_profile &amp;amp;&amp;amp; source ~/.bash\_profile

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installs pip directly from the Python3 library&lt;/li&gt;
&lt;li&gt;Adds an alias &lt;code&gt;pip -&amp;gt; pip3&lt;/code&gt; to your &lt;code&gt;~/.bash_profile&lt;/code&gt;, ensuring that you don't have to recreate the alias every time you restart your computer&lt;/li&gt;
&lt;li&gt;Reloads the &lt;code&gt;~/.bash_profile&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After running this command, you should be able to execute the pip command without any issues.&lt;/p&gt;

</description>
      <category>unix</category>
    </item>
    <item>
      <title>🥴 Resolving a JSON Import Issue with Linaria</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Sun, 26 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/resolving-a-json-import-issue-with-linaria-i82</link>
      <guid>https://dev.to/bmstefanski/resolving-a-json-import-issue-with-linaria-i82</guid>
      <description>&lt;p&gt;Recently, I faced a bug related to the Linaria library that prevented my page from building. I stumbled upon this issue when attempting to import JSON files in a component where Linaria was utilized. Instead of processing the JSON file correctly, Linaria treated it like a JavaScript file, leading to parsing errors. I attempted to exclude all JSON files in the Linaria configuration using a simple regex, but it didn't seem to work properly.&lt;/p&gt;

&lt;p&gt;Here's a screenshot of the exact error I encountered: (screenshot here).&lt;/p&gt;

&lt;p&gt;Before fixing the issue, my configuration looked like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FP2YTcPO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fresolving-json-import-issue-linaria-library%252Fscreenshot.png%26w%3D1200%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FP2YTcPO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fresolving-json-import-issue-linaria-library%252Fscreenshot.png%26w%3D1200%26q%3D75" alt="Linaria bug" width="800" height="163"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const shaker = require('@linaria/shaker').default;

module.exports = {

 rules: [

{

 test:/.json/,

 action: "ignore"

},

{

 test: /node\_modules/,

 action: 'ignore'

},

{

 action: shaker 

},

]

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, I'm ignoring all the .json files and node_modules. Additionally, I have the shaker plugin added as the last rule.&lt;/p&gt;

&lt;p&gt;After some debugging and setting breakpoints in the code, I discovered that the issue was being caused by the shaker plugin. Under the hood, the rules are applied in reverse order, and the order matters. Since I set the shaker as the last rule, it ran as the first one. As a result, it didn't respect the other rules and failed to ignore the files I intended to exclude, causing the issue.&lt;/p&gt;

&lt;p&gt;To fix this problem, I simply needed to place the shaker action as the first rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const shaker = require('@linaria/shaker').default;

module.exports = {

 rules: [

{

 action: shaker 

},

{

 test:/.json/,

 action: "ignore"

},

{

 test: /node\_modules/,

 action: 'ignore'

},

]

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By placing the shaker action as the first rule, I was able to resolve the issue and successfully exclude the JSON files and node_modules from processing.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>😎 Unlocking Next.js Benefits: No SSR? No Problem!</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Wed, 22 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/unlocking-nextjs-benefits-no-ssr-no-problem-4l12</link>
      <guid>https://dev.to/bmstefanski/unlocking-nextjs-benefits-no-ssr-no-problem-4l12</guid>
      <description>&lt;p&gt;Next.js is a powerful framework built on top of React.js, offering numerous advantages over using React.js on its own.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;A common misconception in the industry is that if your application doesn't require Server Side Rendering (SSR), then you shouldn't use Next.js, which is simply not true. Here are some of the beneficial features Next.js offers that can enhance app development:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Granular Error Handling&lt;/strong&gt; at the component level in the app directory&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSR (Server Side Rendering)&lt;/strong&gt; enables moving some heavy logic to the server without involving the backend team, speeding up development. SSR and Static Site Generation (SSG) also prevent Layout Shifts and Loading Screens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSG (Static Site Generation)&lt;/strong&gt; improves page transitions even when SEO isn't a crucial factor. You can easily switch between SSG and client-side pages with minimal code changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Splitting&lt;/strong&gt; is supported out of the box, with page-based splitting as the default behavior, unlike bare React. This can be achieved using &lt;code&gt;next/dynamic&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Next.js provides a &lt;strong&gt;production-ready, battle-tested Webpack config&lt;/strong&gt; that is open for extensions, ensuring optimal performance and short build times.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;next/image&lt;/code&gt; component, co-created with Google developers, &lt;strong&gt;optimizes image loading and display&lt;/strong&gt; , following best practices.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;next/font&lt;/code&gt; module &lt;strong&gt;prevents Layout Shifts&lt;/strong&gt; and enhances developer experience by handling 95% of the work, while ensuring top-notch performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Routes&lt;/strong&gt; allow moving heavy logic to the server and work best on AWS Lambda, acting as simple, small, independent Node servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Opinionated routing&lt;/strong&gt; creates a consistent app architecture, making it easier to understand across millions of apps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prefetching links&lt;/strong&gt; speeds up subsequent requests by prefetching links when hovered or visible in the viewport, which is difficult to achieve in bare React.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layouts&lt;/strong&gt; contribute to a consistent and clean architecture in the app directory, which is hard to achieve in bare React without complex abstraction.&lt;/li&gt;
&lt;li&gt;Most common &lt;strong&gt;polyfills&lt;/strong&gt; are included by default, ensuring compatibility across various browsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Advanced i18n support&lt;/strong&gt; allows for flexible i18n features without altering routing structures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, Next.js offers numerous performance-related features and accelerates development without sacrificing flexibility. Contrary to requiring more code or configuration, Next.js simplifies development. Configuring React (especially Webpack) to match Next.js's capabilities is no easy task, and every library in the React ecosystem is compatible with Next.js.&lt;/p&gt;

</description>
      <category>nextjsperformancedev</category>
    </item>
    <item>
      <title>🌌 Fixing Kubernetes OpenLens Blank Screen Issue</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Wed, 22 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/fixing-kubernetes-openlens-blank-screen-issue-200i</link>
      <guid>https://dev.to/bmstefanski/fixing-kubernetes-openlens-blank-screen-issue-200i</guid>
      <description>&lt;p&gt;I recently attempted to set up OpenLens to work with &lt;code&gt;kubectl&lt;/code&gt;, but all I encountered was a blank white screen. Despite having everything configured correctly and being able to list all the clusters, the connection seemed established. To verify if you have a similar connection, you can try running this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
$ kubectl get pods

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected output of this command should display a list of your available pods. If the connection is established correctly, you'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
NAME READY STATUS RESTARTS AGE 

your-pod-name-11/1 Running 01d 

your-pod-name-21/1 Running 01d 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I soon discovered that OpenLens is built using Electron and React, which led me to a simple solution. &lt;strong&gt;By pressing &lt;code&gt;cmd + R&lt;/code&gt; to refresh the view, I managed to fix the issue, and the clusters view appeared as expected&lt;/strong&gt;. This quick refresh can be a helpful trick if you ever find yourself facing the same problem when working with OpenLens and kubectl.&lt;/p&gt;

</description>
      <category>devops</category>
    </item>
    <item>
      <title>🐯 Opening New Tabs on Mobile Devices with JavaScript, Safari-Friendly</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Tue, 21 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/opening-new-tabs-on-mobile-devices-with-javascript-safari-friendly-4d9l</link>
      <guid>https://dev.to/bmstefanski/opening-new-tabs-on-mobile-devices-with-javascript-safari-friendly-4d9l</guid>
      <description>&lt;p&gt;I recently encountered a situation where I needed to open a new tab on mobile devices using JavaScript. Initially, I used the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
window.open(url, '\_blank');

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It worked well, but when I tested it on Safari, I quickly discovered that Safari's security policies prevent opening a new tab within an asynchronous function, such as inside a promise. To address this issue, I had to find a workaround.&lt;/p&gt;

&lt;p&gt;The most effective workaround I found involved the following steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
var windowReference = window.open();

myService.getUrl().then(function(url) {

 windowReference.location = url;

});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key here is to declare a variable with a reference to the &lt;code&gt;window.open()&lt;/code&gt; object outside of the asynchronous function. Then, reassign the location to the desired URL where you previously called the window.open function.&lt;/p&gt;

</description>
      <category>devrel</category>
    </item>
    <item>
      <title>🛠️ Quickly Launch VSCode from Terminal as Admin (2023)</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Tue, 21 Mar 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/quickly-launch-vscode-from-terminal-as-admin-2023-361o</link>
      <guid>https://dev.to/bmstefanski/quickly-launch-vscode-from-terminal-as-admin-2023-361o</guid>
      <description>&lt;p&gt;I wanted to utilize the code . command in the terminal to directly open VSCode in my desired directory. To achieve this, I navigated to the VSCode Command Palette and chose &lt;code&gt;&amp;gt;Shell Command: Install 'code' command in PATH&lt;/code&gt;. However, I encountered an error message stating "permissions denied" and that administrator access was required for this action.&lt;/p&gt;

&lt;p&gt;After some searching, I discovered several solutions to run VSCode as an administrator. The following command was the only one that worked for me:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
$ sudo /Applications/Visual Studio Code.app/Contents/MacOS/Electron; exit

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon executing this command, VSCode should open, allowing you to select the &lt;code&gt;&amp;gt;Shell Command: Install 'code' command in PATH&lt;/code&gt; option.&lt;/p&gt;

</description>
      <category>devrel</category>
    </item>
    <item>
      <title>🕹️ How to prettify your cat command</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Fri, 24 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/how-to-prettify-your-cat-command-4lnm</link>
      <guid>https://dev.to/bmstefanski/how-to-prettify-your-cat-command-4lnm</guid>
      <description>&lt;p&gt;I have always used the &lt;code&gt;cat&lt;/code&gt; command to quickly preview some files or to copy the contents of them to a clipboard. The second part was always working great, but previewing a let's say JavaScript file or RC file was painful, because of the lack of syntax highlighting.&lt;/p&gt;

&lt;p&gt;I was too lazy to search for solutions, but my colleague recently showed me something called &lt;a href="https://github.com/sharkdp/bat"&gt;bat&lt;/a&gt;, which is a cat, but on steroids. Here's a little preview of what it looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ijf77Doz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fhow-to-prettify-your-cat-unix-command%252Fbat-preview.png%26w%3D1200%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ijf77Doz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fhow-to-prettify-your-cat-unix-command%252Fbat-preview.png%26w%3D1200%26q%3D75" alt="Preview of bat command" width="800" height="514"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h3 id="installation-and-theme-setup"&gt;Installation and theme setup&lt;/h3&gt;

&lt;p&gt;You can install it through brew, just like this:&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ brew &lt;/span&gt;&lt;span&gt;install&lt;/span&gt;&lt;span&gt; bat&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;and if you don't like the default theme, you can choose some that are installed out of the box or &lt;a href="https://github.com/sharkdp/bat#adding-new-themes"&gt;install the custom one&lt;/a&gt;. I decided to use Nord, which was already installed, here's how I did it:&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;mkdir&lt;/span&gt;&lt;span&gt; ~/.config/bat &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;sudo&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;vim&lt;/span&gt;&lt;span&gt; ~/.config/bat/config &lt;/span&gt;&lt;span&gt;# remember to run it in sudo mode&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;then paste this line into the config&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;--theme&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;"Nord"&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;and exit vim with &lt;code&gt;:wq&lt;/code&gt; and you're done!&lt;/p&gt;

&lt;p&gt;P.S you can still copy the contents of the file with &lt;code&gt;bat something.txt | pbcopy&lt;/code&gt;! &lt;span&gt;🤠&lt;/span&gt;&lt;/p&gt;

</description>
      <category>unix</category>
    </item>
    <item>
      <title>🛡️ Prevent Chrome from redirecting your HTTP localhost to HTTPS</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Tue, 21 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/prevent-chrome-from-redirecting-your-http-localhost-to-https-206g</link>
      <guid>https://dev.to/bmstefanski/prevent-chrome-from-redirecting-your-http-localhost-to-https-206g</guid>
      <description>&lt;p&gt;Every time I tried setting up custom &lt;code&gt;/etc/hosts&lt;/code&gt; for local development, chrome kept redirecting my service from HTTP to HTTPS.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;Probably because there was already an existing website with the same hostname and SSL that I previously visited.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;To fix that you need to go to &lt;code&gt;chrome://net-internals/#hsts&lt;/code&gt; and put your service's URL in the input located under the &lt;strong&gt;Delete domain security policies&lt;/strong&gt; section. Click delete and voilà!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mqmAqcjR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fprevent-chrome-from-redirecting-your-http-localhost-to-https%252Fdns-purge.png%26w%3D1200%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mqmAqcjR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://bstefanski.com/_next/image%3Furl%3D%252Fposts%252Fprevent-chrome-from-redirecting-your-http-localhost-to-https%252Fdns-purge.png%26w%3D1200%26q%3D75" alt="Google chrome net internals page" width="800" height="261"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;/small&gt;&lt;/p&gt;

</description>
      <category>devrel</category>
    </item>
    <item>
      <title>🩹 Generating and applying git patches</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Mon, 20 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/generating-and-applying-git-patches-3a2h</link>
      <guid>https://dev.to/bmstefanski/generating-and-applying-git-patches-3a2h</guid>
      <description>&lt;p&gt;Git has a feature called &lt;a href="https://git-scm.com/book/id/v2/Appendix-C%3A-Git-Commands-Patching"&gt;patches&lt;/a&gt; that is great for quickly delivering stuff to other teams when there's a fire happening.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;It might not be the most elegant solution, since sending the code in a form of file doesn't sound too safe, but hey, it works and does the job!&lt;/p&gt;

&lt;p&gt;In the nice happy world you would just add another remote and cherry pick stuff from one to another.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;This sounds solid, but sometimes takes quite a while, especially if you want to push to some new repository, on a different git provider and you need to setup a new SSH keys just for one pull and one push.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;Doesn't seem pragmatic to me. In such cases, I tend to just go with the patches. There are two ways of patching that you can choose from.&lt;/p&gt;

&lt;h3 id="multiple-patch-files"&gt;Multiple patch files&lt;/h3&gt;

&lt;p&gt;The first one will generate multiple patch files. One per commit. Here's how you do this:&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;git&lt;/span&gt;&lt;span&gt; format-patch -3&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It will create a patch files from the last three commits. And then apply it with (not sure what &lt;code&gt;am&lt;/code&gt; acronym means, but I always translate it to &lt;code&gt;apply many&lt;/code&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;git&lt;/span&gt;&lt;span&gt; am&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Git will automatically scan for those files and apply them in correct order.&lt;/p&gt;
&lt;h3 id="single-patch-file"&gt;Single patch file&lt;/h3&gt;
&lt;p&gt;Or the second way, my favorite, is squashing everything into one patch file, like so:&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;git&lt;/span&gt;&lt;span&gt; format-patch -3 --stdout &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; your-patch-name.patch&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;and then applying it with&lt;/p&gt;

&lt;pre&gt;&lt;span&gt;&lt;span&gt;$ &lt;/span&gt;&lt;span&gt;git&lt;/span&gt;&lt;span&gt; apply your-patch-name.patch&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>🤖 Quickly scrape tweets without API or headless browser</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Mon, 20 Feb 2023 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/quickly-scrape-tweets-without-api-or-headless-browser-iad</link>
      <guid>https://dev.to/bmstefanski/quickly-scrape-tweets-without-api-or-headless-browser-iad</guid>
      <description>&lt;p&gt;Writing a scraping tool is a boring process, you have to use headless browser or an API (but that wouldn't be called scraping, would it?).&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;It takes a lot of time to develop and run such a tool. Whenever possible, it's best to avoid writing a standalone application for that.&lt;/p&gt;

&lt;p&gt;My goal was to gather links to some tweets that were listed under Twitter's search page. I went to the search page, put this little snippet that I wrote in the DevTools and started scrolling until I was satisfied with the results.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;It will probably stop working in the near future, since it is fully based on text content of some DOM nodes, but you can of course take a look at Twitter's DOM and modify it to your needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const links = new Set();

window.addEventListener('scroll', () =&amp;gt;

[...document.querySelector('[aria-label="Timeline: Search timeline"').children[0].children].forEach((el) =&amp;gt; {

const singleLink = el.querySelectorAll('a')[3];

if (singleLink) {

 links.add(singleLink.getAttribute('href'));

}

}),

);

console.log(links);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>undefined</category>
    </item>
    <item>
      <title>🔑 Open ID Connect vs OAuth2</title>
      <dc:creator>Bartłomiej Stefański</dc:creator>
      <pubDate>Mon, 12 Dec 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/bmstefanski/open-id-connect-vs-oauth2-223e</link>
      <guid>https://dev.to/bmstefanski/open-id-connect-vs-oauth2-223e</guid>
      <description>&lt;p&gt;OpenID Connect is a protocol that allows you to authenticate your users in a secure, standardized, and centralized manner. It also provides identity management. It relies on &lt;strong&gt;Identity Providers&lt;/strong&gt; (the official term for that is &lt;strong&gt;Authorization Server&lt;/strong&gt; ) to handle authentication securely and verify the identities.&lt;/p&gt;

&lt;p&gt;I was wondering why everyone says I can't use OAuth2 for authentication. How is that not possible? I have been doing that for years and after those years of unsecured authentication, it finally clicked.&lt;br&gt;&lt;br&gt;
&amp;lt;!-- --&amp;gt;It can be used for authentication and it still is by a lot of small services with bad engineering practices. There's one major problem with using it, it is not safe. You can save the Access Token returned from Resource Server and act like it's proof that the user is authenticated, but it's not. The user could lo-gin into some shady website, and leave their (user) access token there. The token could get stolen or exposed and then possibly used to authenticate the user in your app.&lt;/p&gt;

&lt;p&gt;With OIDC you get ID Token in a form of JWT (in a standardized way). The token contains &lt;strong&gt;registered claims&lt;/strong&gt; that inform you about when and where the token was issued, and this gives you proof that the Token is valid and the user is authenticated.&lt;/p&gt;

&lt;h2 id="entity-vs-identity"&gt;Entity vs Identity&lt;/h2&gt;

&lt;p&gt;An entity is a thing that exists as an individual unit while identity is a set of attributes (called &lt;strong&gt;Claims&lt;/strong&gt;) that you can use to distinguish this entity within a context. For example, you are an entity, but not an identity. Your attributes, so for example, name, age, or your mother's name are the attributes that create your identity.&lt;br&gt;
An entity can have more than one identity that will have different attributes depending on the context. When you go to the bank, they perceive you differently than your mother does. That means, you have multiple identities and you can use the one that is matching the context.&lt;/p&gt;
&lt;h2 id="authorization-vs-authentication"&gt;Authorization vs Authentication&lt;/h2&gt;
&lt;p&gt;This is quite simple, but most articles make it sound like a complicated thing. So, authenticating means you're trying to verify that the identity belongs to you. Whereas authorizing refers to you using the identity to ask if you can access some resource or ask what actions you can do. You can use authentication for authorization, but not the other way around. &lt;/p&gt;
&lt;h2 id="oidc-vs-oauth2"&gt;OIDC vs OAuth2&lt;/h2&gt;
&lt;p&gt;Many features of OIDC match OAuth2 features because OIDC is a superset of OAuth2, that adds authentication to the mix.&lt;/p&gt;

&lt;p&gt;Typical OAuth2 flow would look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user (&lt;strong&gt;Resource Owner&lt;/strong&gt;) clicks the button on your page to authorize the application (&lt;strong&gt;Client&lt;/strong&gt;) to post videos on their Youtube channel, on their behalf.&lt;/li&gt;
&lt;li&gt;It redirects the user to Youtube API (&lt;strong&gt;Resource Server&lt;/strong&gt;) to ask if they agree to grant the application access to your Youtube channel.&lt;/li&gt;
&lt;li&gt;If the user agrees, the Resource Server will redirect back to the Client with a token called &lt;strong&gt;Access Token&lt;/strong&gt; that can be used for authorization. Some Resource Providers, like Facebook, return a short-lived token that you have to exchange for a long-lived one. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can't use that &lt;strong&gt;Access Token&lt;/strong&gt; to authenticate or log in to their Youtube channel, but you can use it to perform some actions. With OIDC, the flow would look very similar, but instead of &lt;strong&gt;Access Token&lt;/strong&gt;, you would get &lt;strong&gt;ID Token&lt;/strong&gt; containing information about your entity.&lt;/p&gt;

&lt;p&gt;Sources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.thread-safe.com/2012/01/problem-with-oauth-for-authentication.html" rel="noopener noreferrer"&gt;Why you shouldn't use OAuth2 for authentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.intothesymmetry.com/2014/04/oauth-2-how-i-have-hacked-facebook.html" rel="noopener noreferrer"&gt;Facebook OAuth2 authentication dangerous bug&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://auth0.com/resources/ebooks/the-openid-connect-handbook" rel="noopener noreferrer"&gt;OpenID Connect Handbook by Auth0&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>oauth2openidoidcauth</category>
    </item>
  </channel>
</rss>
