Skip to content

Instantly share code, notes, and snippets.

View jordangraft's full-sized avatar

Jordan Graft jordangraft

View GitHub Profile
@jordangraft
jordangraft / install-s3distcp.sh
Created February 8, 2017 10:34
install-s3distcp.sh
$ s3cmd get s3://us-east-1.elasticmapreduce/libs/s3distcp/1.latest/s3distcp.jar
$ hadoop jar ./s3distcp.jar --src s3a://<bucket>/input/ --dest=s3a://<bucket>/output
@jordangraft
jordangraft / s3cmd-installation.sh
Created February 8, 2017 10:33
S3 Massive Data Transfer Hadoop Job
$ wget http://ufpr.dl.sourceforge.net/project/s3tools/s3cmd/1.6.1/s3cmd-1.6.1.tar.gz
$ tar xzf s3cmd-1.6.1.tar.gz
$ cd s3cmd-1.6.1
$ sudo python setup.py install
$ ./s3cmd --configure
# Add in your Access and secret keys
# Enter through the remaining prompts
# Save configuration
@jordangraft
jordangraft / site
Created February 8, 2017 10:12
Nginx sites configuration file for pushing caching headers
# in you sites-available files
# gzip all asset requests
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Access-Control-Allow-Origin *;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi|eof|ttf|woff|woff2)$ {
@jordangraft
jordangraft / application.rb
Created February 8, 2017 10:08
Rack-Cors configuration for Cloudfront
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
@jordangraft
jordangraft / initial_setup
Last active April 28, 2016 19:47
Linux ubuntu
nano /etc/ssh/sshd_config # change PermitRootLogin to no and PasswordAuthentication to no
sudo service ssh restart
sudo apt-get update
sudo apt-get install ntp ufw git fail2ban default-jre nodejs
sudo dpkg-reconfigure tzdata
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
rails g scaffold email from:string body:text to:string subject:string
class EmailsController < ApplicationController
##
# Receive the AWS post, validate the token and pass to our model method
def incoming
if params[:token] && (params[:token] == 'test_token')
@email = Email.process_incoming_email(params[:message_id])
if @email.valid?
render text: 'email created', status: :created
else
class Email < ActiveRecord::Base
def self.process_incoming_email(message_id)
obj = AWS::S3.new.buckets['my-email-bucket'].objects[message_id]
contents = obj.read
from = contents.match(/(?<=From: )(.*?)(?=\n)/).try(:to_s)
to = contents.match(/(?<=To: )(.*?)(?=\n)/).try(:to_s)
subject = contents.match(/(?<=Subject: )(.*?)(?=\n)/).try(:to_s)
body = contents.match(/(?<=Content-Type: text\/html; charset\=UTF-8)(.*?)(?=--)/m).try(:to_s)
self.create(
config.before do
WebMock.disable_net_connect!(allow_localhost: true)
stub_request(:get, "https://my-email-bucket.s3.amazonaws.com/test")
.to_return(status: 200, body: File.read('spec/support/lambda_email'))
end
var AWS = require('aws-sdk');
var https = require('https');
exports.handler = function(event, context) {
var sesNotification = event.Records[0].ses;
var messageId = sesNotification.mail.messageId;
var receipt = sesNotification.receipt;
var from = sesNotification.mail.commonHeaders.from[0];
var appUrl = 'https://www.example.com'