Skip to content

Instantly share code, notes, and snippets.

View mauricius's full-sized avatar
🏠
Working from home

Maurizio Bonani mauricius

🏠
Working from home
View GitHub Profile
@mauricius
mauricius / ViewServiceProvider.php
Last active September 2, 2022 20:26
Fragment rendering in Laravel
<?php
use Illuminate\Support\Facades\View;
View::macro('renderFragment', function ($view, $fragment, array $data = []) {
$path = View::make($view, $data)->getPath();
$content = File::get($path);
$re = sprintf('/@section\("%s"\)(.*)@show/ms', $fragment);
@mauricius
mauricius / _func.php
Created November 3, 2019 12:22
Helper function to retrieve Textdomain in ProcessWire using TemplateEngineBlade
function getViewTextDomain($path)
{
$config = wire('config');
$input = str_replace('.', '-',
str_replace($config->paths->root, '', $path)
);
$re = '/\/+/m';
@mauricius
mauricius / RecapCommand.php
Created January 9, 2019 15:37
Print a recap of a Laravel/Symphony command before executing
<?php
class RecapCommand extends Command
{
public function handle()
{
$this->recapCommand();
if (! $this->confirm('Do you wish to continue?'))
{
@mauricius
mauricius / Preferences.sublime-settings
Last active December 4, 2018 09:48
SublimeText 3 Preferences
{
"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
"draw_white_space": "all",
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"save_on_focus_lost": true,
"theme": "Material-Theme.sublime-theme",
@mauricius
mauricius / reencode.bat
Created November 4, 2018 11:09
Batch script to re-encode MP3 files to different bitrate
set formats=*.mp3
set presets=-vn -ar 44100 -ac 2 -ab 192k -f mp3 -map_metadata 0 -id3v2_version 3
set outputext=mp3
# iterate through files and save in a 'reencoded' folder
for %%g in (%formats%) do start /b /wait "" "ffmpeg.exe" -i "%~dp0%%g" %presets% "reencoded/%%~ng.%outputext%" && TITLE "Converted: "%%g
@mauricius
mauricius / header.blade.php
Created May 23, 2018 11:03
Tachyons.css Mobile Menu
<nav id="site-navigation" aria-label="Menu" class="dn-l bg-maillis">
<ul id="main-menu" class="dn list pa0">
@if (auth()->check())
<li class="bb bw1 b--maillis-orange pv2 pl4"><span class="f6 white b">{{ auth()->user()->email }}</span></li>
<li><a class="f6 link white dib dim pv2 pl4" href="{{ route("auth.profile") }}">{{ trans("public.profile") }}</a></li>
<li><a class="f6 link white dib dim pv2 pl4" href="{{ route("auth.logout") }}">{{ trans("public.logout") }}</a></li>
@else
<li><a class="f6 link white dib dim pv2 pl4" href="{{ route("auth.login") }}">{{ trans("public.login") }}</a></li>
@endif
<li><a class="f6 link white dib dim pv2 pl4" href="{{ route("auth.register") }}">{{ trans("public.contact") }}</a></li>
@mauricius
mauricius / ContactForm.php
Last active September 18, 2020 17:28
Simple Class for building a Bootstrap-compatible Contact Form for ProcessWire
<?php
class ContactForm
{
var $form;
var $to = 'destination@email.com';
var $toName = 'Destination Name';
public function __construct()
@mauricius
mauricius / iron_maiden_songs.json
Created October 24, 2015 14:33
All Iron Maiden Songs in JSON format
[
"2 A.M.",
"2 Minutes to Midnight",
"22 Acacia Avenue",
"Aces High",
"Afraid to Shoot Strangers",
"The Aftermath",
"Age of Innocence",
"The Alchemist",
"Alexander the Great",
@mauricius
mauricius / TemplateEngineTwig.module
Last active August 29, 2015 14:22
Extend Processwire TemplateEngineTwig.module with the function to enable i18n translations.
protected function ___initTwig(Twig_Environment $twig)
{
$function = new Twig_SimpleFunction("__", function ($text, $filename = '', $context = '') use ($twig) {
if (!empty($filename)) {
if ($twig->getLoader()->exists($filename . '.twig')) {
$textdomain = $twig->getLoader()->getCacheKey($filename . '.twig');
$language = $this->user->language;
$out = htmlspecialchars($language->translator()->getTranslation($textdomain, $text, $context), ENT_QUOTES, 'UTF-8');
} else {
$out = $text;