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 / PasswordController.php
Created October 23, 2017 09:39
Custom validation and error message in Laravel 5
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
/*
@niraj-shah
niraj-shah / delete_file.js
Created August 22, 2017 14:52
Deleting a file using the Cordova File Plugin
// access the persistent file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
// get the file named "config.json"
fs.root.getFile("config.json", { create: false }, function(fileEntry) {
// attempt to remove the file if it exists
fileEntry.remove(function() {
// delete successful
console.info('Config file has been deleted successfully.');
@niraj-shah
niraj-shah / laravel_sftp.php
Last active May 5, 2017 13:56
More SSH / SFTP Commands in Laravel 5.x
<?php
// get list of files / directories, returns array
SSH::getGateway()->getConnection()->nlist('.');
// get current working directory, returns string
SSH::getGateway()->getConnection()->pwd();
// check for directory, returns boolean
SSH::getGateway()->getConnection()->is_dir("Directory");
@niraj-shah
niraj-shah / forever.sh
Last active April 27, 2017 14:20
Process Checker Shell Script
#!/bin/bash
PIDFILE=/var/www/html/ajc.pid
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
@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 June 25, 2024 11:41
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;