Skip to content

Instantly share code, notes, and snippets.

View niraj-shah's full-sized avatar
🏠
Working from home

Niraj Shah niraj-shah

🏠
Working from home
View GitHub Profile
@niraj-shah
niraj-shah / ai.php
Created March 31, 2026 13:28
WordPress AI Client example
<?php
include 'vendor/autoload.php';
use WordPress\AiClient\AiClient;
use WordPress\GoogleAiProvider\Provider\GoogleProvider;
// 1. Set your API key securely
putenv('GOOGLE_API_KEY=YOUR-GOOGLE-AI-API-KEY');
// 2. Register the provider with the default registry
@niraj-shah
niraj-shah / sphp
Last active March 26, 2026 15:59
Script to switch PHP versions on macOS using brew
#!/bin/bash
# Creator: Phil Cook
# Modified: Andy Miller, Niraj Shah
# add the following lines to the httpd.conf file for the script to work correctly, including the # prefix
# ---
# #LoadModule php7_module /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so
# #LoadModule php_module /opt/homebrew/opt/php@8.4/lib/httpd/modules/libphp.so
# #LoadModule php_module /opt/homebrew/opt/php@8.5/lib/httpd/modules/libphp.so
# #LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
@niraj-shah
niraj-shah / adb_copy.sh
Last active March 27, 2026 06:35
Shell script to copy only new files using adb
# path to folder on the device
PHONE_PATH=/storage/self/primary/DCIM/Camera/
# path to copy files to
LOCAL_PATH=~/Camera/
# get list of files from the phone folder
adb shell ls -l $PHONE_PATH > file_list.txt
# filter only jpg and mp4 files
@niraj-shah
niraj-shah / cors.json
Created March 26, 2024 12:20
AWS S3 CORS Policy
[
{
"AllowedHeaders": [],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
@niraj-shah
niraj-shah / suspended.tmpl
Created June 9, 2023 10:17
cPanel Account Suspension Page
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Account Suspended</title>
<!-- Fonts -->
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:RevokeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
@niraj-shah
niraj-shah / lfd-v2.php
Last active March 25, 2024 00:30
LFD Reporting Script using Abuse IP DB v2 API
#!/usr/local/bin/php
<?php
// AbuseIPDB API v2 Key
$api_key = 'xxx';
// AbuseIPDB API v2 Endpoint
$api_endpoint = 'https://api.abuseipdb.com/api/v2/';
// AbuseIPDB User ID
#!/usr/local/bin/php
<?php
// get command line arguments
$args = $argv;
// AbuseIPDB API Key
$api_key = 'xxx';
// your AbuseIPDB User ID
@niraj-shah
niraj-shah / sequential.js
Created October 8, 2018 16:18
Sequential Ajax Calls using jQuery
// parameters for ajax calls
var items = [
{ 'gender': 'male', 'nat': 'US' },
{ 'gender': 'female', 'nat': 'GB' }
];
// function to trigger the ajax call
var ajax_request = function(item) {
var deferred = $.Deferred();
@niraj-shah
niraj-shah / PasswordProtectPDF.php
Last active August 15, 2018 21:39
Password Protecting PDFs using PHP
<?php
require "vendor/autoload.php";
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader;
use setasign\FpdiProtection\FpdiProtection;
class PasswordProtectPDF
{
protected $pdf = null;