<?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: Paetelmechanic</title>
    <description>The latest articles on DEV Community by Paetelmechanic (@paetelmechanic).</description>
    <link>https://dev.to/paetelmechanic</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F239007%2F42bee77b-acb3-4279-b165-42be24df2d18.jpeg</url>
      <title>DEV Community: Paetelmechanic</title>
      <link>https://dev.to/paetelmechanic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paetelmechanic"/>
    <language>en</language>
    <item>
      <title>Databases revisted</title>
      <dc:creator>Paetelmechanic</dc:creator>
      <pubDate>Mon, 20 Jan 2020 13:50:18 +0000</pubDate>
      <link>https://dev.to/paetelmechanic/databases-revisted-5acc</link>
      <guid>https://dev.to/paetelmechanic/databases-revisted-5acc</guid>
      <description>&lt;p&gt;A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records.&lt;br&gt;
Indexes are created using a few database columns.&lt;br&gt;
The first column is the Search key that contains a copy of the primary key or candidate key of the table. These values are stored in sorted order so that the corresponding data can be accessed quickly.&lt;br&gt;
Note: The data may or may not be stored in sorted order.&lt;br&gt;
The second column is the Data Reference or Pointer which contains a set of pointers holding the address of the disk block where that particular key value can be found.&lt;/p&gt;

&lt;p&gt;Two primary methods of constructing indices are clustered and non-clustered:&lt;br&gt;
A non-clustered index (or regular b-tree index) is an index where the order of the rows does not match the physical order of the actual data. It is instead ordered by the columns that make up the index. In a non-clustered index, the leaf pages of the index do not contain any actual data, but instead contain pointers to the actual data&lt;br&gt;
A clustered index is a special index which physically orders the data according to the indexed columns. The leaf nodes of the index store the data for the rest of the columns in the table so when a lookup is performed on this type of index there are no other structures that need to be referenced.&lt;br&gt;
Some other key facts to remember about indexes are:&lt;br&gt;
Indexes take additional disk space.&lt;br&gt;
indexes slow down INSERT,UPDATE and DELETE, but will speed up UPDATE if the WHERE condition has an indexed field. INSERT, UPDATE and DELETE becomes slower because on each operation the indexes must also be updated.&lt;/p&gt;

&lt;p&gt;Suppose a database contains N data items and one must be retrieved based on the value of one of the fields. A simple implementation retrieves and examines each item according to the test. If there is only one matching item, this can stop when it finds that single item, but if there are multiple matches, it must test everything. This means that the number of operations in the worst case is O(N) or linear time. Since databases may contain many objects, and since lookup is a common operation, it is often desirable to improve performance.&lt;br&gt;
Indexing is an easy way to improve the performance of our databases&lt;br&gt;
Hopefully this brief look into indexing helped to clear up the concept.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Stateful and Stateless components in React</title>
      <dc:creator>Paetelmechanic</dc:creator>
      <pubDate>Mon, 14 Oct 2019 12:52:02 +0000</pubDate>
      <link>https://dev.to/paetelmechanic/stateful-and-stateless-components-in-react-inc</link>
      <guid>https://dev.to/paetelmechanic/stateful-and-stateless-components-in-react-inc</guid>
      <description>&lt;p&gt;Lets have a little chat about stateful and stateless components in React. But first, we'd have to say what the heck is React. React is a framework for building web applications.&lt;/p&gt;

&lt;p&gt;In React, applications are made of components. If you pass the same arguments (properties in React lingo, or props) to a component, you have the same output. This allows components to be reusable.&lt;/p&gt;

&lt;p&gt;One more important facet about React is that components cannot change their props. Or rather,  information only flows in one direction. Components can have children and give the props to them, they can also store some information once they are created (the state), but after you give them the props, they wont be able to be changed anymore. This makes components and the application quite static and a more easy to predict.&lt;/p&gt;

&lt;p&gt;In conventional HTML and Javascript applications, Javascript is used to modify the DOM with data, and it usually does this “imperatively”. This means we define each step through code to create the result we want:&lt;/p&gt;

&lt;p&gt;Here is an example of a stateless component:&lt;/p&gt;

&lt;p&gt;An imperative example of calling an API&lt;/p&gt;

&lt;p&gt;Call API&lt;br&gt;
Set some spinner as loading by adding it to the DOM&lt;br&gt;
Get API result&lt;br&gt;
Remove the loading spinner by removing it from the DOM&lt;br&gt;
Add result to DOM by inserting HTML results&lt;/p&gt;

&lt;p&gt;React tries to describe things in a “declarative” way, instead of imperatively. This means, we focus on writing what we want the result to look like, and not the steps that take us to that result.&lt;/p&gt;

&lt;p&gt;This takes us to state. React’s state is used to declaratively set the state of the app, and pass those values to our components. The components then simply use the state passed to render themselves in a specific way:&lt;/p&gt;

&lt;p&gt;A declarative example, using same example as above:&lt;/p&gt;

&lt;p&gt;var React = require('react');&lt;/p&gt;

&lt;p&gt;var Header = React.createClass({&lt;br&gt;
    render: function() {&lt;br&gt;
        return(&lt;br&gt;
            &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ujgka3dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/%7B%27mypicture.png%27%7D" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ujgka3dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/%7B%27mypicture.png%27%7D"&gt;&lt;/a&gt;&lt;br&gt;
        );&lt;br&gt;
    }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;Conversely, here is a stateful one:&lt;/p&gt;

&lt;p&gt;var React = require('react');&lt;/p&gt;

&lt;p&gt;var Header = React.createClass({&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getInitialState: function() {
    return {
        someVariable: "I remember something"
    };
},

render: function() {
    return(
        &amp;lt;img src={'mypicture.png'} /&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This tells our loading spinner to render automatically&lt;/p&gt;

&lt;p&gt;Call API&lt;br&gt;
Get API result, set state to apiCallInProgress: false&lt;/p&gt;

&lt;p&gt;This tells our loading spinner to hide and the result automatically populate to the DOM&lt;/p&gt;

&lt;p&gt;It’s nice because it is easier to understand what is going on just by following the state values.&lt;/p&gt;

&lt;p&gt;Hopefully that helped to clarify some of the ambiguities, or maybe it simply created more. If that's the case then I recommend giving this insightful article a little read to clear up any remaining doubts:&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Deciding between stateless and stateful components depends on your needs. You should think carefully about how each component will be used. If you won’t use state, refs or lifecycle hooks then you should choose stateless components, because there is a significant difference between transpiled versions of them.&lt;/p&gt;

&lt;p&gt;var Header = React.createClass({&lt;br&gt;
    render: function() {&lt;br&gt;
        return(&lt;br&gt;
            &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ujgka3dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/%7B%27mypicture.png%27%7D" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ujgka3dF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/%7B%27mypicture.png%27%7D"&gt;&lt;/a&gt;&lt;br&gt;
        );&lt;br&gt;
    }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;&lt;a href="https://code.tutsplus.com/tutorials/stateful-vs-stateless-functional-components-in-react--cms-29541"&gt;https://code.tutsplus.com/tutorials/stateful-vs-stateless-functional-components-in-react--cms-29541&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks and see you next time coders!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Same Origin Policy &amp; Cors</title>
      <dc:creator>Paetelmechanic</dc:creator>
      <pubDate>Mon, 07 Oct 2019 12:57:17 +0000</pubDate>
      <link>https://dev.to/paetelmechanic/same-origin-policy-cors-2l33</link>
      <guid>https://dev.to/paetelmechanic/same-origin-policy-cors-2l33</guid>
      <description>&lt;p&gt;The backbone of modern internet web security is something called the Same Origin Policy. It refers to the standard in place throughout most of the interwebs that restricts access to a webpage from a secondary page unless the two pages share the same 'origin'. What's an origin you may ask? Well an origin is the combination of domain, host name, and port number, all working in tandem to provide a very specific identification address for where your page lives on the internet&lt;/p&gt;

&lt;p&gt;This mechanism bears a particular significance for modern web applications that extensively depend on HTTP cookies[1] to maintain authenticated user sessions, as servers act based on the HTTP cookie information to reveal sensitive information or take state-changing actions. A strict separation between content provided by unrelated sites must be maintained on the client-side to prevent the loss of data confidentiality or integrity.&lt;/p&gt;

&lt;p&gt;While waiting on that to load, let's talk about CORS a bit. CORS stands for Cross Origin Resource Sharing. It as implemented a a bit of a work around for Same Origin Policy because sometimes sites actually do want to allow access to their page from outside sources. &lt;/p&gt;

&lt;p&gt;They accomplish this by making allowances to certain pages in their response headers. This can be verified with the use of a get request that will show if a page has permission to access or not.&lt;/p&gt;

&lt;p&gt;For Ajax and HTTP request methods that can modify data (usually HTTP methods other than GET, or for POST usage with certain MIME types), the specification mandates that browsers "preflight" the request, soliciting supported methods from the server with an HTTP OPTIONS request method, and then, upon "approval" from the server, sending the actual request with the actual HTTP request method. Servers can also notify clients whether "credentials" (including Cookies and HTTP Authentication data) should be sent with requests&lt;/p&gt;

&lt;p&gt;The browser sends the OPTIONS request with an Origin HTTP header to service.example.com containing the domain that served the parent page:&lt;/p&gt;

&lt;p&gt;Origin: &lt;a href="http://www.example.com"&gt;http://www.example.com&lt;/a&gt;&lt;br&gt;
The server at service.example.com may respond with:&lt;/p&gt;

&lt;p&gt;An Access-Control-Allow-Origin (ACAO) header in its response indicating which origin sites are allowed. For example:&lt;/p&gt;

&lt;p&gt;Access-Control-Allow-Origin: &lt;a href="http://www.example.com"&gt;http://www.example.com&lt;/a&gt;&lt;br&gt;
Since &lt;a href="http://www.example.com"&gt;www.example.com&lt;/a&gt; matches the parent page, the browser then performs the cross-origin request.&lt;/p&gt;

&lt;p&gt;An Access-Control-Allow-Origin (ACAO) header with a wildcard that allows all domains:&lt;/p&gt;

&lt;p&gt;Access-Control-Allow-Origin: *&lt;br&gt;
An error page if the server does not allow a cross-origin request&lt;/p&gt;

&lt;p&gt;Hopefully, if you were in the dark about what exactly same origin policy or cors was, this post helped to clarify it somewhat. Happy coding.&lt;/p&gt;

</description>
      <category>sameoriginpolicycors</category>
    </item>
    <item>
      <title>Recursion in a nutshell</title>
      <dc:creator>Paetelmechanic</dc:creator>
      <pubDate>Mon, 30 Sep 2019 12:14:21 +0000</pubDate>
      <link>https://dev.to/paetelmechanic/recursion-in-a-nutshell-1da4</link>
      <guid>https://dev.to/paetelmechanic/recursion-in-a-nutshell-1da4</guid>
      <description>&lt;p&gt;Recursion in computer science is a sometimes tricky concept to wrap one's head around.&lt;/p&gt;

&lt;p&gt;People often say that to understand recursion, one must first understand recursion! But it needn't be as daunting as it seems. Recursion at in its simplest form is simply a function call itself. My instructors have always told me to ignore complexity and let the recursive call do the work for me. Turns out, they're right!&lt;/p&gt;

&lt;p&gt;Let's cover the basics first. In order for a function to be a working recursive function, it needs two things: a base case that serves as a stopping condition, and a recursive call that calls the selfsame function again(hopefully with a slightly modified argument).. &lt;/p&gt;

&lt;p&gt;Recursion is great for iterating through lists and trees. It does the heavy lifting of sifting through all of the possibilities for us, and does so quite elegantly might I add. &lt;/p&gt;

&lt;p&gt;I would say that the biggest shortfall of using recursion would be the effect that it can have on time complexity of operations. Using recursion where a simple for loop might have sufficed can cause your code's performance to suffer. One technique to hedge against increased time complexity, is memoization. It's used to store the results of expensive function calls and return the cached result when the same input occurs. Memoization can help a recursive function actually run faster than an iterative function if written correctly.&lt;/p&gt;

&lt;p&gt;Be judicious and remember that with great power comes great responsibility, and remember that with great power comes great responsibility, and remember...&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
