Skip to content

Instantly share code, notes, and snippets.

View thmsbkkr's full-sized avatar

Thomas Bakker thmsbkkr

  • https://gorilla.co/
  • Antwerpen, Belgium
View GitHub Profile
@thmsbkkr
thmsbkkr / AddressFilter.php
Last active February 12, 2019 15:13
Address Filtering
<?php
/**
* Filter the model using value.
*
* @param Builder $builder
* @param $value
* @return mixed
*/
public function filter(Builder $builder, $value, $direction)
@thmsbkkr
thmsbkkr / TestHelpers.php
Created June 6, 2018 01:10
Functions for Laravel factories in tests
<?php
function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
function make($class, $attributes = [], $times = null)
{
return factory($class, $times)->make($attributes);
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
@thmsbkkr
thmsbkkr / ExceptionHandling.php
Last active July 24, 2017 13:16
Disable exception handling by default, enabling is optional per test
<?php
namespace Tests;
use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler;
trait ExceptionHandling
{
protected function setUp()
@thmsbkkr
thmsbkkr / FactoryHelpers.php
Last active February 21, 2018 03:35
A helper trait for working with factories in tests
<?php
namespace Tests;
trait FactoryHelpers
{
public function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
@thmsbkkr
thmsbkkr / in_viewport.js
Last active October 13, 2020 09:32 — forked from jjmu15/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
export default function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@thmsbkkr
thmsbkkr / AuthController.php
Last active June 22, 2016 19:46
It enables multiple database connections on user registration.
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create($connection, array $data)
{
$user = new User();
var elixir = require('laravel-elixir');
elixir.config.css.sass.pluginOptions.includePaths = [
'node_modules/bootstrap/scss',
];
elixir(function(mix) {
mix.sass('app.scss')
.browserify('app.js')
.version(['css/app.css', 'js/app.js'])
<?php
namespace App;
class BladeDirective
{
protected $cache;
public function __construct(RussianCache $cache)
{
for ($i = 0; $i < 10; i++) {
// Do something
}
// Much better looking
foreach (range(0,9) as $i) {
// Do something
}