Skip to content

Instantly share code, notes, and snippets.

View hallindavid's full-sized avatar

David Hallin hallindavid

View GitHub Profile
@hallindavid
hallindavid / date-picker.blade.php
Created April 6, 2021 12:36
Laravel Livewire/AlpineJS PikaDay component (with weird date format MM/DD/YYYY)
<div
x-data="{ value: @entangle($attributes->wire('model')), picker: undefined }"
x-init="new Pikaday({ field: $refs.input, format: 'MM/DD/YYYY', onOpen() { this.setDate($refs.input.value) } })"
x-on:change="value = $event.target.value"
>
<input
{{ $attributes->whereDoesntStartWith('wire:model')->merge(['class' => 'border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm']) }}
x-ref="input"
type="text"
x-bind:value="value"
@hallindavid
hallindavid / post_deployment_script.sh
Created March 2, 2021 16:53
A post deployment script for Laravel apps (could work for others) that tries to generate as much information as possible, so the script is re-usable project to project, and user to user.
# This function retreives varaibles from your .env file (must be in same directory as this script)
read_var() {
VAR=$(grep $1 .env | xargs)
IFS="=" read -ra VAR <<<"$VAR"
echo ${VAR[1]}
}
######### SET YOUR VARIABLES #########
##-------------------##
@hallindavid
hallindavid / console.php
Created December 20, 2020 17:24
logs:clear artisan command for Laravel
Artisan::command('logs:clear', function () {
exec('rm ' . storage_path('logs/*.log'));
$this->comment('Logs have been cleared!');
})->describe('Clear log files');
@hallindavid
hallindavid / HTMLDecode.sql
Last active November 11, 2020 21:19
MySQL function to HTMLDecode a text value
CREATE FUNCTION `HTMLDecode`(x TEXT) RETURNS text CHARSET latin1
BEGIN
DECLARE TextString TEXT;
SET TextString = x;
SET TextString = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TextString,"<strong>", ""),"</strong>", ""),"<p>", ""),"</p>", "\n"),"<ul>", ""),"<li>", "- "),"</li>", "\n"),"</ul>", ""),"<br />", "\n"),"<br>", "\n"),"&amp;", "&"),"&nbsp;", " "),"&#39;", "'"),"&lt;", "<"),"&gt;", ">"),"&ndash;", "-"),"&bull;", "- "),"&rsquo;", "'"),"&hellip;", "..."),"&middot;", "- "),"&rdquo;", "'"),"&ldquo;", "'"),"&lsquo;", "'"),"&#x23;", "#"),"&frac12;", "1/2"),"&deg;", "°"),"<i>", ""),"</i>", ""),"&quot;",'"'),"&apos;",'"')
RETURN TextString;
@hallindavid
hallindavid / Codeigniter check_date callback
Created November 20, 2019 18:39
Codeigniter->form_validation->custom callback for check date which supports min date, max date and ensure formatted as YYYY-MM-DD
public function check_date($str)
{
$dts = date_create_from_format("Y-m-d", $str);
if ($dts == FALSE)
{
$this->form_validation->set_message('check_date', 'The {field} field is in an unreadable format');
return false;
}
$maxDate = date_create_from_format('Y-m-d', date('Y-m-d', strtotime('+1 day')));
if ($dts > $maxDate)