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 / 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"
@niraj-shah
niraj-shah / Kernel.php
Created February 21, 2017 13:18
Updating Laravel HTTP Kernel with new Middleware
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middleware = [
// ..
@niraj-shah
niraj-shah / InputTrim.php
Last active March 6, 2017 12:04
Laravel 5.2 Middleware to trim all input
<?php
namespace App\Http\Middleware;
use Closure;
class InputTrim
{
/**
* Handle an incoming request.
@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/
@niraj-shah
niraj-shah / remote.php
Last active May 5, 2018 12:02
Laravel config/remote.php file
<?php
return [
'default' => 'test',
'connections' => [
'production' => [
'host' => '111.111.111.111:22',
'username' => 'prod',
@niraj-shah
niraj-shah / laravel_ssh.php
Created December 6, 2016 20:53
Laravel SSH Commands
// see if file exists on remote
SSH::into($env)->exists( 'path/on/remote/filename.extension' );
// upload file to remote
SSH::into($env)->put( 'path/to/local/filename', 'path/on/remote/filename' );
// run a command - only works on SSH connections
SSH::into($env)->run( 'shasum path/on/remote/filename.extension', function( $line ) {
// display output of command, by line
echo $line;
@niraj-shah
niraj-shah / moment_tz_examples.js
Last active November 21, 2016 22:03
Timezone support using Moment.js
// get the user's timezone
var tz = moment.tz.guess();
console.info('Timezone: ' + tz);
// returns: Timezone: Europe/London
// set the default user timezone
moment.tz.setDefault(tz);
// set custom timezone
moment.tz.setDefault('America/Los_Angeles');
@niraj-shah
niraj-shah / debug-signing.properties
Created November 21, 2016 21:14
Debug Build Signing for Cordova
# location of keystore
storeFile=/path/to/app.keystore
# Key alias
keyAlias=alias_name
# Store password
storePassword=Password1
# Key password
@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 / eid_regex.php
Last active February 4, 2022 09:46
PHP Regex to validate Emirates ID number
<?php
/**
* Regex example to validate the format of a Emirates
* ID number. Does not validate the checkbit (Luhn Algorithm).
*
* @author Niraj Shah <niraj@webniraj.com>
*/
// regex to validate the format xxx-xxxx-xxxxxxx-x (Emirates ID)