Skip to content

Instantly share code, notes, and snippets.

View jaketoolson's full-sized avatar

Jake Toolson jaketoolson

View GitHub Profile
@andrewmclagan
andrewmclagan / repository-interface.php
Created March 8, 2018 21:50
PHP Repository pattern
<?php
namespace EthicalJobs\Foundation\Storage;
use Illuminate\Support\Collection;
interface Repository
{
/**
* Find a model by its id
@derekmd
derekmd / Optional.php
Last active October 17, 2021 10:25
Laravel global helper function `optional()`
<?php
namespace App\Support;
class Optional
{
/**
* The target being transformed.
* Use _ prefix to avoid namespace conflict on __get()
*
@JeffreyWay
JeffreyWay / PjaxMiddleware.php
Last active February 24, 2024 13:40
Laravel middleware for working with pjax.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\DomCrawler\Crawler;
class PjaxMiddleware
@ygotthilf
ygotthilf / jwtRS256.sh
Last active September 20, 2024 17:57
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@chopf
chopf / gist:7d9d7c7c4673624a0205
Last active April 24, 2016 02:20
mysql to pdo conversions
COMMANDS
MySQL PDO Notes
$result = mysql_query($queryStr) $pdoStatement = $pdo->query($queryStr)
mysql_fetch_array($result,$type = MYSQL_BOTH) $pdoStatement->fetch($type = PDO::FETCH_BOTH)
mysql_error() NO EXACT EQUIVALENT $pdo->errorInfo() returns an array, [0=>ErrorCode,1=>Driver specific error code,2=>driver specific error message]
mysql_insert_id() $pdo->lastInsertId()
mysql_free_cursor() NO EXACT EQUIVALENT $pdoStatement->closeCursor() is similar but on statement not PDO
mysql_select_db($dbName) NO EQUIVALENT PDO does not allow databases to be changed, you must create a new PDO connection, or if the info is the same you an use dot notation to query a different database
mysql_real_escape_string($stringToEscape) $pdo->quote($stringToEscape) PDO::quote will add the quotes for you!!!!
@mindplay-dk
mindplay-dk / session-life-cycle.md
Last active August 26, 2024 23:46
Complete overview of the PHP SessionHandler life-cycle

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@msubel
msubel / uuid_v4_excel_formula.txt
Created July 14, 2015 12:37
An Excel Fromula to generate a UUID v4
=LOWER(CONCATENATE(DEC2HEX(RANDBETWEEN(0;POWER(16;8));8);"-";DEC2HEX(RANDBETWEEN(0;POWER(16;4));4);"-";"4";DEC2HEX(RANDBETWEEN(0;POWER(16;3));3);"-";DEC2HEX(RANDBETWEEN(8;11));DEC2HEX(RANDBETWEEN(0;POWER(16;3));3);"-";DEC2HEX(RANDBETWEEN(0;POWER(16;8));8);DEC2HEX(RANDBETWEEN(0;POWER(16;4));4)))
@fny
fny / config.yml.erb
Last active February 16, 2016 22:21
Elastic Beanstalk Deploy with Environment-specific Extensions
# This file lives in `app/.elasticbeanstalk/config.yml.erb`
branch-defaults:
master:
environment: <%= eb_environment %>
# environment: contigo-worker-env # Enable for worker
# Put global configs below!
@sohelamin
sohelamin / http-status-codes.php
Created April 23, 2015 09:05
HTTP Status Codes in a PHP Array
<?php
/**
* Codes collected from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
**/
$http_status_codes = array(
100 => 'Informational: Continue',
101 => 'Informational: Switching Protocols',
102 => 'Informational: Processing',
200 => 'Successful: OK',
@amochohan
amochohan / 01_Laravel 5 Simple ACL manager_Readme.md
Last active July 24, 2024 14:27
Laravel 5 Simple ACL - Protect routes by an account / role type

#Laravel 5 Simple ACL manager

Protect your routes with user roles. Simply add a 'role_id' to the User model, install the roles table and seed if you need some example roles to get going.

If the user has a 'Root' role, then they can perform any actions.

Installation

Simply copy the files across into the appropriate directories, and register the middleware in App\Http\Kernel.php