Skip to content

Instantly share code, notes, and snippets.

View midnite81's full-sized avatar

Simon Rogers midnite81

View GitHub Profile
@midnite81
midnite81 / ValidationClass.php
Created July 20, 2012 10:47
Validation Class
<?php
class Validate {
function chkValid($str,$min=3,$max='',$regex='',$attr='') {
if (is_numeric($min) and $min <> "") {
if (strlen($str) < $min) return false;
}
if (is_numeric($max) and $max <> "") {
if (strlen($str) > $max) return false;
@midnite81
midnite81 / .gitignore
Created August 21, 2016 08:00
General .gitignore file I use
/.idea
/node_modules
/vendor
composer.lock
.DS_Store
.env
@midnite81
midnite81 / RemoveDuplicates.sql
Created October 17, 2016 09:29
Remove Duplicate Rows, Keeping the first lin
DELETE FROM my_table
USING my_table, my_table mt1
WHERE my_table.id > mt1.id
AND my_table.my_column = mt1.my_column -- the column which you're checking for duplicates on
AND my_table.`type` = 'greeting'; -- any other conditions that you need to filter by
@midnite81
midnite81 / GetForeignKeysForColumn.sql
Last active June 20, 2020 23:07
Gets foreign keys for a column
SET @tableName = '<table_name>';
SET @columnName = '<column_name>';
SELECT table_name, column_name, referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_name = @tableName AND column_name = @columnName;
@midnite81
midnite81 / dev_die_and_dump
Created November 12, 2016 00:15
A dev die and dump snippet
if (preg_match('/^dev[^\.]*?\./i', $_SERVER['HTTP_HOST'])) {
if (function_exists('dd')) {
dd('some dump ..', __FILE__.':'.__LINE__);
} else {
die(var_dump('some dump ..', __FILE__.':'.__LINE__));
}
}
@midnite81
midnite81 / HttpErrorCodes.php
Last active June 20, 2020 23:04
Error Code PHP Class
<?php
namespace App\Errors;
class HttpErrorCodes
{
/**
* Return all error codes as an array
*
* @return mixed
@midnite81
midnite81 / Handler.php
Created November 20, 2016 13:37
Overwriting default action in Laravel 5.3 error handler
// Overwriting default action of render - Laravel 5.3
public function render($request, Exception $exception)
{
...
if (! $this->isHttpException($exception) && ! config('app.debug')) {
$exception = new \Symfony\Component\HttpKernel\Exception\HttpException(500);
}
@midnite81
midnite81 / SplitArray.js
Last active June 21, 2020 00:36
Javascript - split array into chunks
var myArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20, 21];
function splitArray(array, numberOfChunks) {
arrayCount = array.length;
split = array.length / numberOfChunks;
chunks = [];
@midnite81
midnite81 / repos
Created December 17, 2016 12:54
Add directories to default laravel application
#!/bin/bash
mkdir -p app/Contracts
mkdir -p app/Contracts/Repositories
mkdir -p app/Contracts/Services
mkdir -p app/Services
mkdir -p app/Store/Eloquent/Models
mkdir -p app/Store/Eloquent/Repositories
mkdir -p app/Store/Eloquent/Traits
@midnite81
midnite81 / Alter Table to InnoDB
Last active June 20, 2020 22:58
Create sql statements to change a table to use InnoDB
SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements
FROM information_schema.tables AS tb
WHERE table_schema = @DATABASE_NAME
AND `ENGINE` = 'MyISAM'
AND `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;