Skip to content

Instantly share code, notes, and snippets.

View AnandPilania's full-sized avatar
🎖️
Working from home

Anand Pilania AnandPilania

🎖️
Working from home
View GitHub Profile
@AnandPilania
AnandPilania / app\Listeners\LogActivity.php
Created February 21, 2024 13:18
Laravel Auth logging
<?php
namespace App\Listeners;
use App\Events;
use Illuminate\Auth\Events as LaravelEvents;
use Illuminate\Support\Facades\Log;
class LogActivity
{
public function login(LaravelEvents\Login $event)
@AnandPilania
AnandPilania / memoize.js
Last active February 21, 2024 01:31
Memoize a function
const memoize = (fn: any) =>
(
(cache = Object.create(null)) =>
(arg: any) =>
cache[arg] || (cache[arg] = fn(arg))
)();
// Calculate Fibonacci numbers
// const fibo = memoize((n: number) => (n <= 2 ? 1 : fibo(n - 1) + fibo(n - 2)));
// fibo(1); // 1
@AnandPilania
AnandPilania / README.md
Created February 8, 2024 09:38
Dynamic Conditional Checks in Laravel Eloquent Base Model

This Laravel Eloquent base model enhancement provides a dynamic method handling mechanism for conditional checks based on column values.

The __call magic method is utilized to interpret method calls ending with Is or IsNot. The associated column is extracted, and the method dynamically checks if the column's value matches or does not match specified values.

This allow to handle multiple parameters, enhancing its flexibility. This concise and expressive approach simplifies conditional checks, making the code more readable and adaptable in various scenarios.

// Assuming there's a 'status' column in the model

// Check if status is one of [1, 2, 3]
@AnandPilania
AnandPilania / README.md
Created December 8, 2023 11:07
Laravel: Pulse sample card - Inspire

Add the card to dashboard

<livewire:pulse-cards.inspire-card cols="3" />
@AnandPilania
AnandPilania / app\Concerns\ModelConcern.php
Created December 1, 2023 05:14
Laravel: Model common utility trait
<?php
namespace App\Concerns;
use DB;
use Illuminate\Database\Eloquent\Builder;
use Schema;
/**
* Trait ModelConcern
@AnandPilania
AnandPilania / app\Concerns\BelongsToTeam.php
Created December 1, 2023 05:04
Laravel: Simplify Access Controller with BelongsToTeam
<?php
namespace App\Concerns;
use App\Models\Team;
use Illuminate\Database\Eloquent\Builder;
trait BelongsToTeam
{
public static function boot()
@AnandPilania
AnandPilania / app\Models\Blog.php
Last active December 1, 2023 04:59
Laravel: Generate unique slug
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Blog extends Model
{
use HasFactory;
@AnandPilania
AnandPilania / README
Last active November 8, 2024 22:50
Task Scheduler BitLocker Unlock Script - PowerShell script automates the setup of a Task Scheduler task to unlock a BitLocker-encrypted drive upon user login.
# Task Scheduler BitLocker Unlock Script
This PowerShell script automates the setup of a Task Scheduler task to unlock a BitLocker-encrypted D: drive upon user login.
## Features:
- Generates a Task Scheduler XML definition and a corresponding PowerShell script to unlock the BitLocker-encrypted D: drive.
- Prompts the user for input, allowing them to choose whether to import the task into Task Scheduler.
- If the user presses Enter without providing input, the script defaults to 'Y' for task import.
- Provides an option to cancel the task creation if the user chooses not to import it.
@AnandPilania
AnandPilania / jquery.location.js
Created November 17, 2023 09:02
Reactive Location Service (jQuery Plugin)
(function ($) {
class LocationService {
static observers = [];
locationObj = {
lat: null,
lng: null,
location: null,
data: null,
};
@AnandPilania
AnandPilania / location.class.js
Created November 17, 2023 09:01
Reactive Location Service (JavaScript)
class LocationService {
static observers = [];
locationObj = {
lat: null,
lng: null,
location: null,
data: null,
};
static apiKeyIpstack = null;