Skip to content

Instantly share code, notes, and snippets.

@lionslair
lionslair / remove_pulse_inserts.sh
Last active March 21, 2024 01:51
Remove the pulse inserts from sql script
#!/bin/bash
# Check if the script received an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <sql_file>"
exit 1
fi
# Check if the file exists
if [ ! -f "$1" ]; then
@saeedvir
saeedvir / spatie laravel-medialibrary__save_media_without_a_model_relationship
Last active January 17, 2024 03:07
spatie/laravel-medialibrary , save media without a model relationship
#1- Create `Media` Model In App\Models
<?php
namespace App\Models;
use Spatie\MediaLibrary\HasMedia;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\InteractsWithMedia;
@darenc
darenc / logwatch.ps1
Last active December 1, 2022 17:54 — forked from rasher/latest_rideon.ps1
Monitor your Zwift log file and outputs the latest Ride On
# Copyright 2020 Jonas Häggqvist <rasher@rasher.dk>
#
# Usage of the works is permitted provided that this instrument is retained with the
# works, so that any entity that uses the works is notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
# This script monitors your Zwift log file and outputs the latest Ride On to a given
# output file. The output file is updated at most every N ms (6000), to try and follow
@laravel-shift
laravel-shift / .php-cs-fixer.php
Last active April 9, 2024 14:08
PHP CS Fixer - Laravel Coding Style Ruleset
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
@ethanclevenger91
ethanclevenger91 / after.sh
Last active May 24, 2024 15:24
Install PHP SQLSRV database extension on Laravel Homestead (probably works as a Laravel Forge recipe, too). Thanks @richvida
#!/bin/sh
PHP_MSSQL_DRIVERS=Ubuntu18-7.3
PHP_MSSQL_RELEASE=5.6.1
# Download and extract phpmysql drivers
sudo wget "https://github.com/Microsoft/msphpsql/releases/download/v${PHP_MSSQL_RELEASE}/${PHP_MSSQL_DRIVERS}.tar" -O - | tar -x
# Change Directory
cd $PHP_MSSQL_DRIVERS
@davidpiesse
davidpiesse / Schedulable.php
Last active September 7, 2023 15:22
Laravel Custom Class/Model Scheduling
<?php
//Don't forget to change the namespace!
namespace App\Traits;
use Cron\CronExpression;
use Illuminate\Support\Carbon;
use Illuminate\Console\Scheduling\ManagesFrequencies;
trait Schedulable{
@seidler2547
seidler2547 / convert_ha_sqlite2mysql.sh
Last active April 16, 2024 02:30
One-liner to convert an existing Home-Assistant SQLite database to MySQL
# prerequisites:
## install software
apt install mariadb-server libmariadbclient-dev sqlite3
## install mysqlclient in virtualenv
su -c 'homeassistant/bin/pip3 install mysqlclient --upgrade' -l homeassistant
## create database
mysql -e 'CREATE SCHEMA IF NOT EXISTS `hass_db` DEFAULT CHARACTER SET utf8'
## create user (use a safe password please)
mysql -e "CREATE USER 'hass_user'@'localhost' IDENTIFIED BY 'hass_pw'"
mysql -e "GRANT ALL PRIVILEGES ON hass_db.* TO 'hass_user'@'localhost'"
@mrofi
mrofi / mysql_backup.config
Last active February 20, 2023 13:41 — forked from tleish/mysql_backup.sh
Bash Script to backup all MySQL databases
[client]
user = "mysql_user"
password = "mysql_password"
host = "localhost"
@brunogaspar
brunogaspar / macro.md
Last active May 1, 2024 07:24
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@zabaala
zabaala / BindDatabaseServiceProvider.php
Last active March 2, 2021 07:50
php artisan db:log <start> <stop>
<?php
namespace App\Commands\Database;
use Illuminate\Support\ServiceProvider;
class BindDatabaseServiceProvider extends ServiceProvider
{
public function boot()
{