Skip to content

Instantly share code, notes, and snippets.

@adamtomat
adamtomat / app - PostTypes - Post.php
Last active July 12, 2018 12:52
Lumberjack Pagination
<?php
namespace App\PostTypes;
use Rareloop\Lumberjack\QueryBuilder\Post as LumberjackPost;
class Post extends LumberjackPost
{
public static function paginate($perPage = 10)
{
@adamtomat
adamtomat / 0-Gruntfile.js
Created August 17, 2017 15:47
Combining Prism.js languages
module.exports = function(grunt) {
pkg = grunt.file.readJSON('package.json');
require('load-grunt-config')(grunt, pkg);
require('load-grunt-tasks')(grunt, pkg);
// ...
grunt.registerTask('prism', ['concat', 'uglify']);
@adamtomat
adamtomat / 0_description.md
Last active May 2, 2017 09:13
Test auth middleware on API routes - Laravel 5.4

When following TDD you shouldn't be writing any application code without writing a test first. This applies to middleware on routes too, however writing a specific test for every route is time consuming.

I decided to write a single test file that knew which endpoints on my API can and cannot be accessed with valid auth credentials.

Here I'm using Passport's Client Credentials to protect endpoints, but you should be able to tweak this file for any auth method.

Data providers

This file only consists of 3 tests:

@adamtomat
adamtomat / 0_description.md
Last active April 28, 2017 16:08
Laravel Any/Or Middleware

Sometimes you may run into cases where you would like at least 1 middleware to pass from multiple middlewares.

Laravel cannot do this out of the box, so I created a middleware that proxies other middleware and passes as soon as one passes.

@adamtomat
adamtomat / TestCase.php
Last active April 2, 2023 12:44
Laravel 5.4 - Disable Exception Handling for tests, with reminder to enable it when green
<?php
namespace Tests;
use App\Exceptions\Handler;
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
@adamtomat
adamtomat / routes.php
Last active August 29, 2015 14:22
Naming default implicit auth & password controller routes in Laravel 5.0
// By default, Laravel sets up the routes for auth/ and password/ using implicit controllers
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
// This means to get a url to the route, you need to do something like url('/auth/login')
@adamtomat
adamtomat / _sass-typeahead-bs3.scss
Created February 18, 2015 11:06
SASS for Typeahead for Bootstrap 3
// Inspired by byhays CSS version https://gist.github.com/bhays
.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
margin-bottom: 0;
}
.tt-hint {
color: #bbb;
color: rgba(0, 0, 0, .4);
@adamtomat
adamtomat / browser-sync-alias.md
Last active February 25, 2018 14:56
Bash Alias for Browser Sync

Wash your hands of remembering the command to proxy a url through Browser Sync

Usage:

$ sink localhost:4001

Instead of:

$ browser-sync start --proxy "localhost:4001" --files "css/*.css"
@adamtomat
adamtomat / _nesting-maps.scss
Created September 22, 2014 10:24
Nesting Sass maps
// Sass 3.3
$example: (
foo: (
x: 100,
y: 200
),
bar: (
x: 150,
y: 250
@adamtomat
adamtomat / _max.scss
Created September 22, 2014 09:22
Get largest value from a map in Sass using max()
// Sass 3.3
// This function can be used to get the largest number from a nested map. Currently only supports 1 sub-map.
// Uses max() to get the biggest number in a map
// See max() docs for reference: http://sass-lang.com/documentation/Sass/Script/Functions.html#max-instance_method
@function get-max($map, $key) {
$list: ();
// Loop through each item in the map
@each $map-key, $sub-map in $map {