Skip to content

Instantly share code, notes, and snippets.

View bmadigan's full-sized avatar

Brad Madigan bmadigan

View GitHub Profile
@bmadigan
bmadigan / Test.php
Last active November 9, 2020 20:09
sample livewire api component
<?php
namespace App\Http\Livewire\Accounts;
use Livewire\Component;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use App\Services\ApiHeaders;
class Test extends Component
@bmadigan
bmadigan / tinker-api.php
Created March 19, 2020 14:16
Larvel 7 HTTP Call Sample
Http::withHeaders([
'accept' => 'application/json'
])
->withToken('apiKey123')
->get('https://some.server.com/api/v1/customers')
->json();
@bmadigan
bmadigan / .new-laravel
Created February 10, 2020 20:17
Bash Create Laravel Project
# Usage:
# l project-name -a -g -d
#
# Available options:
# -a Authentication scaffolding with tests
# -g Add Github remote
# -d Create a fresh MySQL database
# Laravel Zonda
function l {
@bmadigan
bmadigan / convert.php
Created March 14, 2019 15:07
Currency conversion
<?php
/** @test */
public function it_converts_currency_to_cents_if_dollar_sign()
{
$this->assertEquals(6500, convertCurrencyToCents('$65'));
$this->assertEquals(6600, convertCurrencyToCents('$66.00'));
$this->assertEquals(6750, convertCurrencyToCents('$67.50'));
$this->assertEquals(2500, convertCurrencyToCents('25.00'));
$this->assertEquals(3300, convertCurrencyToCents('33'));
<?
// this script receives a Stripe dispute / chargeback and:
//
// - immediately refunds the payment
// - closes the user's account (in my DB, add your own code there)
//
// this is to automate dispute handling (because you never win a dispute on Stripe anyway)
// and by refunding avoiding the chargeback fee
//
@bmadigan
bmadigan / .zshrc
Created February 26, 2019 13:34
Zsh config
# Paths
export PATH=$HOME/bin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=$HOME/.composer/vendor/bin:$PATH
export PATH=vendor/bin:$PATH
export PATH=vendor/phpunit/phpunit:$PATH
export PATH="$HOME/.yarn/bin:$PATH"
# Setup xdebug
export XDEBUG_CONFIG="idekey=VSCODE"
@bmadigan
bmadigan / .functions
Last active August 9, 2020 17:20
ZSH Functions
# Switch PHP versions
phpv() {
valet stop
brew unlink php@7.1 php@7.2 php@7.4
brew link --force --overwrite $1
brew services start $1
composer global update
valet install
}
@bmadigan
bmadigan / .aliases
Last active October 3, 2023 06:18
ZSH Aliases
# Misc
# --------------------------------------------
alias s="subl"
alias rip="rm -rf"
alias vc="code"
alias p="pstorm"
alias dev="cd ~/dev"
alias codee="cd ~/Dropbox/Code"
alias c="composer"
alias cu="COMPOSER_MEMORY_LIMIT=-1 composer update"
@bmadigan
bmadigan / Install Imagemagick PHP 7.0
Created August 15, 2018 17:30 — forked from grumpysi/Install Imagemagick PHP 7.0
Install Imagemagick on Laravel Homestead box Ubuntu 14 + PHP 7.0
sudo apt-get update && sudo apt-get install -y imagemagick php-imagick && sudo service php7.0-fpm restart && sudo service nginx restart
@bmadigan
bmadigan / FakePaymentGateway.php
Last active October 26, 2017 12:58
Laravel TDD - FakePayment Gateway
<?php
namespace App\Billing;
class FakePaymentGateway implements PaymentGateway
{
const TEST_CARD_NUMBER = '4242424242424242';
private $charges;
private $tokens;