-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoding_examples.html
534 lines (503 loc) · 24.1 KB
/
coding_examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
<!DOCTYPE html>
<html lang="en">
<head>
<title>Lee Whiting - SCS Scion Scheme</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/b4e3e1b974.js" crossorigin="anonymous"></script>
<script src="JS/typeEffect/core.js" defer></script>
<script src="JS/main.js" defer></script>
<link href="css/prism.css" rel="stylesheet" />
<script src="JS/prism/prism.js" defer></script>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="menu">
<a class="logo" href="index.php"><img src="img/LW-logo.jpg" alt="Lee Whiting Web Developer"></a>
<nav>
<div class="menu">
<a href="about_me.html">About Me</a>
<a href="index.php#project">My Portfolio</a>
<a href="coding_examples.html">Coding Examples</a>
<a href="scs_scheme.html">SCS Scheme</a>
<a href="index.php#contact">Contact Me</a>
</div>
<a href="https://github.com/donk3ylee" class="center" target="_blank">
<div class="tooltip-container">
<i class="github-icon fab fa-github"></i>
<span class="tooltipi">See my coding projects on GitHub</span>
</div>
</a>
</nav>
</div>
<div id="slider-container">
<div id="x"></div>
<a href="index.php">
<div class="slider-home"></div>
Home
</a>
<a href="about_me.html">
<div class="slider-about"></div>
About Me
</a>
<a href="index.php#project">
<div class="slider-portfolio"></div>
My Portfolio
</a>
<a href="coding_examples.html">
<div class="slider-code"></div>
Coding Examples
</a>
<a href="scs_scheme.html">
<div class="slider-scheme"></div>
SCS Scheme
</a>
<a href="index.php#contact">
<div class="slider-contact"></div>
Contact Me
</a>
<a href="https://github.com/donk3ylee" target="_blank">
<div class="slider-github"></div>
My GitHub
</a>
</div>
<div class="hamburger-menu" id="slider-trigger"><i class="fas fa-bars"></i></div>
<div class="main-page">
<div id="coding-examples">
<header>
<img src="img/coding_example.jpg" class="header-image">
<h1>Examples of My Coding</h1>
</header>
<main>
<div id="accordion-wrapper">
<div class="accordion">
<div class="accordion-title">
<h2>Netmatters Reflection</h2>
<p>This was a learning task to build a detailed copy of the Netmatters homepage. Firstly in html/css/sass and then adding javascript functionality and back-end processing. The live example can be found <a href="http://netmatters.lee-whiting.netmatters-scs.co.uk" target="_blank">here.</a> An example of the code used can be found below.</p>
<div class="tech-breakdown">
<div class="breakdown-item sass" title="This Project Required the use of 54.9% SASS (Sassy CSS)">
<div class="value">54.9%</div>
</div>
<div class="breakdown-item markup" title="This Project Required the use of 45.1% HTML 5 Markup Language">
<div class="value">45.1%</div>
</div>
</div>
<div class="accordion-instructions"></div>
</div>
<div class="accordion-body">
<h3>Example: Sass Looping</h3>
<p>This is an example of the SASS looping I used in order to build the menu. I used SASS looping to dynamically build classes and their bespoke colours and pseudo place icons.</p>
<pre class="code">
<code class="language-sass">
@each $name, $color in $menu_color_map{
#menu-top .wrapper-#{$name}{
.button-#{$name}{
@include flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 19px 0 18px;
height: 100px;
width: 200px;
@include MQ('3','and-smaller'){
width: 160px;
}
color: white;
text-decoration: none;
padding-bottom:10px;
}
&:hover{
color: white;
background-color: #{$color};
.icon{ // make icons white on hover.
color:white;
}
.submenu{
a{
color: white;
align-self: center;
text-decoration: none;
}
@include flex;
justify-content: space-between;
align-items: center;
align-content: center;
position: absolute;
top: 100px;
left: 0;
width: 100%;
z-index: 1;
font-size: 1rem;
@include MQ('3','and-smaller'){
width: 90vw;
left: 5vw;
}
height: 45px;
@include make-bgcolor-wide(darken($color, $darken-submenu-amt));
@include fix-normalize-transparency($color);
}
}
}
.icon{
&-#{$name}{
color: #{$color};
padding-bottom: 8px;
@include place-awesome-icon(unquote("#{$name}"),$size: 1.328rem);
@if(unquote("#{$name}")=="telecom"){
@include rotate-phone-icon;
}
}
}
}
</code>
</pre>
<p>The colour map it references is this one....</p>
<pre class="code">
<code class="language-sass">
$menu_color_map:(
'design': $color-design,
'support':$color-support,
'telecom':$color-telecom,
'software':$color-software,
'marketing':$color-marketing,
'security':$color-security,
);
</code>
</pre>
<p>and the html it relates to is......</p>
<pre class="code">
<code class="language-html">
<div class="wrapper-top-menu">
<div id="menu-top">
<div class="wrapper-design">
<a class="button-design" href="#">
<div class="icon icon-design"></div>
<span class="small">Web</span>Design
</a>
</div>
<div class="wrapper-support">
<a class="button-support" href="#">
<div class="icon icon-support"></div>
<span class="small">IT</span>Support
</a>
</div>
<div class="wrapper-telecom">
<a class="button-telecom" href="#">
<div class="icon icon-telecom"></div>
<span class="small">Telecom</span>Services
</a>
</div>
<div class="wrapper-software">
<a class="button-software" href="#">
<div class="icon icon-software"></div>
<span class="small">Bespoke</span>Software
</a>
</div>
<div class="wrapper-marketing">
<a class="button-marketing" href="#">
<div class="icon icon-marketing"></div>
<span class="small">Digital</span>Marketing
</a>
</div>
<div class="wrapper-security">
<a class="button-security" href="#">
<div class="icon icon-security"></div>
<span class="small">Cyber</span>Security
</a>
</div>
</div>
</div>
</code>
</pre>
<p>The end result is a menu built from efficient sass code which has unique colouring and icon inclusion. You can <a href="http://netmatters-reflection.phpdonk3y.com" target="_blank">see the live example here.</a></p>
<img class="screenshot" src="img/codingExamples/menu_loopin_sass.png" alt="A screenshot of the menu in my Netmatters reflection build.">
<h2>Further....</h2>
<p>If your interested in finding out more about my current skill-set or want to discuss any open positions which you feel may suit me, please don't hesitate to
<a href="index.php#contact"> contact me.</a>
</p>
</div>
<div class="accordion-footer">
</div>
</div>
<div class="accordion">
<div class="accordion-title">
<h2>Example of Back-End Procedural PHP code</h2>
<p>This is the procedural PHP code which processes, validates and sanitizes the inputs of the contact form on this site and inserts them into a database. An example of the code used can be found below.</p>
<div class="tech-breakdown">
<div class="breakdown-item sass" title="This Project Required the use of 33.6% SASS (Sassy CSS)">
<div class="value">33.6%</div>
</div>
<div class="breakdown-item css" title="This Project Required the use of 2.4% CSS 3">
<div class="value">2.4%</div>
</div>
<div class="breakdown-item markup" title="This Project Required the use of 38.2% HTML 5 Markup Language">
<div class="value">38.2%</div>
</div>
<div class="breakdown-item javascript" title="This Project Required the use of 6.3% of JavaScript">
<div class="value">6.3%</div>
</div>
<div class="breakdown-item php" title="This Project Required the use of 19.5% PHP code">
<div class="value">19.5%</div>
</div>
</div>
<div class="accordion-instructions"></div>
</div>
<div class="accordion-body">
<p>Below is an example of a PHP script which processes a form and validates the data being entered, sanitizes the data and inserts it into a database. </p>
<pre class="code">
<code class="language-php">
session_start();
include_once("./bootstrap.php");
include_once('./processForm.functions.php');
// START send form data back to repopulate the contact form
$form_data = array();
foreach($_POST as $name => $value){
$_SESSION['form_data'][$name] = $value;
}
// END send form data back to repopulate the contact form
// START check for empty status for each required field
$errors = array();
foreach($_POST as $name => $value){
if(empty($value)){
if($name !="companyName"){
array_push($errors, getRealName($name) ." is a required field and needs to be filled out.");
}
}
}
if (count($errors) != 0){
$_SESSION['errors'] = $errors;
header('Location: http://'. $_SERVER['HTTP_HOST'] . $_SERVER["PHP_SELF"] .'/../../index.php#error_target');
exit;
}
// END check for empty status for each required field
// START validate the email and telephone inputs
$validation_errors = array();
$results = array();
$results['emailAddress'] = filter_var($_POST['emailAddress'], FILTER_VALIDATE_EMAIL);
foreach($results as $name => $value){
if($value == FALSE){
array_push($validation_errors, "<p>". getRealName($name) ." is not the correct format please check.</p>");
}
}
if (count($validation_errors) != 0){
$_SESSION['errors'] = $validation_errors;
header('Location: http://'. $_SERVER['HTTP_HOST'] . $_SERVER["PHP_SELF"] .'/../../index.php#error_target');
exit;
}
// END validate the email and telephone inputs
// START Sanitize post inputs and add them to the database
$filter = array(
"firstName" => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"lastName" => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"emailAddress" => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"subject" => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
"message" => FILTER_SANITIZE_FULL_SPECIAL_CHARS
);
$input = filter_input_array(INPUT_POST, $filter);
try{
$db = new DB;
$conn = $db->get_connection();
$query = "INSERT INTO contacts (fName, lName, email, subject, message)
VALUES(:fname, :lName, :email, :subject, :message)";
$result = $conn->prepare($query);
$result->bindParam(':fname', $input['firstName']);
$result->bindParam(':lName', $input['lastName']);
$result->bindParam(':email', $input['emailAddress']);
$result->bindParam(':subject', $input['subject']);
$result->bindParam(':message', $input['message']);
if($result->execute()){
$_SESSION['success'] = "Thank you for leaving a message. I will get back to you at my earliest convenience";
unset($_SESSION['form_data']);
header('Location: http://'. $_SERVER['HTTP_HOST'] . $_SERVER["PHP_SELF"] .'/../../index.php#success_target');
exit;
} else {
$_SESSION['error'] = "Something went wrong. I'm sorry but you did not leave a message this time please try again.";
header('Location: http://'. $_SERVER['HTTP_HOST'] . $_SERVER["PHP_SELF"] .'/../../index.php#error-target');
exit;
}
} catch (PDOException $e) {
throw $e;
}
// END Sanitize post inputs and add them to the database
</code>
</pre>
<p>The function/s contained in processForm.functions.php that relate to this code are:</p>
<pre class="code">
<code class="language-php">
function getRealName($name){
switch ($name){
case 'firstName':
return "The First Name";
case 'lastName':
return "The Last Name";
case 'emailAddress':
return "Your Email Address";
case 'subject':
return "The Subject Line";
case 'message':
return "The Message";
default:
return null;
}
}
</code>
</pre>
</div>
<div class="accordion-footer">
</div>
</div>
<!-- example of another section -->
<!-- <div class="accordion">
<div class="accordion-title">
Testing testing testing 1 2 3 the middle section
<div class="accordion-instructions"></div>
</div>
<div class="accordion-body">
bla bla bla middle section code etc.
<pre class="code">
<code class="language-html">
code
</code>
</pre>
</div>
<div class="accordion-footer">
</div>
</div> -->
<!-- end example section -->
<div class="accordion">
<div class="accordion-title">
<h2>Example of an SQL query containing a table join, subquery and ordering filter</h2>
<p>The objective of this example is to demonstrate an SQL query which contains a table join, the use of a subquery and the use of an ordering filter. The database has two tables <span class="italics bolder">employees</span> and <span class="italics bolder">department</span>. The two tables are joined on a column in the <span class="italics bolder">employees</span> database which makes use of a foreign key constraint.</p>
<div class="tech-breakdown">
<div class="breakdown-item sql" title="This Project Was Built Using 100% SQL">
<div class="value">100% SQL </div>
</div>
</div>
<div class="accordion-instructions"></div>
</div>
<div class="accordion-body">
<h2>Database Schemas and Contents</h2>
<h4>The Schema of the <span class="italics bolder">employees</span> table is:</h4>
<pre class="code">
<code class="language-sql">
+------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+-------+
| emp_id | int | NO | PRI | NULL | |
| emp_name | varchar(15) | NO | | NULL | |
| job_name | varchar(10) | NO | | NULL | |
| manager_id | int | YES | | NULL | |
| hire_date | date | NO | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
| commission | decimal(7,2) | YES | | NULL | |
| dep_id | int | NO | MUL | NULL | |
+------------+---------------+------+-----+---------+-------+
</code>
</pre>
<h4>The contents of the <span class="italics bolder">employees</span> table:</h4>
<pre class="code">
<code class="language-sql">
emp_id | emp_name | job_name | manager_id | hire_date | salary | commission | dep_id
--------+----------+-----------+------------+------------+---------+------------+--------
68319 | KAYLING | PRESIDENT | | 1991-11-18 | 6000.00 | | 1001
66928 | BLAZE | MANAGER | 68319 | 1991-05-01 | 2750.00 | | 3001
67832 | CLARE | MANAGER | 68319 | 1991-06-09 | 2550.00 | | 1001
65646 | JONAS | MANAGER | 68319 | 1991-04-02 | 2957.00 | | 2001
67858 | SCARLET | ANALYST | 65646 | 1997-04-19 | 3100.00 | | 2001
69062 | FRANK | ANALYST | 65646 | 1991-12-03 | 3100.00 | | 2001
63679 | SANDRINE | CLERK | 69062 | 1990-12-18 | 900.00 | | 2001
64989 | ADELYN | SALESMAN | 66928 | 1991-02-20 | 1700.00 | 400.00 | 3001
65271 | WADE | SALESMAN | 66928 | 1991-02-22 | 1350.00 | 600.00 | 3001
66564 | MADDEN | SALESMAN | 66928 | 1991-09-28 | 1350.00 | 1500.00 | 3001
68454 | TUCKER | SALESMAN | 66928 | 1991-09-08 | 1600.00 | 0.00 | 3001
68736 | ADNRES | CLERK | 67858 | 1997-05-23 | 1200.00 | | 2001
69000 | JULIUS | CLERK | 66928 | 1991-12-03 | 1050.00 | | 3001
69324 | MARKER | CLERK | 67832 | 1992-01-23 | 1400.00 | | 1001
14 rows
</code>
</pre>
<h4>The Schema of the <span class="italics bolder">department</span> table is:</h4>
<pre class="code">
<code class="language-sql">
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| dep_id | int | NO | PRI | NULL | |
| dep_name | varchar(20) | NO | | NULL | |
| dep_location | varchar(15) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
</code>
</pre>
<h4>The contents of the <span class="italics bolder">department</span> table:</h4>
<pre class="code">
<code class="language-sql">
dep_id | dep_name | dep_location
--------+------------+--------------
1001 | FINANCE | SYDNEY
2001 | AUDIT | MELBOURNE
3001 | MARKETING | PERTH
4001 | PRODUCTION | BRISBANE
4 rows
</code>
</pre>
<h4>And Finally <span class="italics bolder">The SQL Query</span> Itself</h4>
<p>I chose to write an SQL query which returns all of the employees who earn an above average salary, sorted by salary.</p>
<p>The <span class="italics bolder">employees</span> database is joined to the <span class="italics bolder">department</span> database using the <span class="italics bolder">department</span> databases primary key which is referenced from the <span class="italics bolder">employees</span> database using a join on a column which makes use of a foreign key constraint (dep_id).</p>
<p>In order to get all employees earning over the average salary I included a subquery in the WHERE clause which compares each employees salary with the returned subquery which calculates the average salary.</p>
<p>The selectors have been formatted to use easy to read labels</p>
<pre class="code">
<code class="language-sql">
SELECT
E.emp_name AS 'Employee Name',
E.job_name AS 'Job Title',
E.salary AS Salary,
D.dep_name AS Department,
D.dep_location AS Location
FROM employees AS E
JOIN department AS D ON D.dep_id = E.dep_id
WHERE E.salary > (
SELECT AVG(salary)
FROM employees
)
ORDER BY E.salary DESC;
</code>
</pre>
<h4>The Returned Result Set</h4>
<p>The result of the SQL query is a table that contains the employee name, job title, salary, department and location of every employee who earns above the average salary, ordered by salary. </p>
<pre class="code">
<code class="language-sql">
+---------------+-----------+---------+------------+-----------+
| Employee Name | Job Title | Salary | Department | Location |
+---------------+-----------+---------+------------+-----------+
| KAYLING | PRESIDENT | 6000.00 | FINANCE | SYDNEY |
| FRANK | ANALYST | 3100.00 | AUDIT | MELBOURNE |
| SCARLET | ANALYST | 3100.00 | AUDIT | MELBOURNE |
| JONAS | MANAGER | 2957.00 | AUDIT | MELBOURNE |
| BLAZE | MANAGER | 2750.00 | MARKETING | PERTH |
| CLARE | MANAGER | 2550.00 | FINANCE | SYDNEY |
+---------------+-----------+---------+------------+-----------+
6 Rows
</code>
</pre>
</div>
<div class="accordion-footer">
</div>
</div>
</div>
</main>
<footer>
<a href="#top">
<div class="scroll-up">
<i class="fas fa-chevron-up"></i>
Scroll Up
</div>
</a>
</footer>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
</body>
</html>