Skip to content

Instantly share code, notes, and snippets.

View agarwa13's full-sized avatar

Nikhil Agarwal agarwa13

View GitHub Profile
@agarwa13
agarwa13 / AppServiceProvider.php
Last active November 5, 2015 02:23
Laravel 5.1 Event Listener that prevents emails from being sent to email addresses that have bounced previously.
<?php
// Filter Emails in the Bounce List
Event::listen('mailer.sending',function(\Swift_Message $swiftype_message){
// Get the Original Recipients of the Mail
$recipients = $swiftype_message->getTo();
// Log::info('Original Recepients: '.json_encode($recipients));
// Check if Any of the Email Addresses are in the Problem Emails Database
@agarwa13
agarwa13 / EmailController.php
Created November 5, 2015 02:26
Laravel 5.1 Controller that receives AWS SES Bounce and Complaint notifications sent via AWS SNS. It records the email addresses that bounced or complained in a database.
<?php
public function postBounceOrComplaint(Request $request, Mailer $mailer){
Log::info($request->json()->all());
if($request->json('Type') == 'SubscriptionConfirmation'){
$client = new Client();
$client->get($request->json('SubscribeURL'));
return response()->json();
@agarwa13
agarwa13 / migration.php
Last active November 5, 2015 02:36
Laravel 5.1 Migration that creates a table where we will store email addresses that have bounced or complained.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBadEmails extends Migration
{
/**
* Run the migrations.
*
@agarwa13
agarwa13 / notifications.blade.php
Created November 5, 2015 02:39
Laravel 5.1 Blade File that allows us to conveniently notify our users along with any response. Note we are using notifyjs to prettify our notifications.
<script src="{{asset('/vendor/notifyjs/notify.min.js')}}"></script>
<script>
$(document).ajaxComplete(function(event, xhr, settings){
$( ".log" ).text( "Triggered ajaxComplete handler." );
console.log(xhr.responseText);
response = $.parseJSON(xhr.responseText);
// Check for Notifications and Display Them
if(response.hasOwnProperty('notifications')){
for(var i=0; i< response.notifications.length; i++){
@agarwa13
agarwa13 / NotificationInsertion.php
Created November 5, 2015 02:40
Laravel 5.1 Middleware that ensures notifications set by the controller if any are sent along with any json responses.
<?php
namespace App\Http\Middleware;
use App\Services\Notification;
use Closure;
use Session;
class NotificationInsertion
{
@agarwa13
agarwa13 / Notification.php
Created November 5, 2015 02:42
Notification Service that manages an array in session. It allows us to specify notifications to send to the user in controllers and other locations conveniently.
<?php
/**
* Created by PhpStorm.
* User: Nikhil
* Date: 11/2/2015
* Time: 9:56 PM
*/
namespace App\Services;
@agarwa13
agarwa13 / facebook-pinterest-opengraph-incompatability.php
Created September 30, 2016 01:16
Solution for Pinterest and Facebook Open Graph Incompatibility on Article Author Meta Tag
if ( stripos( $_SERVER['HTTP_USER_AGENT'], 'Pinterest' ) !== false ) {
echo '<meta property="article:author" content="' . esc_attr( $author ) . '"/>' . "n";
} elseif ( !empty( $author_facebook ) ) {
echo '<meta property="article:author" content="http://www.facebook.com/' . esc_attr( $author_facebook ) . '"/>' . "n";
}
@agarwa13
agarwa13 / deploy.script
Created February 18, 2017 00:48
Deploy Script for Laravel Forge Site
cd /home/forge/bloggercasts.com
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader
if [ -f artisan ]
then
php artisan migrate --force
fi
@agarwa13
agarwa13 / acceleratorstrategies.com.css
Created May 3, 2017 00:54
CSS for acceleratorstrategies.com.css Footer
.footer-widget{
margin-bottom: 30px !important;
}
#footer-widgets{
padding-top: 30px !important;
}
@agarwa13
agarwa13 / hide-post-views.css
Created May 21, 2017 14:14
Big Hawaii Travel Hide Post Views
.post-views{
display: none;
}