Skip to content

Instantly share code, notes, and snippets.

View martinbean's full-sized avatar

Martin Bean martinbean

View GitHub Profile
@martinbean
martinbean / convert-seconds.js
Created July 13, 2016 08:03
Convert seconds to HH:MM:SS format in JavaScript.
new Date(seconds * 1000).toISOString().substr(11, 8)
@martinbean
martinbean / Shareable.php
Created January 14, 2024 20:56
Shareable
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Shareable extends Model
{
public function source(): MorphTo
@martinbean
martinbean / pre-commit
Last active December 19, 2023 22:14
Pre-commit hook to detect if any .php files contain dd()
#!/usr/bin/php
<?php
$files = shell_exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD | grep "\.php$"');
$files = explode("\n", trim($files));
$exitCode = 0;
foreach ($files as $file) {
if (empty($file)) {
@martinbean
martinbean / CartPage.php
Created March 15, 2019 22:06
Laravel Dusk example test
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class CartPage extends Page
{
/**
* {@inheritDoc}
@martinbean
martinbean / Stack.php
Created September 8, 2023 11:17
Laravel stack Blade component
<?php
namespace App\View\Components;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use InvalidArgumentException;
class Stack extends Component
{
@martinbean
martinbean / error-bag.ts
Created August 10, 2023 16:23
Vue.js form object
export default class {
public errors: Record<string, string[]>;
constructor(errors: Record<string, string[]> = []) {
this.errors = errors;
}
set(errors: Record<string, string[]>) {
this.errors = errors;
}
@martinbean
martinbean / WHOIS look-up bookmark
Created October 26, 2010 10:06
Want to quickly do a WHOIS look-up of the domain of the current website you're browsing? Simple save the following snippet as a bookmark in your favourite WebKit-enabled web browser...
javascript:var loc=window.location.host;window.location.href='http://whois.domaintools.com/'+loc;
@martinbean
martinbean / ArticleController.php
Created March 26, 2018 13:35
Using Laravel’s Responsable interface to create view models
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Http\Views\ArticleIndex;
class ArticleController extends Controller
{
public function index()
@martinbean
martinbean / Invitation.php
Created March 29, 2023 12:33
Basic Laravel-based invitation system
<?php
namespace App\Models;
class Invitation extends Model
{
protected $fillable = [
'token',
'email',
];
@martinbean
martinbean / google-feed.php
Created December 20, 2012 12:14
Building a Google RSS feed with DOMDocument.
<?php
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->formatOutput = true;
$rss = $xml->createElement('rss');
$rss->setAttribute('version', '2.0');
$rss->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:g', 'http://base.google.com/ns/1.0');
$xml->appendChild($rss);