Skip to content

Instantly share code, notes, and snippets.

View matthew-inamdar's full-sized avatar

Matthew Inamdar matthew-inamdar

View GitHub Profile
@matthew-inamdar
matthew-inamdar / auth.js
Last active March 14, 2020 20:12
Implementing basic auth with the Serverless Framework
exports.handler = (evt, ctx, callback) => {
const authorizationHeader = evt.headers.Authorization;
if (!authorizationHeader) {
return callback("Unauthorized");
}
const encodedCreds = authorizationHeader.split(" ")[1];
const [username, password] = Buffer.from(encodedCreds, "base64")
.toString()
{
"message": "The given data was invalid.",
"errors": {
"username": [
"The username cannot include spaces",
"The username must contain at least 1 letter and number"
],
"password": [
"The password must be longer than 8 characters"
]
@matthew-inamdar
matthew-inamdar / .php_cs
Created May 21, 2019 14:08
PHP-CS-Fixer Config
<?php
declare(strict_types=1);
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = Finder::create()
->in(__DIR__)
->exclude([
@matthew-inamdar
matthew-inamdar / helpers.php
Created January 9, 2019 11:18
Function to combine a Laravel query with the bindings and output as a string.
<?php
/**
* Outputs the query with bindings inserted.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return string
*/
function combine_query(\Illuminate\Database\Eloquent\Builder $query): string
{
@matthew-inamdar
matthew-inamdar / CsvAndArrayParser.php
Created December 3, 2018 15:16
Parse a CSV string to an array and vice versa
<?php
/**
* @param string $content
* @return array
*/
function csv_to_array(string $content): array
{
$rows = str_getcsv($content, "\n");
@matthew-inamdar
matthew-inamdar / helpers.php
Created October 29, 2018 17:55
A function to crop an image from the center (1:1) and resize it
<?php
/**
* @param string $content
* @param int $width
* @param int $height
* @return string
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
function crop_and_resize(string $content, int $width, int $height): string
@matthew-inamdar
matthew-inamdar / vagrant.sh
Created September 24, 2018 15:13
SSH into vagrant box and share ports from host machine
# Where 12345 is the host port and 80 is what it maps to.
vagrant ssh -- -R 12345:localhost:80
@matthew-inamdar
matthew-inamdar / helpers.php
Created August 28, 2018 09:32
Register enum as string in Laravel migrations
<?php
if (!function_exists('register_enum_type')) {
/**
* Registers the enum type as a string.
* Call this in the constructor of your migration.
*/
function register_enum_type()
{
\Illuminate\Support\Facades\Schema::getConnection()
@matthew-inamdar
matthew-inamdar / BladeServiceProvider.php
Last active July 13, 2018 14:22
Add custom file extensions to blade
<?php // app/Providers/BladeServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
@matthew-inamdar
matthew-inamdar / Flatten.php
Last active July 5, 2018 08:56
Flatten Multidimensional Array to HTML Input Name Array
<?php
use Illuminate\Http\UploadedFile;
class Flatten
{
/**
* Used for turning an array into a PHP friendly name.
*
* @param array $array