Skip to content

Instantly share code, notes, and snippets.

View steveshead's full-sized avatar
💭
Inspired by genius - driven by passion

Steve Shead steveshead

💭
Inspired by genius - driven by passion
View GitHub Profile
@steveshead
steveshead / script.js
Last active January 16, 2021 16:07
[Javascript - find specific words] - function to find specific words in a string and respond accordingly
const checkBaggage = function (items) {
const baggage = items.toLowerCase();
if (baggage.includes('knife') || baggage.includes('gun')) {
return ('You are NOT allowed on board');
} else {
return ('Welcome aboard');
}
};
@steveshead
steveshead / script.js
Last active January 16, 2021 16:05
[Javascript - Captialize Names] - function to capitalize the first letter of each word in a string
const capitaliizeName = function (name) {
const names = name.split(' ');
const namesUpper = [];
for (const n of names) {
// namesUpper.push(n[0].toUpperCase() + n.slice(1));
namesUpper.push(n.replace(n[0], n[0].toUpperCase()));
}
return (namesUpper.join(' '));
};
@steveshead
steveshead / script.js
Last active January 16, 2021 16:04
[Javascript - Mask Credit Card Numbers] - basic - function to mask all but the last 4 numbers of a 16 digit credit card number
const maskCreditCard = function (number) {
const str = number + '';
const last = str.slice(-4);
if (str.length !== 16) {
return ('The credit card number is incorrect');
} else {
return last.padStart(str.length, '*');
}
}
@steveshead
steveshead / index.html
Created January 9, 2021 17:22
[Javascript Guessing Game] - javascript two player number guessing game #javascript #game
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Pig Game</title>
</head>
<body>
@steveshead
steveshead / index.html
Created January 9, 2021 02:25
[Javascript Numbers Game] - numbers guessing game built in javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Guess My Number!</title>
</head>
<body>
@steveshead
steveshead / index.html
Created January 9, 2021 02:21
[Javascript Modal] Pure javascript modal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Modal window</title>
</head>
<body>
@steveshead
steveshead / contact.php
Created January 6, 2021 00:16
[Simple Contact Form] A simple PHP contact form - all inclusive #php #contact #form
<?php
$response = '';
if (isset($_POST['email'], $_POST['subject'], $_POST['name'], $_POST['msg'])) {
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$response = 'Email is not valid!';
} else if (empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['name']) || empty($_POST['msg'])) {
$response = '<div class="alert alert-warning alert-dismissible fade show" role="alert">Please complete all fields!<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
} else {
$to = '[email protected]';
$from = $_POST['email'];
@steveshead
steveshead / function.php
Created January 5, 2021 20:20
[Convert @mention to link] Public function to convert a @mention's and #tag's to links
public function strConvert($string) {
$pat = array('/#(\w+)/', '/@(\w+)/');
$rep = array('<span class="font-weight-bold text-info">#$1</span>', '<span class="font-weight-bold text-info">@$1</span>');
return preg_replace($pat, $rep, $string);
}
@steveshead
steveshead / message.js
Created January 5, 2021 20:03
[Display text one word at a time] Javascript to display text in the UI one word at a time with a time delay #javascript #js #ui #message
let messages = ["Here", "are", "some", "messages."];
let delay = 1000;
let header = document.getElementById("message");
messages.forEach(function(message, i) {
setTimeout(function() {
header.innerText = message;
}, delay * i);
});
@steveshead
steveshead / find.js
Last active January 9, 2021 18:03
[JQuery Find and Replace] - find href or text in a link #jquery #find
// vim: syntax=jquery
$(document).ready(function() {
$('#submit').click(function() {
var text = $('a').prop('text');
alert(text);
})
});
$(document).ready(function() {