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 / 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;
@niraj-shah
niraj-shah / htaccess
Last active July 19, 2018 10:12
WordPress .htaccess Restrictions
# .htaccess file for root WordPress directory
# add this line if it's not already present in your .htaccess file
ErrorDocument 401 default
<Files "wp-login.php">
AuthName "WordPress Admin"
AuthUserFile "/path/to/passwd"
AuthType Basic
require valid-user
@niraj-shah
niraj-shah / download_svn.sh
Last active May 10, 2018 15:21
SVN Setup on EasyApache4
# move to home directory
cd ~/
# download svn source
wget https://archive.apache.org/dist/subversion/subversion-1.7.14.tar.bz2
# extract source
tar -xzvf subversion-1.7.14.tar.bz2
# enter extracted directory
@niraj-shah
niraj-shah / mydomain-ssl.conf
Last active March 21, 2018 15:35
Apache2 vhost and site config setup. `mydomain-ssl.conf` is the SSL site conf, `mydomain.conf` is the regular site conf, and `mydomain.vhost` is the vhost found in `/etc/apache2/conf/vhosts`.
<IfModule mod_ssl.c>
<VirtualHost *:443>
Include conf/vhosts/mydomain.vhost
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<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.'
]);
}