Navigation Menu

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 / cors.json
Created March 26, 2024 12:20
AWS S3 CORS Policy
[
{
"AllowedHeaders": [],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
@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
@niraj-shah
niraj-shah / fb_tab_app_4.0.x.php
Last active January 22, 2024 11:42
Creating a Facebook Page Tab App using the Facebook PHP SDK 4.0.x
<?php
// required Facebook PHP SDK v4.0.9 or later.
// include required files form Facebook SDK
require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
require_once( 'Facebook/HttpClients/FacebookCurl.php' );
require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );
require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/Entities/SignedRequest.php' );
@niraj-shah
niraj-shah / certificate_pdf.php
Created September 12, 2016 20:36
Creating a PDF using FPDF and PHP
<?php
// include composer packages
include "vendor/autoload.php";
// Create new Landscape PDF
$pdf = new FPDI('l');
// Reference the PDF you want to use (use relative path)
$pagecount = $pdf->setSourceFile( 'certificate.pdf' );
@niraj-shah
niraj-shah / index.php
Created June 24, 2014 17:41
PHP file to redirect visitors to iOS or Android app files
<?php
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
$iPod = stripos( $_SERVER['HTTP_USER_AGENT'], "iPod" );
$iPhone = stripos( $_SERVER['HTTP_USER_AGENT'], "iPhone" );
$iPad = stripos( $_SERVER['HTTP_USER_AGENT'], "iPad" );
$Android = stripos( $_SERVER['HTTP_USER_AGENT'], "Android" );
$webOS = stripos( $_SERVER['HTTP_USER_AGENT'], "webOS" );
@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 -->
@niraj-shah
niraj-shah / page_post.php
Last active May 16, 2023 10:32
Posting to a Page using Facebook PHP SDK v4.0.x and Graph API v2.x
<?php
// post to page
$page_post = (new FacebookRequest( $session, 'POST', '/'. $page_id .'/feed', array(
'access_token' => $access_token,
'name' => 'Facebook API: Posting As A Page using Graph API v2.x and PHP SDK 4.0.x',
'link' => 'https://www.webniraj.com/2014/08/23/facebook-api-posting-as-a-page-using-graph-api-v2-x-and-php-sdk-4-0-x/',
'caption' => 'The Facebook API lets you post to Pages you administrate via the API. This tutorial shows you how to achieve this using the Facebook PHP SDK v4.0.x and Graph API 2.x.',
'message' => 'Check out my new blog post!',
) ))->execute()->getGraphObject()->asArray();
@niraj-shah
niraj-shah / aws-security.sh
Last active February 13, 2023 23:52
Shell Script to update AWS EC2 Security Groups with Fixed and Current IPs for a given Port, using `aws ec2` command line
#!/bin/bash
# Shell Script to Update AWS EC2 Security Groups
# Note that existing IP rules will be deleted
# CONFIG - Only edit the below lines to setup the script
# ===============================
# AWS Profile Name
profile="name1"
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:RevokeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
@niraj-shah
niraj-shah / replicate_db.sh
Last active July 7, 2022 20:39
Script to Replicate Database from Remote to Local
#!/bin/bash
# replicate_db.sh (c) by Niraj Shah
# replicate_db.sh is licensed under a
# Creative Commons Attribution-ShareAlike 4.0 International License.
# You should have received a copy of the license along with this
# work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
# https://www.webniraj.com/2017/01/13/replicating-a-remote-mysql-database-to-local-environment-server/