Skip to content

Instantly share code, notes, and snippets.

View paperscissors's full-sized avatar

paperscissors

  • Albany, NY
View GitHub Profile
@paperscissors
paperscissors / FieldRepeater.php
Created October 31, 2023 17:32
Laravel Livewire 3 Field Repeater
<?php
namespace App\Livewire;
use Livewire\Component;
class FieldRepeater extends Component
{
public array $rows = [];
public string $field;
switchphp () {
phpversion="$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d".")"
brew unlink php@$phpversion && brew link php@$1 && valet use php@$1 --force
}
<?php
public function getSummaryAttribute()
{
$summary = Str::words($this->description, 250, '...');
$summary = html_entity_decode($summary);
$summary = html_entity_decode($summary);
$summary = html_entity_decode($summary);
$summary = html_entity_decode($summary);
$summary = htmlspecialchars_decode($summary);
@paperscissors
paperscissors / switchphp.sh
Created August 19, 2022 13:41
Bash command to switch between multiple versions of PHP on MacOs, Homebrew, and Valet
switchphp () {
phpversion="$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d".")"
brew unlink php@$phpversion && brew link php@$1 && valet use php@$1 --force
}
# then switchphp 8.1, switchphp 7.4, whatever versions installed
@paperscissors
paperscissors / app.js
Created August 9, 2021 18:01
jquery content repeater
$('.repeater').on('click', '.repeater-btn', function(e) {
e.preventDefault();
var $this = $(this),
$repeater = $this.closest('.repeater').find('[data-repeatable]'),
count = $repeater.length,
$clone = $repeater.first().clone();
$clone.find('[id]').each(function() {
this.id = this.id + '_' + count;
@paperscissors
paperscissors / AppServiceProvider.php
Last active March 2, 2021 21:41
LAravel response macro for file attachment download response
Response::macro('attachment', function ($content, $filename) {
$headers = [
'Content-type' => 'text/plain',
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
];
return Response::make($content, 200, $headers);
});
<?php
/**
* Complete the order, send notifications and invoice, if applicable
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function complete(Request $request)
{
$user = $request->user();
@paperscissors
paperscissors / intro.js
Created July 20, 2020 18:49
quick intro animation for multiple staggered elements
/*
.orc {
transition: top 1s ease 0s;
position: relative;
top: -3000px;
&.shown {
top: 0;
}
}
@paperscissors
paperscissors / email.blade.php
Created May 18, 2020 23:05
Obfuscate mailto: email links with base64 encoding and Javascript (blade file for example)
<a class="email" data-target="{{ base64_encode($email) }}" href="#">Email</a>
@paperscissors
paperscissors / compare.js
Created November 18, 2019 18:39
Intl.Collator loose comparison of diacritics with str.startsWith()
// probably not necessary to normalize, but let's cover our bets
var value = val.normalize()
var conjugation = this.conjugation.normalize()
// collator to do a loose comparison of characters. some characters like ț in Romanian
// have three or more versions, so this seems to resolve the issue
var collator = new Intl.Collator('ro', { sensitivity: 'base' })
// do the comparison, for feedback while they type
if (collator.compare(value.substring(0, value.length), conjugation.substring(0, value.length)) === 0) {