<?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: Muhammad Hewedy</title>
    <description>The latest articles on DEV Community by Muhammad Hewedy (@mhewedy).</description>
    <link>https://dev.to/mhewedy</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%2F186412%2Ffada6e8a-599f-423d-b6ee-811bfbc8caa2.png</url>
      <title>DEV Community: Muhammad Hewedy</title>
      <link>https://dev.to/mhewedy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mhewedy"/>
    <language>en</language>
    <item>
      <title>Connect to a Private network via proxy server from macOS</title>
      <dc:creator>Muhammad Hewedy</dc:creator>
      <pubDate>Thu, 22 Apr 2021 17:44:53 +0000</pubDate>
      <link>https://dev.to/mhewedy/connect-to-a-proxy-server-from-mac-41f5</link>
      <guid>https://dev.to/mhewedy/connect-to-a-proxy-server-from-mac-41f5</guid>
      <description>&lt;p&gt;&lt;a href="https://media.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%2Fwzpumfbtuex8tnojm0bf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwzpumfbtuex8tnojm0bf.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post, we will see how to connect from mac to another machine (as a forwarding proxy) then to the internet (or to a private network 😉). &lt;/p&gt;

&lt;p&gt;The steps will focus to macos client, but it can be any other OS.&lt;/p&gt;

&lt;p&gt;First, You need to install squid proxy on your Windows/Linux box (the jump box). there are many ways to do so, in my case I used a docker image for squid proxy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 3128:3128 --restart unless-stopped cosmicq/docker-squid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, go to macOS, and you need to change the proxy settings in two places, the &lt;code&gt;System Preferences &amp;gt; Network&lt;/code&gt; and in the shell.&lt;/p&gt;

&lt;h4&gt;
  
  
  System Preferences
&lt;/h4&gt;

&lt;p&gt;For &lt;code&gt;System Preferences &amp;gt; Network&lt;/code&gt;, Click Advanced, then go to the proxy tab and in the &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; sections, enter the ip/port of the proxy:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fbd1sjq1jv7ke35cvohi6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fbd1sjq1jv7ke35cvohi6.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note, you can use commands to set the proxy instead of using GUI, as follows:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;networksetup -setwebproxy wi-fi 192.168.100.39 3128
networksetup -setwebproxystate wi-fi on
networksetup -setsecurewebproxystate wi-fi on
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make it easy to enable/disable the proxy setting on a user basis.&lt;/p&gt;

&lt;h4&gt;
  
  
  The shell
&lt;/h4&gt;

&lt;p&gt;The last step is to set the &lt;code&gt;http_proxy&lt;/code&gt; and &lt;code&gt;https_proxy&lt;/code&gt; in your shell.&lt;/p&gt;

&lt;p&gt;You can append the following at the end of your &lt;code&gt;~/.zshrc&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export http_proxy="192.168.100.39:3128"
export https_proxy=$http_proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Update
&lt;/h3&gt;

&lt;p&gt;The squid proxy works well for HTTP/HTTPS traffic. however, some traffic is TCP traffic. There are different solutions to this problem, but I fixed it by using a native port-forward solution in windows using the command &lt;code&gt;netsh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In my case, I needed to access a DB server accessible from windows machine by &lt;em&gt;192.168.100.100/1433&lt;/em&gt;, so I run the following command in windows cmd (as administrator)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netsh interface portproxy add v4tov4 listenport=14330 connectport=1433 connectaddress=192.168.100.100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which will open port &lt;em&gt;14330&lt;/em&gt; on the windows machine and forward traffic to the DB server at &lt;em&gt;192.168.100.100&lt;/em&gt; on port &lt;em&gt;1433&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Now I can connect to the DB server from mac on the windows IP address (in my case &lt;em&gt;192.168.100.39&lt;/em&gt;) on port &lt;em&gt;14330&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To delete the port-forwarding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netsh interface portproxy delete v4tov4 listenport=14330
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To list port-forwarding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netsh interface portproxy show v4tov4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://github.com/CosmicQ/docker-squid" rel="noopener noreferrer"&gt;https://github.com/CosmicQ/docker-squid&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731068(v=ws.10)?redirectedfrom=MSDN" rel="noopener noreferrer"&gt;https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731068(v=ws.10)?redirectedfrom=MSDN&lt;/a&gt;&lt;/p&gt;

</description>
      <category>proxy</category>
      <category>macos</category>
      <category>squid</category>
      <category>docker</category>
    </item>
    <item>
      <title>Using MongoDB query syntax to query Relational Database in Java</title>
      <dc:creator>Muhammad Hewedy</dc:creator>
      <pubDate>Fri, 26 Mar 2021 18:53:09 +0000</pubDate>
      <link>https://dev.to/mhewedy/using-mongodb-query-syntax-to-query-relational-database-in-java-49hf</link>
      <guid>https://dev.to/mhewedy/using-mongodb-query-syntax-to-query-relational-database-in-java-49hf</guid>
      <description>&lt;p&gt;&lt;code&gt;Spring Data JPA&lt;/code&gt; provides a lot of features on top of JPA. Such as Query methods, Query by examples, and a lot more.&lt;/p&gt;

&lt;p&gt;It also integrates with JPA Specifications, QueryDSL, Jooq, and other fantastic libraries.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;However there’s a specific use-case that exists in most applications which is &lt;strong&gt;the need to make the user search by multiple criteria for an entity and its related associations&lt;/strong&gt;. This is where &lt;a href="https://github.com/mhewedy/spring-data-jpa-mongodb-expressions"&gt;Spring Data JPA Mongodb Expressions&lt;/a&gt; excels.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;Spring Data JPA MongoDB Expressions&lt;/strong&gt;&lt;/em&gt; allows you to use &lt;a href="https://docs.mongodb.com/manual/tutorial/query-documents/"&gt;MongoDB query syntax&lt;/a&gt; to send the queries as JSON string typically from the frontend app to a Rest API and then to the Repository layer.&lt;/p&gt;

&lt;p&gt;Here’s an example query that users can send from the frontend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"lastName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ibrahim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$and"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"birthDate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"$gt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1981-01-01"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"birthDate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"$lte"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1985-10-10"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;that will be translated to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="o"&gt;=?&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;birth_date&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;?&lt;/span&gt; &lt;span class="k"&gt;and&lt;/span&gt; &lt;span class="n"&gt;birth_date&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see, it uses the same notation of the initiative and simple-to-use MongoDB query language with features such as ANDing, ORing, and joining entities.&lt;/p&gt;




&lt;h2&gt;
  
  
  So How to start?
&lt;/h2&gt;

&lt;p&gt;You can follow &lt;a href="https://github.com/mhewedy/spring-data-jpa-mongodb-expressions"&gt;the README file on the project page at Github&lt;/a&gt;, it contains a lot of details.&lt;/p&gt;

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

</description>
      <category>springboot</category>
      <category>mongodb</category>
      <category>jpa</category>
      <category>hibernate</category>
    </item>
  </channel>
</rss>
