Skip to content

Instantly share code, notes, and snippets.

@Patabugen
Patabugen / setup-php-for-sqlserver.sh
Created October 16, 2023 14:56
Setup pdo_sqlsrv for PHP 8.2 in ubuntu:22.04
#!/bin/sh
# I use this to setup my Laravel 10 (sail) docker container to setup PDO_Sqlsrv
# Let pecl auto-configure our php.ini
pear config-set php_ini /etc/php/8.1/cli/php.ini
# Setup PHP to be able to connect to SQLServer.
# From here: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > /etc/apt/sources.list.d/mssql-release.list
@Patabugen
Patabugen / Kernel.php
Last active October 9, 2023 13:12 — forked from phillipsharring/Kernel.php
Laravel Artisan command to perform MySQL Dump using database connection information in the .env file. Posted 2016 Jan. Unsupported. Forked from https://gist.github.com/kkiernan/bdd0954d0149b89c372a
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://app.sunsama.com/*focus=true*
// @que
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
@Patabugen
Patabugen / StrServiceProvider.php
Created August 2, 2022 17:18
isMatch macro for Laravel fluent strings to check if a string matches a regex
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;
/**
* Add isMatch() method to Str helper and Stringable objects. isMatch is the love hild
@Patabugen
Patabugen / 1-DuskServiceProvider.php
Last active July 27, 2022 14:42
Laravel Dusk "waitForAjax" Macro (and an old CodeCeption one)
<?php
/**
* $browser->waitForAjax() macro for Laravel Dusk. See comment below for details.
**/
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Laravel\Dusk\Browser;
class DuskServiceProvider extends ServiceProvider
@Patabugen
Patabugen / MakeEntryLine.php
Last active July 26, 2022 16:06
Default shouldRun expectations in Laravel Actions
<?php
/**
* An example of overriding the shouldRun method to add the default expectations to the Mock,
* instead of redefining it in all your tests.
*
* You can still call MakeEntryLine::shouldRun()->andReturn(...)
* to override the default expectations.
*/
namespace App\Actions\Csv;
@Patabugen
Patabugen / Transaction.php
Created June 28, 2022 18:26
Eloquent Model event hook to allow inserting primary keys into SQL Server tables with IDENTITY_INSERT = off
<?php
class Transaction extends Model
{
protected $primaryKey = 'TransactionID';
/**
* Using Laravel to export data from a SQL Server Express 15.0 I ran into an issue when creating test models
* using my Eloquent Model Factory on some tables which did not have an Auto Incrementing primary
* key, and where the table was set to disallow inserting the Primary Key (IDENTITY_INSERT is set to OFF).
*
@Patabugen
Patabugen / disable-wp-is-mobile.php
Last active June 23, 2022 15:35
Workaround for Simple Share Buttons and front end caching
<?php
/**
* The Simple Share Buttons uses wp_is_mobile() to decide how to render front end
* pages, which is incompatible with frontend caching. So filter the check
* to always return the "mobile version" (unless we are in the admin backend).
*
* Bbeware! It overrides _all_ frontend calls, not just SSBA ones).
*
* Save this as a mu-plugin ( wp-content/mu-plugins/disable-wp-is-mobile.php )
* or paste it into your functions.php file
@Patabugen
Patabugen / clear-google-my-activity.js
Last active January 22, 2021 12:08
A little script to clear all your history at https://myactivity.google.com/myactivity
/**
* A little script to clear all your history at https://myactivity.google.com/myactivity
*
* Load Developer Console (usually F12), paste this into the Console and hit Enter (or Run).
*
* Doesn't use any cool magic, just simulates clicking on all the delete buttons.
**/
var ClearGoogleMyAccount =
{
@Patabugen
Patabugen / form_exporter.js
Created November 8, 2012 15:53
Form Exporter
/**
* This is a bit of code to make it easier to turn forms into PHP Arrays
* for use in scrapers etc.
* It's designed to be run from the console, e.g in Firebug. Just copy
* everything from this file into the console and hit Go. It shouldn't
* take much to turn it into a browser extension by someone with the know how.
**/
/**
* The arrays didn't seem to want to .concat, so I just call this