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
<IfModule mod_ssl.c>
<VirtualHost *:443>
Include conf/vhosts/domain.vhost
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
@niraj-shah
niraj-shah / getIP.js
Created March 5, 2018 17:19
AWS Lambda IP Example
// include the libraries we need
var request = require('request');
var cheerio = require('cheerio');
// set some defaults
req = request.defaults({
jar: true, // save cookies to jar
rejectUnauthorized: false,
followAllRedirects: true // allow redirections
});
@niraj-shah
niraj-shah / aws_sms_example.php
Last active January 17, 2018 17:07
Using AWS SNS to send SMS messages
<?php
require 'vendor/autoload.php';
$sdk = new Aws\Sns\SnsClient([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => ['key' => 'xxx', 'secret' => 'xxx']
]);
$result = $sdk->publish([
@niraj-shah
niraj-shah / docker_commands.sh
Created January 12, 2018 22:06
Docker Usage and Examples
# get list of docker images
docker images
# build docker image
docker build -t <repo>/<name>:<version> ./path/to/directory
# example: docker build -t nirajshah/php7:v0.3 .
# run a command in container
docker run <img_id> <command>
# example: docker run bbd53c8ffa96 php -v
@niraj-shah
niraj-shah / CSPortalController.php
Created November 28, 2017 09:23
Using the ResetsPasswords trait in Laravel 5.2 to trigger a password reset
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request as LaravelRequest;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Redirect;
use Request;
@niraj-shah
niraj-shah / AuthController.php
Created October 23, 2017 09:59
Updating the Password Policy in Laravel 5.x's AuthController.php file
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:8|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).+$/',
], [
'password.regex' => 'Password must contain at least 1 lower-case and capital letter, a number and symbol.'
]);
}
@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