Skip to content

Instantly share code, notes, and snippets.

View ralphschindler's full-sized avatar

Ralph Schindler ralphschindler

View GitHub Profile
@ralphschindler
ralphschindler / SnapshotCommand.php
Created July 11, 2019 20:26
An example Laravel app command to create and load database snapshots using S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
class SnapshotCommand extends Command
{
@ralphschindler
ralphschindler / AuthServiceProvider.php
Last active April 5, 2019 09:04
Laravel 5.8 Policy Guesser For Using "Models" Directory
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
@ralphschindler
ralphschindler / SampleOAuth2Client.php
Created November 26, 2014 16:23
A Barebones OAuth2 PHP Client demonstrating the "Password Grant Type"
<?php
namespace SampleOauth2Client;
class Client
{
protected $configuration = [
'token_file' => null, // path to a file to store token information
'api_authorization_token' => null, // authorization to talk to token service
'api_token_url' => null, // url to post to
@ralphschindler
ralphschindler / array_walk_recursive_key.php
Created September 19, 2014 14:59
Apply user functions to both keys and values while recursively walking an associative array
<?php
function array_walk_recursive_key(array $array, callable $valueCallback, callable $keyCallback = null) {
foreach ($array as $n => &$v) {
$n2 = ($keyCallback) ? $keyCallback($n) : $n;
if ($n != $n2) {
$array[$n2] = &$array[$n];
unset($array[$n]);
}
if (is_array($v)) {
@ralphschindler
ralphschindler / database-column-ordering.md
Last active November 2, 2017 15:02
Ralph's Database Column Organization

Ralph's Database Column Organization

TLDR:

  1. primary key columns (e.g. id)
  2. foreign key columns (e.g. other_id)
  3. row qualifying columns (e.g. status)
  4. entity identification columns (e.g. name, title, slug, base_url)
  5. non-string-based entity attribute columns (e.g. rating, is_admin)
  6. string-based entity attribute columns (e.g. short_description, description, notes)
@ralphschindler
ralphschindler / spider.php
Created September 22, 2012 15:27
Script to be used with PHP's built-in webserver to proxy and spider a site on click
<?php
// start PHP with: php -S localhost:8888 -t . spider.php
$site = 'http://www.targetwebsite.org/';
$path = $_SERVER["REQUEST_URI"];
if ($path == '/') {
$path = '/index.html';
<?php
setup();
$t = new Tree('top', 'T');
$t->append(new TreeNode('one', 1));
$t->append($x = new TreeNode('two', 2));
$t->append(new TreeNode('three', 3));
$t->append(new TreeNode('foo', 'foo'));
@ralphschindler
ralphschindler / tree.php
Created April 21, 2010 14:42
'tree' console command, in PHP.
#!/usr/bin/php
<?php
/**
* Because you want "tree", but cannot find the source code quick enough
* on the web to compile for OS.X or there is no suitable implementation
* on windows.
*/
// set error reporting
error_reporting(E_STRICT | E_ALL);
@ralphschindler
ralphschindler / README.md
Last active October 21, 2017 12:55
Anonymous Proxy Pattern (Ralph Schindler)

README

Problem & Solution

Problem: you want to set protected properties of an object, or a set of objects as efficiently and without much convention as possible.

Solution in 5.4 is the "Anonymous Proxy", see the by-anonymous-proxy.php file.

@ralphschindler
ralphschindler / node_mate.rb
Created October 6, 2013 01:31
Running unsaved JavaScript though Node.js with TextMate 2 Notes: It's basically 2 files, one created with the bundle editor (See the tmCommand), and the actual node runner. This also requires an environment variable to be setup pointing to the node command line utility: TM_NODE=/usr/local/bin/node for node installed via homebrew
require "#{ENV["TM_SUPPORT_PATH"]}/lib/scriptmate"
class NodeScript < UserScript
def lang; "JavaScript" end
def default_extension; ".js" end
def args
[]
end
def executable; @hashbang || ENV['TM_NODE'] || 'node' end
def version_string