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 / db.php
Last active January 9, 2021 17:27
[Clean database class] #database #class #php
<?php
class db {
protected $connection;
protected $query;
protected $show_errors = TRUE;
protected $query_closed = TRUE;
public $query_count = 0;
public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') {
@steveshead
steveshead / pdo_guide.php
Last active January 5, 2021 19:49 — forked from bradtraversy/pdocrash.php
[PDO & Prepared Statements Snippets] PDO prepared statement snippets for reference
<?php
$host = 'localhost';
$user = '';
$password = '';
$dbname = 'dbname';
// Set DSN
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
// Create a PDO instance
@steveshead
steveshead / sticky_footer.css
Last active January 5, 2021 19:49
[Admin Panel Sticky Footer] CSS #admin_panel #sticky_footer
@steveshead
steveshead / pagination.php
Last active January 9, 2021 18:00
[PHP Pagination] #paginate #page
<?php
// Database
include('config/db.php');
// Set session
session_start();
if(isset($_POST['records-limit'])){
$_SESSION['records-limit'] = $_POST['records-limit'];
}
@steveshead
steveshead / index.html
Last active January 9, 2021 18:03
[Find and Change @mention] Javascript - Reformat/Replace href Text for @mention - convert "@firstName_LastName" to "Firstname Lastname" - #JS #javascript
// vim: syntax=javascript
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
@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() {
@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 / 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 / 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 / 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>