<?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: Amit Misra</title>
    <description>The latest articles on DEV Community by Amit Misra (@amitmisra16).</description>
    <link>https://dev.to/amitmisra16</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%2F524555%2F42880941-2957-48d3-83ed-33435c0e471f.jpeg</url>
      <title>DEV Community: Amit Misra</title>
      <link>https://dev.to/amitmisra16</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amitmisra16"/>
    <language>en</language>
    <item>
      <title>Using DisplayLink Breaks Apple Watch Unlock—But This Setting Fixes It</title>
      <dc:creator>Amit Misra</dc:creator>
      <pubDate>Wed, 17 Dec 2025 13:21:54 +0000</pubDate>
      <link>https://dev.to/amitmisra16/using-displaylink-breaks-apple-watch-unlock-but-this-setting-fixes-it-5hlk</link>
      <guid>https://dev.to/amitmisra16/using-displaylink-breaks-apple-watch-unlock-but-this-setting-fixes-it-5hlk</guid>
      <description>&lt;p&gt;If you use a dual-monitor setup on your Mac with a DisplayLink adapter and rely on your Apple Watch to unlock your system, this might save you some frustration.&lt;/p&gt;

&lt;p&gt;I’ve always found unlocking my Mac with my Apple Watch incredibly convenient. But after upgrading my desk setup to dual monitors using a DisplayLink docking station, that convenience disappeared overnight.&lt;/p&gt;

&lt;p&gt;It turns out that because of how DisplayLink works, macOS interprets the setup as if the screen is being shared. And when macOS thinks you’re screen-sharing, it automatically disables Apple Watch unlock for security reasons. Fair enough—but definitely inconvenient.&lt;/p&gt;

&lt;p&gt;At first, it felt like I had to choose between keeping my dual-monitor setup or keeping the Apple Watch unlock feature. But after reading the login-screen error message more closely—specifically the part that said unlock is blocked while screen sharing—I realized there was a workaround.&lt;/p&gt;

&lt;p&gt;💡 The Fix&lt;/p&gt;

&lt;p&gt;All I needed to do was adjust my Lock Screen settings so that:&lt;br&gt;
    • The display turns off (on battery and on power) before or at the same time as&lt;br&gt;
    • “Require password after screen saver begins or display is turned off.”&lt;/p&gt;

&lt;p&gt;In other words, I aligned the timers so that my Mac simply turns the display off rather than triggering the screen saver. And just like that—problem solved. Apple Watch unlock works again, without sacrificing the dual-monitor setup.&lt;/p&gt;

&lt;p&gt;The trade-off? My screen saver no longer runs. But personally, that’s a small price to pay.&lt;/p&gt;

&lt;p&gt;Hope this helps someone running into the same issue. Cheers!&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>tooling</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Install OpenCV for Java using brew on Ubuntu</title>
      <dc:creator>Amit Misra</dc:creator>
      <pubDate>Sun, 20 Nov 2022 23:47:00 +0000</pubDate>
      <link>https://dev.to/amitmisra16/install-opencv-for-java-using-brew-on-ubuntu-2njl</link>
      <guid>https://dev.to/amitmisra16/install-opencv-for-java-using-brew-on-ubuntu-2njl</guid>
      <description>&lt;p&gt;Learning new stuff over the weekend is something we all do and this weekend, I started exploring OpenCV. What follows next is my walkthrough for setting up my system with OpenCV 4.6.0 on Ubnutu 20.04.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The installation process wasn't that straightforward, specially if you want to use Java as your programming language of choice. There are a few documentation around but I ended up taking a different route which worked like charm without any major issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup &lt;code&gt;brew&lt;/code&gt; on ubuntu
&lt;/h2&gt;

&lt;p&gt;This step is trivial all you need to do is follow the steps mentioned on their &lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;website&lt;/a&gt; - &lt;br&gt;
&lt;code&gt;/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the installation completes the script will ask you to execute the following commands in the terminal. Please be advised, these commands are not &lt;strong&gt;optional&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo '# Set PATH, MANPATH, etc., for Homebrew.' &amp;gt;&amp;gt; $HOME/.zprofile
$ echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' &amp;gt;&amp;gt; $HOME/.zprofile
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

## Additional commands
$ sudo apt-get install build-essential
$ brew install gcc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally if you are using &lt;code&gt;zsh&lt;/code&gt; like I am, add the following line to your &lt;code&gt;$HOME/.zshrc&lt;/code&gt; file - &lt;code&gt;source $HOME/.zprofile&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install &lt;code&gt;openCV&lt;/code&gt; using &lt;code&gt;brew&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Let's start by installing &lt;code&gt;ant&lt;/code&gt; using &lt;code&gt;brew&lt;/code&gt; like so - &lt;code&gt;brew install ant&lt;/code&gt;. This is mandatory in case you want the final installation step to generate the &lt;code&gt;opencv-java460.jar&lt;/code&gt; file and the associated shared library.&lt;/li&gt;
&lt;li&gt;Next execute the following command and update the flag &lt;code&gt;-DBUILD_opencv_java&lt;/code&gt; to be &lt;code&gt;ON&lt;/code&gt; (&lt;a href="https://medium.com/@nicomor/installing-opencv-4-on-macos-d0cc33e5618e" rel="noopener noreferrer"&gt;source&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;You can check if your system is ready for &lt;code&gt;opencv&lt;/code&gt; to be installed by executing the following command - &lt;code&gt;brew doctor&lt;/code&gt;. The output should look something like so, which is understandable as we changed the flag in the last step
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew doctor       
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have uncommitted modifications to Homebrew/homebrew-core.
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
  cd /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core &amp;amp;&amp;amp; git stash &amp;amp;&amp;amp; git clean -d -f

Uncommitted files:
   M Formula/opencv.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally execute the command to install &lt;code&gt;openCV&lt;/code&gt; on your system like so - &lt;code&gt;brew install opencv --build-from-source&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Checking the installation
&lt;/h2&gt;

&lt;p&gt;Once the install command finishes, you should be all good. Check the output of the command &lt;code&gt;brew info opencv&lt;/code&gt; it should look something like so -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew info opencv                       
==&amp;gt; opencv: stable 4.6.0 (bottled)
Open source computer vision library
https://opencv.org/
/home/linuxbrew/.linuxbrew/Cellar/opencv/4.6.0_1 (865 files, 324MB) *
  Built from source on 2022-11-20 at 18:33:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/opencv.rb
License: Apache-2.0
==&amp;gt; Dependencies
Build: cmake ✔, pkg-config ✔
Required: ceres-solver ✔, eigen ✔, ffmpeg ✔, glog ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, libtiff ✔, numpy ✔, openblas ✔, openexr ✔, openjpeg ✔, protobuf ✔, python@3.10 ✔, tbb ✔, vtk ✔, webp ✔, zlib ✔
==&amp;gt; Analytics
install: 16,116 (30 days), 47,026 (90 days), 194,148 (365 days)
install-on-request: 15,595 (30 days), 45,590 (90 days), 187,137 (365 days)
build-error: 96 (30 days)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirm you have the necessary shared library and jar file created under the installation folder like so -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls /home/linuxbrew/.linuxbrew/Cellar/opencv/4.6.0_1/share/java/opencv4 
libopencv_java460.so  opencv-460.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prep &lt;code&gt;opencv-java460.jar&lt;/code&gt; for &lt;code&gt;maven&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Once you have the final &lt;code&gt;opencv_java460.jar&lt;/code&gt;, you can install it to your local repository for development purposes. This ensures you are not making multiple copies of the jar file or referring to an external jar with unusual path for &lt;code&gt;linuxbrew&lt;/code&gt; home directory. I used the following command for the same -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn org.apache.maven.plugins:maven-install-plugin:3.1.0:install-file  -Dfile=/home/linuxbrew/.linuxbrew/Cellar/opencv/4.6.0_1/share/java/opencv4/opencv-460.jar \
-DgroupId=org.opencv \
-DartifactId=opencv-java \
-Dversion=4.6.0_1 \
-Dpackaging=jar \
-DlocalRepositoryPath=$HOME/.m2/repository
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the above command should something like so -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
...
[INFO] pom.xml not found in opencv-460.jar
[INFO] Installing /home/linuxbrew/.linuxbrew/Cellar/opencv/4.6.0_1/share/java/opencv4/opencv-460.jar to $HOME/.m2/repository/org/opencv/opencv-java/4.6.0_1/opencv-java-4.6.0_1.jar
[INFO] Installing /tmp/mvninstall7616729450445116135.pom to $HOME/.m2/repository/org/opencv/opencv-java/4.6.0_1/opencv-java-4.6.0_1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.325 s
[INFO] Finished at: 2022-11-20T18:41:42-05:00
[INFO] ------------------------------------------------------------------------
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Post this you can add &lt;code&gt;opencv-java&lt;/code&gt; as a dependency in your favorite project like so -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.opencv&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;opencv-java&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;4.6.0_1&amp;lt;/version&amp;gt;
&amp;lt;dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;p&gt;During the installation I ran into an issue with &lt;code&gt;too many open files&lt;/code&gt; when I executed the &lt;code&gt;brew install opencv --build-from-source&lt;/code&gt; command. In order to resolve that I have to increase the &lt;code&gt;ulimit&lt;/code&gt; like so - &lt;code&gt;ulimit -n 2048&lt;/code&gt;. &lt;/p&gt;

</description>
      <category>opencv</category>
      <category>ubuntu</category>
      <category>brew</category>
      <category>java</category>
    </item>
    <item>
      <title>Install Zorin 15.3 OS on Macbook Pro (Mid 2010)</title>
      <dc:creator>Amit Misra</dc:creator>
      <pubDate>Tue, 03 May 2022 21:11:49 +0000</pubDate>
      <link>https://dev.to/amitmisra16/install-zorin-153-os-on-macbook-pro-mid-2010-4iai</link>
      <guid>https://dev.to/amitmisra16/install-zorin-153-os-on-macbook-pro-mid-2010-4iai</guid>
      <description>&lt;h2&gt;
  
  
  Why Install Zorin OS 15.3, you ask?
&lt;/h2&gt;

&lt;p&gt;Let me tell you why. After a week of agonising hit and trial methodologies and following countless tutorials/threads including very promising ones like this one - &lt;a href="https://www.if-not-true-then-false.com/2021/debian-ubuntu-linux-mint-nvidia-guide/" rel="noopener noreferrer"&gt;https://www.if-not-true-then-false.com/2021/debian-ubuntu-linux-mint-nvidia-guide/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I stumbled upon the following article &lt;a href="https://jeremy.geek.nz/2021/08/23/using-legacy-nvidia-gpus-in-ubuntu-20-04/" rel="noopener noreferrer"&gt;https://jeremy.geek.nz/2021/08/23/using-legacy-nvidia-gpus-in-ubuntu-20-04/&lt;/a&gt; explaining the fact the NVidia 340.108 is only supported by the linux kernel version &lt;code&gt;5.4.x&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The question why this specific version, that is because the Mid 2010 Macbook Pro comes with NVidia GeForce 320M graphics card. The only driver that supports this card it the NVidia 340.108 other than the default non performant open source nouveau x drivers.&lt;/p&gt;

&lt;p&gt;I started looking around for a good distro that support kernel version &lt;code&gt;5.4.x&lt;/code&gt;and to my delight I found Ubuntu 18.04 LTS supports this kernel and will continue to do so till 2028. This implies if all goes to plan my Mid 2010 can still be useful.&lt;/p&gt;

&lt;p&gt;This also means that the steps mentioned here should be applciable not just for Zorin OS 15.3 but also for other Ubuntu 18.04 based distros as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download the required OS
&lt;/h2&gt;

&lt;p&gt;In case you want to continue with the Zorin OS, you can download 15.3 version from &lt;a href="https://zorin.com/os/download/15/core/64/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Download the iso image and burn it to a USB using tool like &lt;a href="https://www.balena.io/etcher/" rel="noopener noreferrer"&gt;Etcher&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Install Zorin OS
&lt;/h2&gt;

&lt;p&gt;Once you have the OS burned plug the USB to the Mac book you want to install it on and restart the machine. As the machine boots up press the &lt;code&gt;Option&lt;/code&gt;/&lt;code&gt;alt&lt;/code&gt; key to get boot device seletion screen. Choose the module on which you have burned the Zorin image recently. The key point here is to uncheck the following options on the &lt;code&gt;Updates and other software&lt;/code&gt; screen - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Other options

&lt;ul&gt;
&lt;li&gt;Download updates while installing ubuntu&lt;/li&gt;
&lt;li&gt;Install third-party software for graphics and wi-fi hardware and additional media formats.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Proceed with the installation as usual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Post installation steps
&lt;/h2&gt;

&lt;p&gt;Once the installation is completed and you are logged in to the newly installed OS. Perform the following tasks without restarting the machine - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install all the updates, this can be done graphically or via CLI ensuring you &lt;code&gt;DO NOT REBOOT&lt;/code&gt; the system&lt;/li&gt;
&lt;li&gt;Setup the PCI-E bus identifiers. For this task you can follow &lt;a href="https://askubuntu.com/questions/264247/proprietary-nvidia-drivers-with-efi-on-mac-to-prevent-overheating/613573#613573" rel="noopener noreferrer"&gt;this&lt;/a&gt; thread for creating the &lt;code&gt;/etc/grub/01_enable_vga.conf&lt;/code&gt; file, but &lt;code&gt;DO NOT REBOOT&lt;/code&gt; your system.&lt;/li&gt;
&lt;li&gt;Check to see if the OS recognizes the underlying hardware using the following command - &lt;code&gt;sudo ubuntu-drivers devices&lt;/code&gt;. The output of the command should look something like this -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;==&lt;/span&gt; /sys/devices/pci0000:00/0000:00:17.0/0000:04:00.0 &lt;span class="o"&gt;==&lt;/span&gt;
modalias : pci:v000010DEd000008A0sv0000106Bsd000000C2bc03sc00i00
vendor   : NVIDIA Corporation
model    : MCP89 &lt;span class="o"&gt;[&lt;/span&gt;GeForce 320M]
driver   : nvidia-340 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free &lt;span class="nb"&gt;builtin&lt;/span&gt;

&lt;span class="o"&gt;==&lt;/span&gt; /sys/devices/pci0000:00/0000:00:15.0/0000:02:00.0 &lt;span class="o"&gt;==&lt;/span&gt;
modalias : pci:v000014E4d0000432Bsv0000106Bsd0000008Dbc02sc80i00
vendor   : Broadcom Limited
model    : BCM4322 802.11a/b/g/n Wireless LAN Controller &lt;span class="o"&gt;(&lt;/span&gt;AirPort Extreme&lt;span class="o"&gt;)&lt;/span&gt;
driver   : bcmwl-kernel-source - distro non-free
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I had a hard time with Ubuntu 22.04 to get the output where the OS recognizes the NVidia card using the above command, even after installing the &lt;code&gt;patched&lt;/code&gt; version of the NVidia GeForce 320M 340.108 drivers with kernel version &lt;code&gt;5.15&lt;/code&gt; or &lt;code&gt;5.17&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;Additional Drivers&lt;/code&gt; using the GUI or CLI - &lt;code&gt;sudo ubuntu-drivers autoinstall&lt;/code&gt;, once again &lt;code&gt;DO NOT REBOOT&lt;/code&gt; the system post-installation.&lt;/li&gt;
&lt;li&gt;The next steps are taken from the post &lt;a href="https://forums.developer.nvidia.com/t/black-screen-after-install-of-nvidia-driver-ubuntu/109312/2" rel="noopener noreferrer"&gt;here&lt;/a&gt;. 

&lt;ul&gt;
&lt;li&gt;Install nvidia-prime - &lt;code&gt;sudo apt install --reinstall nvidia-prime&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Switch to nvidia - &lt;code&gt;sudo prime-select nvidia&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: I did not remove the stray blacklist files as specified in the article, if you get the black screen after all then please follow all the instructions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Finally run the following command to generate the xconfig file - &lt;code&gt;sudo nvidia-xconfig&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;At this point please reboot your machine&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Moment of truth
&lt;/h2&gt;

&lt;p&gt;Ideally if all goes well, you should be greeted to your OS login or desktop screen without any issues. You can run the following command to see if everthing is working as expected -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvidia-smi
Tue May  3 16:44:05 2022
+------------------------------------------------------+
| NVIDIA-SMI 340.108    Driver Version: 340.108        |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|&lt;span class="o"&gt;===============================&lt;/span&gt;+&lt;span class="o"&gt;======================&lt;/span&gt;+&lt;span class="o"&gt;======================&lt;/span&gt;|
|   0  GeForce 320M        Off  | 0000:04:00.0     N/A |                  N/A |
| N/A   51C   P12    N/A /  N/A |    181MiB /   252MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Compute processes:                                               GPU Memory |
|  GPU       PID  Process name                                     Usage      |
|&lt;span class="o"&gt;=============================================================================&lt;/span&gt;|
|    0            Not Supported                                               |
+-----------------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgywx7f3oxokohmonu7ed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgywx7f3oxokohmonu7ed.png" alt="Nvidia-Settings-Post-Driver-Install" width="663" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this article helps someone who is also trying to increase the life of their mac books. &lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>macbookpro</category>
      <category>nvidia</category>
    </item>
    <item>
      <title>VS Code setup for Spring Boot + Docker/Compose</title>
      <dc:creator>Amit Misra</dc:creator>
      <pubDate>Fri, 15 Apr 2022 17:32:14 +0000</pubDate>
      <link>https://dev.to/amitmisra16/vs-code-setup-for-spring-boot-dockercompose-4bgi</link>
      <guid>https://dev.to/amitmisra16/vs-code-setup-for-spring-boot-dockercompose-4bgi</guid>
      <description>&lt;p&gt;Recently I started looking at how I can leverage VS Code editor for Spring Boot and docker development for mainstream projects/applications. In this article I will try to cover subtle points that will get you started quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install extension packs&lt;/li&gt;
&lt;li&gt;Configure Java runtimes in &lt;code&gt;settings.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Setup docker compose to pass &lt;code&gt;BUILD_ARGS&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Environment configuration for enabling remote debugging&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install Extension Packs
&lt;/h2&gt;

&lt;p&gt;The starting part was relatively pretty easy, all you need is to install the following extensions — &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack" rel="noopener noreferrer"&gt;Extension Pack for Java&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=Pivotal.vscode-boot-dev-pack" rel="noopener noreferrer"&gt;Spring Boot Extension Pack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-spring-boot-dashboard" rel="noopener noreferrer"&gt;Spring Boot Dashboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok" rel="noopener noreferrer"&gt;Lombok Annotations Support&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configure Java Runtimes
&lt;/h2&gt;

&lt;p&gt;If you are like me you might have projects using different JDKs. One of the ways I manage multiple JDKs on my machine is using &lt;a href="https://sdkman.io/" rel="noopener noreferrer"&gt;SDKMAN&lt;/a&gt;. The problem I encountered with VS Code is you have to manually specify the path to various runtimes. You can achieve the same by editing the settings.json like so -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“java.configuration.runtimes”: [
   {
       “name”: “JavaSE-1.8”,
       “path”: “$HOME/.sdkman/candidates/java/8.0.275.hs-adpt”
   },
   {
        "name": "JavaSE-15",
        "path": "$HOME/.sdkman/candidates/java/15.0.2.j9-adpt"
   },
   {
       “name”: “JavaSE-11”,
       “path”: “$HOME/.sdkman/candidates/java/11.0.14-zulu”,
       “default”: true
   }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Docker &lt;code&gt;BUILD_ARGS&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Moving on I realized that most of our Springboot applications are using the same DOCKERFILE and are using ARGS in them. Here is a sample of such a file —&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM openjdk:11.0.12-jre-slim-bullseye
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=UTC", "-XshowSettings:vm", "-XX:+UseContainerSupport", "-jar", "-Xms2048M", "-XshowSettings:vm", "/app.jar"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is not so much related to VS Code, but I thought it might be helpful to the readers who might be running into similar issues where they want to build the docker image using docker-compose by simply running the following command — &lt;br&gt;
&lt;code&gt;docker compose up --build myApp -d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The alternative for this is a multi step process&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker compose build myApp --build-arg JAR_FILE=target/myApp.jar
$ docker compose up myApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works but is not as fluent. I tried few options and finally with some hit and trial I found the service definition that works like a charm. Here is the sample of docker compose service —&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.2'
services:
 myApp:
   build:
     context: ./myApp
     args:
       JAR_FILE: target/myApp.jar
   ports:
     - "8080:8080"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above configuration is assuming you have a multi-module &lt;code&gt;maven&lt;/code&gt;/&lt;code&gt;gradle&lt;/code&gt; setup and &lt;code&gt;myApp&lt;/code&gt; is just one of the Spring Boot application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up VS Code for remote debugging
&lt;/h2&gt;

&lt;p&gt;The last bit was to get the Spring Boot application running with debug port and have VS Code attach to the remote debugger. I was looking for a solution that was not obtrusive and did not want to manage multiple &lt;code&gt;DOCKERFILE&lt;/code&gt;s for the same project one for debugging and other for building images for production. &lt;/p&gt;

&lt;p&gt;This was achieved by setting &lt;code&gt;JAVA_TOOL_OPTION&lt;/code&gt; environment variable in the docker-compose file itself like so —&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.2'
services:
 myApp:
   build:
     context: ./myApp
     args:
       JAR_FILE: target/myApp.jar
 environment:
   - JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=*:8081,server=y,suspend=n
 ports:
   - "8080:8080"
   - "8081:8081"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when you bring up your application using docker compose up command you should see a log statement which will confirm you application will be able to receive remote connection on 8081 for remote debugging —&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Picked up JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,address=*:8081,server=y,suspend=n
Listening for transport dt_socket at address: 8081
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next part was configuring VS code for attaching it to the remote debugger. This part was relatively easy. Add a new “Run and Debug” configuration like so —&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "type": "java",
   "name": "Remote MyApp Debug (attach)",
   "request": "attach",
   "hostName": "localhost",
   "port": 8081
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Voila! you should be able to connect to the Spring Boot application running inside your container.&lt;/p&gt;

&lt;p&gt;Happy Debugging!&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>vscode</category>
      <category>docker</category>
    </item>
    <item>
      <title>Converting path params to query params in Spring Cloud Gateway</title>
      <dc:creator>Amit Misra</dc:creator>
      <pubDate>Thu, 14 Apr 2022 17:21:58 +0000</pubDate>
      <link>https://dev.to/amitmisra16/converting-path-params-to-query-params-in-spring-cloud-gateway-3mno</link>
      <guid>https://dev.to/amitmisra16/converting-path-params-to-query-params-in-spring-cloud-gateway-3mno</guid>
      <description>&lt;h1&gt;
  
  
  Problem Statement
&lt;/h1&gt;

&lt;p&gt;How can I convert path-params on the incoming request to query params for one of your APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.filters(fs -&amp;gt; fs.rewritePath("/(?&amp;lt;country&amp;gt;.\\S+)/(?&amp;lt;locale&amp;gt;.\\S+)/v(?&amp;lt;version&amp;gt;\\d+)/my-endpoint(?&amp;lt;queryParams&amp;gt;.*)",
                        "/api/v2/my-endpoint?locale=${locale}&amp;amp;country=${country}&amp;amp;"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;API evolution is part of Microservices based development. One of our APIs used to have locale and country as path params. As we were writing a new version of the same API, we decided to have those path-params passed on as query-params instead.&lt;/p&gt;

&lt;p&gt;In order to support migration from old to the newer version we decided to add &lt;code&gt;gateway&lt;/code&gt; between the clients and two versions of the API.&lt;/p&gt;

&lt;p&gt;The challenge now becomes that the client will keep sending the locale and country information like before but we need to somehow convert those params before calling the newer version. &lt;/p&gt;

&lt;p&gt;Surprisingly, we were able to do that with relative ease. All you need is the following &lt;code&gt;FilterSpec&lt;/code&gt; being added to your &lt;code&gt;route&lt;/code&gt; -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.filters(fs -&amp;gt; fs.rewritePath("/(?&amp;lt;country&amp;gt;.\\S+)/(?&amp;lt;locale&amp;gt;.\\S+)/v(?&amp;lt;version&amp;gt;\\d+)/my-endpoint(?&amp;lt;queryParams&amp;gt;.*)",
                        "/api/v2/my-endpoint?locale=${locale}&amp;amp;country=${country}&amp;amp;"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that in place the our gateway is now able to route the request to both the versions of our API without any impact on the client. Here are some logs collected for the gateway application -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Incoming request http://localhost:8081/us/en/v1/my-endpoint?channel=WEB is routed to id: my-api-v2-/us/en/v1/my-endpoint, uri:http://localhost:8080/api/v2/my-endpoint?locale=en&amp;amp;country=us&amp;amp;?channel=WEB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above log statement was generated by using the code available on this &lt;a href="https://stackoverflow.com/questions/54117061/springcloudgateway-log-incoming-request-url-and-corresponding-route-uri" rel="noopener noreferrer"&gt;thread&lt;/a&gt; on StackOverFlow&lt;/p&gt;

</description>
      <category>spring</category>
      <category>gateway</category>
      <category>route</category>
      <category>microservices</category>
    </item>
  </channel>
</rss>
