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 / keyboardEventLogger.js
Last active October 23, 2023 10:24
JavaScript Keyboard Event Logger
document.addEventListener('keydown', function (e) {
let table = [];
['key', 'keyCode', 'which', 'code', 'location', 'altKey', 'ctrlKey', 'metaKey', 'shiftKey', 'repeat'].forEach(function (key, k) {
table.push({key: key, code: e[key]});
});
console.table(table.reduce((acc, {key, ...x}) => { acc[key] = x; return acc}, {}));
});
@AnandPilania
AnandPilania / use.js
Created October 22, 2023 10:06
JS Encryption
const js_code=`
const domain = "testro.com";
const from_year = 2023;
const copyright = "(c)" + from_year + "-" + new Date().getFullYear() + "," + domain;
console.log(copyright);
`;
const encrypted_code = enxor(js_code,"_0x31aca");
console.log(encrypted_code);
@AnandPilania
AnandPilania / LoadTestCommand.php
Last active September 28, 2023 10:39
Laravel Load Testing Command with GuzzleHttp
<?php
namespace App\Console\Commands;
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use Illuminate\Console\Command;
class LoadTestCommand extends Command
{
@AnandPilania
AnandPilania / README.md
Created September 23, 2023 05:04
Tailing Laravel Log Files : This Gist presents two variants for tailing Laravel log files, each with its own approach to reading and displaying log data.

Tailing Laravel Log Files - Two Variants

Overview

This Gist presents two variants for tailing Laravel log files, each with its own approach to reading and displaying log data.

Variant 1: Custom Laravel Console Command

  • File: app/Console/Commands/TailLogCommand.php
  • Description: This variant demonstrates how to create a custom Laravel console command to tail Laravel log files. The command accepts an optional argument to specify the number of lines to display and checks for the existence of log files before attempting to tail them. It also uses the Process component to execute the tail and grep commands for efficiency.

Variant 2: Direct Artisan Command in console.php

@AnandPilania
AnandPilania / index.html
Created August 30, 2023 09:15
Extensible VanillaJS
<!DOCTYPE html>
<html>
<head>
<title>myApp.js</title>
</head>
<body>
<script src="myApp.js"></script>
<script src="settings.js"></script>
<script src="utilities.js"></script>
</body>
@AnandPilania
AnandPilania / index.html
Created August 30, 2023 09:05
Code Sandbox
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Code Sandbox</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
margin: 1em auto;
@AnandPilania
AnandPilania / OptimisticLocking.php
Created July 18, 2023 05:32
The OptimisticLocking trait enables optimistic locking for Laravel models. It prevents conflicts when multiple users edit the same model simultaneously by using a "locking column"
<?php
namespace App\Concerns;
use Exception;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Support\Facades\Schema;
use InvalidArgumentException;
trait OptimisticLocking
@AnandPilania
AnandPilania / html.html
Created July 17, 2023 07:24
SwitchIt - Customizable JavaScript for Radio/Select Switch Element
<div id="switchElement" class="switch-element">
<label>
<input type="radio" name="switch" value="on">
<span></span>
</label>
<label>
<input type="radio" name="switch" value="default">
<span></span>
</label>
<label>
@AnandPilania
AnandPilania / switchIt.jquery.js
Created July 17, 2023 06:58
SwitchIt - Customizable jQuery Plugin for Radio/Select Switch Element
(function ($) {
$.fn.switchIt = function (options) {
var defaults = {
initialValue: 'default',
hasDefault: true,
onChange: null,
labels: {
on: 'On',
default: 'Default',
off: 'Off',
@AnandPilania
AnandPilania / CommandTrait.php
Last active July 12, 2023 11:34
Laravel helpers / supportive traits
// GET COMMAND DEFINED OPTIONS ONLY
<?php
namespace App\Console\Commands\Traits;
use Illuminate\Support\Arr;
trait CommandTrait
{