Skip to content

Instantly share code, notes, and snippets.

View casperwilkes's full-sized avatar

Casper Wilkes casperwilkes

View GitHub Profile
@casperwilkes
casperwilkes / FakerFunctions.php
Last active March 25, 2020 17:11
Different ways to generate faker sentences, paragraphs, and word arrays using native Faker `realText` algorithm.
<?php
use Faker\Generator as Faker;
/**
* Different ways to generate faker sentences, paragraphs, and word arrays using native
* Faker `realText` algorithm.
**/
if (!function_exists('fakerRealParagraph')) {
@casperwilkes
casperwilkes / SoftDeletesTrait.php
Created March 2, 2020 16:06
Laravel override trait for soft deletes that recognizes the observer
<?php
/**
* Overrides original SoftDeletes::runSoftDelete method to include observer changes in `deleting` event.
* @see SoftDeletes
* @uses SoftDeletes::runSoftDelete()
*/
namespace App\Traits;
@casperwilkes
casperwilkes / slimphp_alias.md
Last active June 8, 2018 05:04
An alias function for the SlimPHP framework. Also serves as an in-depth guide to setting it up.

Purpose

SlimPHP v2 did not offer an elegant way (or any way actually) to alias application urls. I created a function that will allow a user to alias their urls in such a way that they can use optional and conditional parameters as well.

This will also help maintain an application when routes change. Instead of having to navigate through .htaccess rewrite rules, you could potentially enforce all of your route re-writes through this method.

There are several steps that you will need to take to successfully set this up. Once it's set up, you will only need to modify 1 file (or section) going forward.

@casperwilkes
casperwilkes / redirect.php
Created February 22, 2016 17:11
Simple redirect function for php
/**
* Redirection header.
* @param string $location Where to send user to.
*/
function redirect($location = NULL) {
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}
@casperwilkes
casperwilkes / redirect.js
Last active February 22, 2016 17:13
Simple javascript redirect function. Inline and included
// Inline //
window.location.replace('location/to/redirect.html');
// Functions.js //
/**
* Redirects user to specified location.
* @param {string} redLocation Location to send user to
* @returns {void}
*/
function redirect(redLocation) {
@casperwilkes
casperwilkes / search_current.bat
Created February 7, 2016 01:55
Recursively search current directory for a specific string. Good for looking for specific strings in a windows environment
@ECHO OFF
REM SET TITLE
TITLE Search Current Directory and Sub Directory
REM Output Directions
ECHO ==========================
ECHO This is a simple search program. Be exact when searching.
ECHO This will serach the current directory and all subdirectories.
ECHO The nature of the search will be case insensitive.
ECHO The name of the file where the search term appears will be listed below.
@casperwilkes
casperwilkes / see_var.php
Last active September 28, 2018 19:49
Improved variable dumping. Lets you see the contents of a variable.
<?php
/**
* Lets you inspect variables. If no $var is defined, it will get all defined variables.
* @param mixed $var The variable to inspect.
* - Options:
* - __ALL__: Print all variables in global scope
* - __TRACE__: print out backtrace
* - $variable: Outputs variable info
* @param string $name An optional display name for variable.