<?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 Alexandar Zaharyan on Medium]]></title>
        <description><![CDATA[Stories by Alexandar Zaharyan on Medium]]></description>
        <link>https://medium.com/@alexandarzaharyan?source=rss-53c15833356d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*cjvep2evpoxNa3gY7G4qpg.jpeg</url>
            <title>Stories by Alexandar Zaharyan on Medium</title>
            <link>https://medium.com/@alexandarzaharyan?source=rss-53c15833356d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:59:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexandarzaharyan/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[Optimizing Queries in Your SQL Server]]></title>
            <link>https://medium.com/better-programming/optimizing-queries-in-your-sql-server-b8f13082fde5?source=rss-53c15833356d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8f13082fde5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql-server]]></category>
            <dc:creator><![CDATA[Alexandar Zaharyan]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 00:46:46 GMT</pubDate>
            <atom:updated>2020-03-03T00:46:46.093Z</atom:updated>
            <content:encoded><![CDATA[<h4>Investigating execution plans</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e2MpK7fHvZ5e-rQC" /><figcaption>Photo by <a href="https://unsplash.com/@helloquence?utm_source=medium&amp;utm_medium=referral">Helloquence</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This piece outlines the basic things we need to know when examining execution plans.</p><h3>Introduction</h3><p>Have you ever had to optimize an SQL query where pointing out the performance bottleneck was not trivial?</p><p>In such cases, the execution plan the SQL Server provides you with comes in handy and you’d better be able to interpret it correctly as it shows a lot of important information about how the Query Optimizer executes your query and so on.</p><p>A query declaratively specifies what data we need to retrieve, but it is up to the query processor what the steps will be. So, the query plan (or also <em>execution plan</em>) reveals to us how the SQL Server decides to retrieve the data that we requested.</p><p>A common misconception is that the SQL Server chooses the best plan, whereas it actually picks a plan that is “good enough,” since there might be a lot of possible sequences and executing all of them might take too much time.</p><p>In this article, we will go through the main operators that are shown in the execution plan and some points to keep in mind while investigating it.</p><h3>What Is the Execution Plan and Where Can I Find It?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*nnzbJbqehYI0UegZ5G-BDg.png" /><figcaption>A very basic execution plan looks like this</figcaption></figure><p>There are two types of execution plans — estimated and actual.</p><p>The first one is generated without executing the T-SQL query and therefore contains no runtime information. You could display it by clicking the <em>Display Estimated Execution Plan</em><strong> </strong>toolbar button on a specific query.</p><p>The actual execution plans are generated after the execution of the T-SQL queries and contain runtime information such as actual resource usage metrics and runtime warning (if any). You can display it by clicking the <em>Include Actual Execution Plan</em><strong> </strong>toolbar button.</p><h3>Operators</h3><p>Let’s go through some of the operators that you might see in an execution plan:</p><ul><li>Index Scan — An index scan means that the SQL Server reads all rows in a table and then returns those that satisfy the search conditions. It is an efficient strategy when the table is small or most of the rows qualify for the predicate.</li><li>Index Seek — Index Seek, on the other hand, means that it only touches the rows that contain these qualifying rows. Hence, it is most beneficial in cases where a small percentage of the records will be returned.</li><li>Sort — It is one of the most expensive operations you can do, so it should be avoided when possible. Indexing a column is one of the ways to mitigate the need for using this operator.</li><li>Hash Join — The hash join is one of the most expensive join operations as it requires a hash table to do the join. It’s the join that is best for large unsorted inputs. It first reads one of the inputs and hashes the join column and puts the resulting hash and the column values in a hash table built-up in memory. Then it reads all the rows in the second input, hashes those and checks the rows in the resulting hash bucket for the joining rows.</li><li>Nested Loop — Works by looping through all the rows of one input and for each row looping through all the rows of the second input, looking for matches.</li><li>Merge Join — Works by running through the two inputs, comparing rows and outputting matching rows. Both inputs must be sorted on the joining columns for this join to be possible.</li></ul><p>Of course, this list is by no means exhaustive.</p><h3>How Do We Actually Read the Execution Plan?</h3><p>We start interpreting the plan by looking at the top-right operator and go to the left in the direction of the arrows.</p><p>The arrows between the operators stand for the flow of the data. They also have different thicknesses— the thicker they are, the more rows are read between the operators.</p><p>Underneath each of the operators is shown the cost percentage of that operator relative to all the others. These relative costs can sometimes help you identify where the bottlenecks are in the performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*NmDdhEwNpqbdZgn-5qghOA.png" /><figcaption>An example operator with its cost percentage.</figcaption></figure><p>You can also examine the <em>estimated number of rows</em> and the <em>actual number of rows</em> by hovering over any of the operators’ icons or any of the arrows.</p><p>Another thing to be aware of is the warning signs that sometimes appear on the operator’s bottom-right corner. They indicate that there is a warning in that operator. We can learn more about it when hovering over.</p><p>One of the most common warnings is when an operator “spills data” to tempdb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*2u7kCq_R1K93SqArQj_KvA.png" /></figure><p>Usually, the reason is a big difference between the estimated number of rows and the actual number of rows.</p><p>When the estimated is too low, the query optimizer allocates less memory than needed and this results in writing data to tempdb, which obviously is slower.</p><h3>Conclusion</h3><p>In this article, we went through the basics of the execution plans in the SQL Server — how to find them, some of the operators, and how to interpret them. Of course, the topic is much deeper than what we covered here.</p><p>Please, do not hesitate to comment if there are any inaccuracies or you have any questions.</p><h3>Resources</h3><ol><li><a href="https://docs.microsoft.com/en-us/sql/relational-databases/performance/display-an-actual-execution-plan?view=sql-server-ver15">Display an Actual Execution Plan</a></li><li><a href="https://bertwagner.com/2019/08/06/5-things-you-need-to-know-when-reading-sql-server-execution-plans/">5 things to know when reading execution plans</a></li><li><a href="https://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/">SQLAuthority</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8f13082fde5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/optimizing-queries-in-your-sql-server-b8f13082fde5">Optimizing Queries in Your SQL Server</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Quick Guide to Integrating Leaflet.js and React]]></title>
            <link>https://medium.com/better-programming/a-quick-guide-to-integrating-leaflet-js-and-react-ed89ff92790e?source=rss-53c15833356d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed89ff92790e</guid>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[leafletjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Alexandar Zaharyan]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 01:50:31 GMT</pubDate>
            <atom:updated>2019-09-09T01:50:31.343Z</atom:updated>
            <content:encoded><![CDATA[<h4>An easy tutorial for showing different locations on a map in a React app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jK6iDgnjlGNADckZ" /><figcaption>Photo by <a href="https://unsplash.com/@s_hietsch?utm_source=medium&amp;utm_medium=referral">Sebastian Hietsch</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Overview</h3><p>We live in a fascinating, yet confusing time for web developers. With so many frameworks, libraries, plugins, and who-knows-what-else, it is sometimes hard to decide which to use and how to integrate them to work in synergy.</p><p>Let’s say you need to show different locations on a map in your React app. One of the best libraries you can choose is <a href="https://leafletjs.com/">Leaflet.js</a>, “an open-source JavaScript library for mobile-friendly interactive maps”.</p><p>It gives you the ability to easily display tiled web maps, hosted on a public server, with optional tiled overlays.</p><p>So, let’s see how we can integrate it into our React App with the fewest steps possible.</p><h3>Development</h3><p>For our example, we will use our beloved <a href="https://github.com/facebook/create-react-app/blob/master/README.md">Create React App</a>. (For instructions on how to get started, use the <a href="https://github.com/facebook/create-react-app/blob/master/README.md">Quick Guide</a>).</p><p>As of September 2019, this is the structure of the created project:</p><figure><img alt="Create-React-App project structure" src="https://cdn-images-1.medium.com/max/427/1*Ix_sHEKLfZDJdlpnBxsMVw.png" /></figure><p>Now, let’s add the Leaflet library. In the project directory, run:</p><pre>npm install leaflet</pre><p>Finally, we should add the CSS reference in our index.html:</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.css&quot; /&gt;</pre><p>Cool, now we are ready to create our map component. We will use <a href="https://www.openstreetmap.org/">OpenSteetMap </a>as our tile source and position the center at my home town — Sofia, Bulgaria.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18b4fa4f3be4656b4c47bd88d172c284/href">https://medium.com/media/18b4fa4f3be4656b4c47bd88d172c284/href</a></iframe><p>The next step is to level up and add a marker to our map. As an example, I will use the coordinates of the Bulgarian National Assembly Building.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11dcaa740f3c3491c09791b7f682309a/href">https://medium.com/media/11dcaa740f3c3491c09791b7f682309a/href</a></iframe><p>Now, you would probably say: “Yeah, a map with a static marker….Very useful, thank you”. But hold on, Leaflet is capable of much more and we are just warming up.</p><h3>Introducing GeoJSON</h3><p>What fascinated me when I first got to know the library is how easy it is to show simple geographical features on the map, presented in <a href="https://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> format.</p><p>Basically, GeoJSON is an open-standard format, designed for representing simple geographical features — points (addresses and locations), line strings (streets, public transport lines, etc.), polygons (regions, states, etc.).</p><p>The great thing about it is that it is based on the well-known JSON format.</p><p>For our example, I will use a simple GeoJSON, <a href="https://mellyan.carto.com/tables/sofia_regions/public/map">found on the internet</a>, representing the different regions in Sofia.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cdd8f28a5a8692493efd91636d7c1e1/href">https://medium.com/media/5cdd8f28a5a8692493efd91636d7c1e1/href</a></iframe><p>And here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bseRYxHSnQ5juhAHjk-a2Q.png" /></figure><p>Let’s now build upon this a little more. We will add the functionality to move the marker at the center of the polygon when the user clicks on one and paint it in a different color.</p><p>For this, we will need two things:</p><ol><li>Store the selected feature (polygon) in the component’s state.</li><li>Add it to the useEffect Hook’s dependencies.</li></ol><p>If you are still new to React Hooks, I highly recommend checking out Dan Abramov’s post <a href="https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889"><em>Making Sense of React Hooks</em></a>.</p><p>To calculate the center of the polygon, we will use the <a href="https://en.wikipedia.org/wiki/Centroid#Of_a_polygon">formula</a> for finding the centroid of a non-self-intersecting closed polygon, defined by <em>n</em> vertices (<em>x</em>0,<em>y</em>0), (<em>x</em>1,<em>y</em>1), …, (<em>xn</em>−1,<em>yn</em>−1).</p><p>Props to <a href="https://stackoverflow.com/a/22796806">this</a> StackOverflow answer.</p><p>And lastly, we will add a click handler on each feature, where we will set the newly selected one, calculate the centroid, and set the new position of the marker.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d881292d6c5e5f324b3682177f30b94/href">https://medium.com/media/8d881292d6c5e5f324b3682177f30b94/href</a></iframe><h3>Conclusion</h3><p>So, that is a simple and quick way to integrate LeafletJS in a React component. Of course, there are numerous ways to improve it further.</p><p>I hope that this article will save some time for its readers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed89ff92790e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/a-quick-guide-to-integrating-leaflet-js-and-react-ed89ff92790e">A Quick Guide to Integrating Leaflet.js and React</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JWT Authentication with .NET Core 2.1 and React]]></title>
            <link>https://medium.com/@alexandarzaharyan/jwt-authentication-with-net-core-2-1-and-react-f12a9725c3bc?source=rss-53c15833356d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f12a9725c3bc</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alexandar Zaharyan]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 11:11:55 GMT</pubDate>
            <atom:updated>2018-10-20T20:02:35.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*51YYofZCS6b1FuxGoYBpEQ.jpeg" /></figure><h3><strong>What exactly is JWT (JSON Web Token)?</strong></h3><p>We won’t go very formally here as there is Wikipedia for that matter (click <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">here</a>). However, the most important things to remember about JWT are:</p><ul><li>It contains some number of claims (e.g. “logged in as admin”)</li><li>It is generated by the server and signed by one party’s private key (usually the server’s)</li><li>When the user gets this token it must save it locally so that it can access protected resources later</li></ul><p>So, for the current implementation we’ll use .NET Core 2.1 and ReactJS.</p><p>To create our sample project run</p><pre>dotnet new react -o &lt;project_name&gt;</pre><p>in the command line tool. (First, make sure you have installed .NET Core SDK on your machine).</p><h3>Generating the token</h3><ol><li>Add</li></ol><pre>app.UseAuthentication()</pre><p>in Startup.cs Configure method. This adds an AuthenticationMiddleware instance into the process’ request-handling pipeline, which basically enables authentication capabilities.</p><p>2. In the body of the ConfigureServices method add</p><pre><strong> </strong>            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)</pre><pre>       .AddJwtBearer(options =&gt;</pre><pre>        {</pre><pre>           options.TokenValidationParameters = new        Microsoft.IdentityModel.Tokens.TokenValidationParameters()</pre><pre>             {<br>                 RequireExpirationTime = true,</pre><pre>                 ValidIssuer = &quot;YOU_ISSUER_VALUE&quot;, </pre><pre>                 ValidateIssuer = true,</pre><pre>                 ValidateAudience = false,</pre><pre>                 ValidateLifetime = true,</pre><pre>                 ValidateIssuerSigningKey = true,</pre><pre>                 IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(&quot;YOUR_KEY&quot;))</pre><pre>};</pre><pre>});</pre><p>We just told our server the things it should look for when validating a token and also the key every token will be signed by.</p><p>3. Now we are ready to add our Controller method which will actually create the tokens. But first add</p><pre>routes.MapRoute(name: &quot;api&quot;,template:&quot;api/{controller}/{action}/{id?}&quot;);</pre><p>in the UseMvc method call in Configure method.</p><p>4. Now, let’s create a new RegistrationController in the project and add in it the login method.</p><pre>[HttpPost]<br>public JsonResult Login([FromBody] LoginParameters login)<br>{<br>     &lt;Here we should validate the received email and password and</pre><pre>proceed if they are valid&gt;<br>     var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(&quot;YOUR_KEY&quot;));<br>     var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);<br>    var claims = new[]<br>    {<br>       new Claim(ClaimTypes.Role, &quot;Administrator&quot;),<br>    };<br>     var token = new JwtSecurityToken(&quot;YOUR_ISSUER_VALUE&quot;,    &quot;YOUR_AUDIENCE_VALUE&quot;, claims, expires: DateTime.Now.AddMinutes(30),signingCredentials: creds);<br>     var tokenString = new JwtSecurityTokenHandler().WriteToken(token);<br>     return new JsonResult(new {token = tokenString });</pre><p>Here LoginParameters is a custom class with two properties — Email and Password.</p><h3>Receiving and Saving the token</h3><p>Now let’s create our login form. I’ll first add two npm packages: Material-UI and Axios. The first is a very good library with React controls and the second — a Promise-based HTTP client. They are by no means obligatory, but I like using them in my React projects.</p><p>To install them open your command line, navigate to the project’s ClientApp folder and run</p><pre>npm install --save @material-ui/core axios</pre><p>We’ll create a custom HTTP client which makes use of the Axios library and our whole app will use this client as a bottleneck. This is the place where we’ll set the token after we have received it.</p><pre>import axios from &#39;axios&#39;</pre><pre>class httpClient {</pre><pre>constructor() {</pre><pre>const token = JSON.parse(localStorage.getItem(&#39;user&#39;) || &#39;{}&#39;)[&#39;token&#39;]</pre><pre>const instance = axios.create({</pre><pre>baseURL: &#39;/&#39;,</pre><pre>headers: { &#39;Authorization&#39;: `Bearer ${token}` }</pre><pre>})</pre><pre>this.axiosInstance = instance</pre><pre>}</pre><pre>get(url){</pre><pre>return this.axiosInstance.get(url)</pre><pre>.then((resp) =&gt; {</pre><pre>})</pre><pre>.catch((resp) =&gt; {</pre><pre>if (resp.response !== undefined &amp;&amp; resp.response.status == &#39;401&#39;) {</pre><pre>localStorage.removeItem(&#39;user&#39;)</pre><pre>location.replace(&#39;/login&#39;)</pre><pre>} else {</pre><pre>return Promise.reject(resp)</pre><pre>}})</pre><pre>}</pre><pre>post(url, formData) {</pre><pre>return this.axiosInstance.post(url, formData)</pre><pre>.then((resp) =&gt; {</pre><pre>})</pre><pre>.catch((resp) =&gt; {</pre><pre>if (resp.response !== undefined &amp;&amp; resp.response.status == &#39;401&#39;) {</pre><pre>localStorage.removeItem(&#39;user&#39;)</pre><pre>location.replace(&#39;/login&#39;)</pre><pre>} else {</pre><pre>return Promise.reject(resp)</pre><pre>}})</pre><pre>}</pre><pre>setTokenOnLogin = () =&gt; {</pre><pre>const token = JSON.parse(localStorage.getItem(&#39;user&#39;) || &#39;{}&#39;)[&#39;token&#39;]</pre><pre>this.axiosInstance.defaults.headers = { &#39;Authorization&#39;: `Bearer ${token}` }<br>}</pre><pre>clearTokenOnLogout = () =&gt; {</pre><pre>localStorage.removeItem(&#39;user&#39;)</pre><pre>this.axiosInstance.defaults.headers = {}</pre><pre>}}</pre><pre>const instance = new httpClient()</pre><pre>export default instance</pre><p>Now, the only that needs to be done is to set an item with key ‘user’ and value - the received token, if the request to the Login method was successful.</p><p>P.S.: Visit us <a href="https://www.iphos.bg/">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f12a9725c3bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>