Skip to content

Instantly share code, notes, and snippets.

@0xMatt
0xMatt / UserManagerTest.php
Last active August 29, 2015 14:16
User service test
<?php
use Lithe\Testing\TestCase;
class UserManagerTest extends TestCase
{
/**
*
* @var UserManager
*/
@0xMatt
0xMatt / Answer.php
Last active August 29, 2015 14:15
Interview answer
<?php
function most_letters_in_a_word($string) {
$string = preg_replace("/[^A-Za-z]/", ' ', $string);
foreach(array_filter(explode(' ', $string)) as $word) {
$words[max(count_chars($word, 1))] = $word;
}
return $words[max(array_keys($words))];
@0xMatt
0xMatt / form.php
Last active August 29, 2015 14:15
A basic form. Susceptible to csrf and no post/redirect/get implementation.
<?php
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Set required fields
$required = [
'field_1',
'field_2'
];
@0xMatt
0xMatt / FizzBuzz.php
Created January 24, 2015 15:16
PHP FizzBuzz
<?php header('Content-Type: text/plain');
for($i = 1; $i <= 100; $i++) {
$string = '';
$string .= ($i % 3) == 0 ? "fizz" : '';
$string .= ($i % 5) == 0 ? "buzz" : '';
print (empty($string)) ? $i : $string;
print PHP_EOL;
}
@0xMatt
0xMatt / Cache.php
Last active August 29, 2015 14:13
Cache Decoration
<?php
namespace Lithe\Database;
use Illuminate\Cache\CacheManager;
use Lithe\Contracts\Database\CacheInterface;
class Cache implements CacheInterface
{
/**
@0xMatt
0xMatt / RouterServiceProvider.php
Created January 15, 2015 20:56
RouteServiceProvider
<?php
namespace Lithe\Routing;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
*
@0xMatt
0xMatt / gist:f906cf1d3a1042add9cd
Last active August 29, 2015 14:12
$_GET keys whitelist
<?php
if(!validate_request()) {
die('you requested data from a $_GET key that is not whitelisted.');
}
echo 'Your request is valid';
function validate_request($additional_keys = array()) {
@0xMatt
0xMatt / install_projects_module.php
Created December 29, 2014 18:57
Project Module's migration
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class InstallProjectsModule extends Migration
{
/**
* Run the migrations.
*
@0xMatt
0xMatt / AuthController.php
Last active August 29, 2015 14:12
User Authentication
<?php
namespace Modules\System\Http\Controllers\Frontend;
use Modules\System\Http\Requests\Frontend\LoginRequest;
use Modules\System\Http\Requests\Frontend\RegisterRequest;
use Modules\System\Http\Requests\Frontend\ResetRequest;
use Modules\System\Domain\User\UserManager;
use Modules\System\Domain\User\UserRepositoryInterface;
use Modules\System\Domain\User\LoginManager;
use Modules\System\Domain\Validating\ValidatingManager;
@0xMatt
0xMatt / Controller.php
Last active August 29, 2015 14:11
Get paginated relationship results for Eloquent 4&5
<?php
class Controller {
public function action()
{
$model = MyModal::with('relationship')->first();
return $model->relationshipPaginated();
}