Skip to content

Instantly share code, notes, and snippets.

@jangaraev
jangaraev / folders-size.sh
Created December 20, 2022 06:22
Lists packages in node modules and shows their size sorted from higher to lower
du -sh ./node_modules/* | sort -nr | grep '\dM.*'
DB::table('really_long_table_name as short_alias')
Model::from('table_name as table_alias')
const messageEl = document.querySelector('.message');
password.addEventListener('keyup', function (e) {
if (e.getModifierState('CapsLock')) {
messageEl.textContent = 'Caps lock is on';
} else {
messageEl.textContent = '';
}
});
@jangaraev
jangaraev / MorphMapServiceProvider.php
Last active August 17, 2022 10:13
Specifying map for morph relationships which enables short/human-friendly model names in DB
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class MorphMapServiceProvider extends ServiceProvider
{
@jangaraev
jangaraev / gist:aa9753420f01ed7c89d79afaf063441b
Last active May 18, 2022 04:38
Update 'required' validation to use translatable field names
Validator::replacer('required', function ($message, $attribute, $rule, $parameters) {
$attributeSanitized = $attribute;
if (Str::endsWith($attribute, '_id')) {
$attributeSanitized = substr($attribute, 0, -3);
}
$friendlyAttributeName = str_replace('_', ' ', $attribute);
$newAttributeName = Lang::has('fields.' . $attributeSanitized)
? __('fields.' . $attributeSanitized)
@jangaraev
jangaraev / test.php
Last active May 24, 2022 05:55
Check if browser supports webp
<?php
// plain PHP solution
$supportsWebp = strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false;
// Laravel solution
$supportsWebp = request()->accepts('image/webp');
@jangaraev
jangaraev / cmd.sh
Last active May 17, 2022 05:50
Setting up Laravel script with nginx + mysql + php
# installing nginx
sudo apt update
sudo apt install nginx
# firewall: opening appropriate ports
sudo ufw app list
sudo ufw allow 'Nginx Full'
sudo ufw status