Skip to content

Instantly share code, notes, and snippets.

@imliam
imliam / cmd.lua
Created April 26, 2017 16:01
Command line argument parsing
command_strings = {
'php artisan make="hi mate" heh "I have a value"',
"php artisan make:auth",
[[I "am" 'the text' and "some more text with '" and "escaped \" text"]],
[[1 2 word 2 9 'more words' 1 "and more" "1 2 34"]],
[[omo "This is a string!" size=14 font="Comic Sans" break= hmm "thing and 'thing'" ]]
}
function command_parse(s)
local t={}
/**
* Register a new wildcard route that returns a view if it exists.
*
* @param string $path
* @param string $viewDirectory
* @param array $data
* @return \Illuminate\Routing\Route
*/
\Route::macro('viewDir', function ($path, $viewDirectory = null, $data = []) {
$pathWithSegments = trim($path, '/') . '/{page?}';
@imliam
imliam / query_string.php
Last active November 9, 2019 15:52
Laravel 5 - URL Query String Helper
<?php
/*
|--------------------------------------------------------------------------
| Laravel 5 - URL Query String Helper
|--------------------------------------------------------------------------
|
| A helper function to take a URL string then quickly and easily add query
| string parameters to it, or change existing ones.
|
| url_queries(['order' => 'desc', 'page' => 2],
@imliam
imliam / take.php
Last active January 15, 2020 14:30
Run functions consecutively by piping through the result of one into the next.
<?php
if (! function_exists('take')) {
/**
* Run functions consecutively by piping through the result of one
* into the next.
*
* @param mixed $value A value
*
* @return object
*/
@imliam
imliam / example.php
Created August 23, 2018 20:17
Define a set of constants to be used as flags for bitmasked options.
<?php
set_bitmask_flags([
'FLAG_1',
'FLAG_2',
'FLAG_3',
'FLAG_4',
'FLAG_5',
]);
@imliam
imliam / operator-mono-lig.css
Created July 5, 2018 12:37
Use the Operator Mono Lig typeface on any website.
/** General websites **/
code { font-family: "Operator Mono Lig" !important; font-weight: 200; }
pre > code { font-family: "Operator Mono Lig" !important; font-size: 1.2em !important; font-weight: 200; }
/** GitHub **/
.blob-code-inner, .blob-num, .highlight pre { font-family: "Operator Mono Lig" !important; font-weight: 200; }
.pl-c, .pl-e { font-style: italic; }
.pl-c { color: #4CAF50; }
/** Prism JS **/
@imliam
imliam / bind_methods.php
Created January 10, 2018 18:10
Trait to dynamically bind methods to a class.
<?php
trait BindMethods
{
private $boundMethods = [];
public function bindMethod($methodName, $method) {
$this->boundMethods[$methodName] = Closure::bind($method, $this, get_class());
}

You can register the mixin class in the register method of a Laravel service provider:

use Illuminate\Foundation\Testing\TestResponse;

TestResponse::mixin(TestResponseMixin::class);
@imliam
imliam / popover-close-when-losing-focus.js
Created March 17, 2017 16:42
Bootstrap 4 - Close Popover When Losing Focus
/*
|--------------------------------------------------------------------------
| Bootstrap 4 - Close Popover When Losing Focus
|--------------------------------------------------------------------------
|
| A JavaScript snippet that closes a Bootstrap 4 popover when clicking off
| of it, but unlike the default behaviour, allows it to stay open when
| clicking within the popover itself.
*/
@imliam
imliam / popover-dom-content.html
Last active May 16, 2022 06:19
Bootstrap 4 - Load Popover Content From DOM
<div id="unique-id" style="display:none;">
<div class="popover-heading">This is a heading</div>
<div class="popover-body">This is HTML content that will be loaded inside a </div>
</div>
<span tabindex="0" role="button" data-toggle="popover" data-placement="bottom" data-popover-content="#unique-id">
Click me to load a popover
</span>