Skip to content

Commit

Permalink
Deploying to gh-pages from @ 0c0c3f3 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMcKew committed Jul 23, 2024
1 parent 4ec01e0 commit 3f90b54
Show file tree
Hide file tree
Showing 80 changed files with 371 additions and 371 deletions.
10 changes: 5 additions & 5 deletions actions-and-reducers-in-react-redux.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ <h1 id="actions-and-reducers-in-react-redux">Actions and Reducers in React-Redux
<p><img alt="Redux State Diagram" class="img-fluid" src="https://jackmckew.dev/img/redux-diagram.png"/></p>
<p>Let's use <code>react-redux</code> to build a system which we can alert users when things trigger. For this we will need to build an action, a reducer and a component to display the alert.</p>
<p>To ensure that these three components are speaking the same language, we need to initialise types which will represent the states being passed around. These variables contain a string. For our alert system we need two variables</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="k">export</span> <span class="kd">const</span> <span class="nx">SET_ALERT</span> <span class="o">=</span> <span class="s2">"SET_ALERT"</span>
<span class="k">export</span> <span class="kd">const</span> <span class="nx">REMOVE_ALERT</span> <span class="o">=</span> <span class="s2">"REMOVE_ALERT"</span>
</code></pre></div>
</td></tr></tbody></table>
<h2 id="action">Action</h2>
<p>We'll start by creating the action which will signify when an alert is triggered. We want all of our alerts to be unique so multiple alerts can handled without a problem which we will use <code>uuid</code>.</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
Expand Down Expand Up @@ -212,7 +212,7 @@ <h2 id="action">Action</h2>
</td></tr></tbody></table>
<p>The action is declared as a function, which takes in 3 arguments (2 required): <code>msg</code>, <code>alertType</code> and <code>timeout</code>. Which we then use call the dispatch function with an object constructed from the arguments, and then after a specified timeout we dispatch another object to remove the same alert.</p>
<p>Note that we curry the dispatch function in this case, this is only possible from using the middleware <code>redux-thunk</code>, which can also be represented as:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
Expand All @@ -230,7 +230,7 @@ <h2 id="component">Component</h2>
<blockquote>
<p>This post won't go into detail around how to build a React component, which you can find over at another post: [INSERT REACT COMPONENT POST]</p>
</blockquote>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
Expand Down Expand Up @@ -278,7 +278,7 @@ <h2 id="component">Component</h2>
<p>To break it down, we've created a React component (class) <code>Alert</code> which takes in <code>alerts</code> as an array, verifies it isn't null or empty, and finally iterates over each element in the <code>alerts</code> array to return a <code>div</code> stylized with the appropriate information.</p>
<h2 id="reducer">Reducer</h2>
<p>Lastly we have the reducer which we want to handle all the states that can be created by the <code>alert</code> action. Luckily we can do this with a switch statement:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
Expand Down
16 changes: 8 additions & 8 deletions api-routes-in-nodejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ <h1 id="api-routes-in-nodejs">API Routes in Node.js</h1>
<div>
<body><p>First off what's an API and more specifically what's an API route? API stands for Application Programming Interface, meaning it's how to communicate with the system you are creating. A route within an API is a specific path to take to get specific information or data out of. This post will dive into how to set up API routes in Nodejs with express.</p>
<p>We start by 'importing' express into our route and instantiating a router from the express library.</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="kd">const</span> <span class="nx">express</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'express'</span><span class="p">);</span>
<span class="kd">const</span> <span class="nx">router</span> <span class="o">=</span> <span class="nx">express</span><span class="p">.</span><span class="nx">Router</span><span class="p">();</span>
</code></pre></div>
Expand Down Expand Up @@ -204,23 +204,23 @@ <h1 id="api-routes-in-nodejs">API Routes in Node.js</h1>
<p>These 4 methods make up the basic CRUD functionality (Create, Read, Update and Delete) of an application.</p>
<h2 id="post">POST</h2>
<p>Let's create a scaffold <code>POST</code> method in node.js.</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span><span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'POST request to homepage'</span><span class="p">);</span>
<span class="p">})</span>
</code></pre></div>
</td></tr></tbody></table>
<p>Similarly to do this asynchronously with arrow functions:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span><span class="k">async</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span><span class="nx">res</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'POST request to homepage'</span><span class="p">);</span>
<span class="p">})</span>
</code></pre></div>
</td></tr></tbody></table>
<p>As we can see above, the first argument to our API route method is the path, and the following is the callback function (what should happen when this path is hit). The callback function can be a function, array of functions, series of functions (separated by commas), or a combination of all of them. This is useful if you are wanting to do validation before the final POST request is made. An example of this is:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,[</span><span class="nx">checkInputs</span><span class="p">()],</span> <span class="k">async</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'POST request to homepage and inputs are valid'</span><span class="p">);</span>
Expand All @@ -229,7 +229,7 @@ <h2 id="post">POST</h2>
</td></tr></tbody></table>
<h2 id="get">GET</h2>
<p>All the methods within Express.js follow the same principles so to create a scaffold <code>GET</code> request:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span><span class="k">async</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'GET request to homepage'</span><span class="p">);</span>
Expand All @@ -238,7 +238,7 @@ <h2 id="get">GET</h2>
</td></tr></tbody></table>
<h2 id="put">PUT</h2>
<p>Similarly:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="nx">put</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span><span class="k">async</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'PUT request to homepage'</span><span class="p">);</span>
Expand All @@ -247,7 +247,7 @@ <h2 id="put">PUT</h2>
</td></tr></tbody></table>
<h2 id="delete">DELETE</h2>
<p>Similarly:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code><span class="nx">router</span><span class="p">.</span><span class="k">delete</span><span class="p">(</span><span class="s1">'/'</span><span class="p">,</span><span class="k">async</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">res</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="s1">'PUT request to homepage'</span><span class="p">);</span>
Expand Down Expand Up @@ -279,7 +279,7 @@ <h2 id="express-middleware">Express Middleware</h2>
</tbody>
</table>
<p>An example of using all of the arguments is:</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
Expand Down
4 changes: 2 additions & 2 deletions australia-post-codes-connected.html
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ <h1 id="australia-post-codes-connected">Australia Post Codes Connected</h1>
text-align: right;
}
</style>
<table border="1" class="table-striped dataframe table">
<table border="1" class="table-striped table dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down Expand Up @@ -1118,7 +1118,7 @@ <h1 id="australia-post-codes-connected">Australia Post Codes Connected</h1>
text-align: right;
}
</style>
<table border="1" class="table-striped dataframe table">
<table border="1" class="table-striped table dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
Expand Down
2 changes: 1 addition & 1 deletion author/jack-mckew6.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ <h2><a href="https://jackmckew.dev/automatically-generate-documentation-with-sph
<body><h2 id="document-code-automatically-through-docstrings-with-sphinx"><strong>Document code automatically through docstrings with Sphinx</strong></h2>
<p>This post goes into how to generate documentation for your python projects automatically with Sphinx!</p>
<p>First off we have to install sphinx into our virtual environment. Pending on your flavour, we can do any of the following</p>
<table class="table-striped table highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
<table class="table-striped highlighttable table"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span></span><code>pip install sphinx …</code></pre></div></td></tr></tbody></table></body>
<br>
Expand Down
Loading

0 comments on commit 3f90b54

Please sign in to comment.