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\Console\Commands\CheckResourceRoutesCommamd.php
Created August 1, 2024 16:10
Laravel: find missing methods in reaource routes.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Route;
use ReflectionClass;
class CheckResourceRoutesCommand extends Command
{
@AnandPilania
AnandPilania / index.js
Created July 22, 2024 03:46
SolidJS implementation of signals from scratch using the Pub-Sub pattern.
import { createSignal, createEffect } from "./signal.js";
const [name, setName] = createSignal("Reyansh");
const [age, setAge] = createSignal(2.5);
// Effects automatically subscribes to signals used within
createEffect(() => {
// Runs whenever the count changes
console.log(`Name: ${name()}, Age: ${age()}`);
});
@AnandPilania
AnandPilania / index.js
Created July 22, 2024 03:46
SolidJS implementation of signals from scratch using the Pub-Sub pattern.
import { createSignal, createEffect } from "./signal.js";
const [name, setName] = createSignal("Reyansh");
const [age, setAge] = createSignal(2.5);
// Effects automatically subscribes to signals used within
createEffect(() => {
// Runs whenever the count changes
console.log(`Name: ${name()}, Age: ${age()}`);
});
@AnandPilania
AnandPilania / use-browser-ai.js
Created July 17, 2024 15:07
Google Chrome's experimental (canary build) language model web API
// Assume inputText is a string containing the text you want to prompt the AI with.
const inputText = "What is the capital of India?";
async function useAI() {
try {
// Create a text session with the AI
const session = await window.ai.createTextSession();
// Get a streaming response from the AI
const result = session.promptStreaming(inputText);
@AnandPilania
AnandPilania / blank.js
Last active April 2, 2024 11:16
Enhance Your Website Notifications with JavaScript Toasts
function blank(value) {
if(Array.isArray(value)) {
return value.length === 0;
}
if(value instanceof Date) {
return false;
}
if(typeof value === 'object' && value !== null) {
@AnandPilania
AnandPilania / README.md
Last active April 1, 2024 05:30
Enhanced jQuery Plugin for Observing Events

This gist provides a jQuery plugin for observing events, offering improved flexibility and functionality. The plugin supports various syntaxes, including object-based and chained function-based, and allows for observing both DOM and AJAX events. It also includes error handling and validation for input parameters.

<input id="input">
<select id="select">
  <option value="" selected></option>
  <option value="1">1</option>
@AnandPilania
AnandPilania / parseURL.js
Last active March 22, 2024 03:20
URL Parser - Easily extract protocol, host, path, query parameters, and more from any URL string (w/o URLSearchParams API).
/*
This JavaScript function parseURL takes a URL string as input and parses it into its various
components such as protocol, host, path, query parameters, and relative path. It utilizes
regular expressions to extract these components efficiently. The parsed components are then
encapsulated within an object for convenient access and manipulation in your code. This can
be useful in scenarios where you need to extract specific parts of a URL or analyze and modify
URLs dynamically within your web applications.
*/
function parseURL(url) {
@AnandPilania
AnandPilania / generateUUID.js
Last active March 21, 2024 13:43
UUID Generator
const generateUUID = () =>
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
var r = Math.random() * 16 | 0;
return (c == "x" ? r : (r & 0x3 | 0x8)).toString(16);
});
$1 = generateUUID();
$2 = generateUUID();
@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