Skip to content

Instantly share code, notes, and snippets.

@thepsion5
thepsion5 / ModuleAServiceProvider.php
Last active July 18, 2018 11:40
Simple Module Concept for Laravel 5
<?php
namespace App\Providers;
use Illuminate\Support\ModuleServiceProvider;
class FooModuleServiceProvider extends ModuleServiceProvider
{
protected $moduleName = 'Foo Module';
protected $moduleNamespaces = ['App\FooModule'];
@thepsion5
thepsion5 / gist:f35d09ed9b5c8393671a
Last active August 29, 2015 14:24
Laravel Self-Validating Request Example
<?php
namespace MyAppName\Http\Requests\Members;
use Illuminate\Contracts\Validation\Validator;
use InternalPackage\Laravel\Traits\SessionFlashNotifierTrait;
use MyAppName\Http\Requests\Request;
class ImportMembersRequest extends Request
{
use SessionFlashNotifierTrait;
@thepsion5
thepsion5 / AclMiddleware.php
Last active September 16, 2015 20:29
Possible ACL Middleware Implementation for Laravel 5.1.11+
<?php
use AppName\Posts\Post;
use Illuminate\Http\Request;
class GenericAclMiddleware
{
private $entityClasses = [
'post' => Post::class
];
@thepsion5
thepsion5 / AbstractImporter.php
Last active September 22, 2015 18:10
Excerpts from proprietary code used to import items from a CSV
<?php
//namespaces and imports excluded for brevity
abstract class AbstractImporter implements Importer
{
/**
* @var ImportTransformer
*/
private $transformer;
/**
@thepsion5
thepsion5 / html_attr_extraction_functions.php
Created February 4, 2016 15:32
Simple PHP functions to extract links and metadata from a webpage
<?php
//Created as an alternative to an article demonstrating the use of regular expressions to parse HTML:
// http://www.web-development-blog.com/archives/parse-html-with-preg_match_all/
/**
* @param string $remoteUrl
* @param string $yourLink
* @return bool
*/
function check_back_link($remoteUrl, $yourLink)
@thepsion5
thepsion5 / CountyElectionResult.php
Created February 24, 2016 00:09
An example of how to use PDO and a simple repository and POPO entity might work, in contrast with a large ORM
<?php
namespace MyApp\Domain;
class CountyElectionResult
{
/**
* @var string
*/
private $county;
@thepsion5
thepsion5 / Model.js
Created January 13, 2017 16:07
Legacy Javascript from a SPA written in 2007
//Vintage Jquery 1.3
$.post("DataFiles/Registration.ashx",
{
//Actual values sent to the server are formatted are broken into 3 segments, separated by a tilde
//The first is the type to which the value should be cast at the server, the second the actual value
//The third segment, "fin" specifies the server should not validate or update those fields
//We have the best code. Tremendous code, people tell me all the time.
new_ncoqfrname: $("#txtRegNo").attr("type") + "~" + $("#txtRegNo").val() + "~fin",
new_federalidfein: $("#new_federalidfein").attr("type") + "~" + $("#new_federalidfein").val() + "~fin",
new_ncoqfrfinancialperiodstartdate: "datetime" + "~" + $("#new_ncoqfrfinancialperiodstartdate").val() + "~fin",
@thepsion5
thepsion5 / example.php
Created January 19, 2017 18:18
An extremely simple example of how to create a generic validation function using PHP's filter_input() function and/or callbacks
<?php
//Define how each POST field is validated
$fieldValidation = [
'username' => 'required',
'first_name' => 'required',
'last_name' => 'required',
'website' => 'website',
'email' => 'email',
'pass' => 'password',
@thepsion5
thepsion5 / whyyyyyyyy.php
Created May 16, 2017 19:11
Did you know you can shove entire chunks of HTML into a PHP array key? WELL YOU CAN
<?php
//Formatting and indentation unchanged from original file
$find = $_GET['find'];
$browse = $_GET['browse'];
//More awful code ommitted to preserve the sanity of readers
if(isset($find)) {
$find = addcslashes(mysql_real_escape_string($find), "%_");
$rs = new MySQLPagedResultSet("SELECT * FROM TableName WHERE MATCH (Name) AGAINST ('$find' IN BOOLEAN MODE) ORDER BY Name ASC", 100, $dbConnect);
}
@thepsion5
thepsion5 / GeneratesPermutationsTrait.php
Last active August 31, 2017 16:39
Example Permutation Generation
<?php
trait GeneratesPermutationsTrait
{
/**
* Generates an array with N unique combinations of inputs and a unique output, where N is equal to 2^count($params)
* For example, generatePermutations([], 'Param 1', 'Param 2') would return something similar to:
* [
* [
* 'inputs' => ['Param 1v1', 'Param 2v1'],