Skip to content

Instantly share code, notes, and snippets.

Juan Pablo Balarini jpbalarini

Block or report user

Report or block jpbalarini

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jpbalarini
jpbalarini / sendgrid_send_email.md
Last active Aug 29, 2015
Setting up email with Sendgrid
View sendgrid_send_email.md

Generate the user mailer class

rails generate mailer UserMailer

Define the method for sending emails

class UserMailer < ActionMailer::Base
  include SendGrid
  sendgrid_category :use_subject_lines
View image_file_whitelist.rb
WHITELISTED_FORMATS = [
{ name: 'png', first_bytes: '89 50 4E 47 0D 0A 1A 0A' },
{ name: 'jpg1', first_bytes: 'FF D8 FF DB' },
{ name: 'jpg2', first_bytes: 'FF D8 FF E0' },
{ name: 'jpg3', first_bytes: 'FF D8 FF E1' },
{ name: 'ico', first_bytes: '00 00 01 00' },
{ name: 'gif1', first_bytes: '47 49 46 38 37 61' },
{ name: 'gif2', first_bytes: '47 49 46 38 39 61' },
{ name: 'tiff1', first_bytes: '49 49 2A 00' },
{ name: 'tiff2', first_bytes: '4D 4D 00 2A' },
@jpbalarini
jpbalarini / Bitnami_Amazon_EC2.md
Last active Feb 15, 2017
How to create a RoR Bitnami Amazon EC2 instance
View Bitnami_Amazon_EC2.md

RoR Bitnami Amazon EC2 instance

This guide will provide you some basic steps to create a Bitnami RoR Amazon EC2 instance, using Nginx with Passenger.

  1. Create an Amazon EC2 instance using a Community AMI. At the time of writing, the latest Bitnami AMI is: bitnami-rubystack-2.2.4-4-linux-ubuntu-14.04.1-x86_64-hvm-ebs Be careful to open SSH, HTTP and HTTPS ports on the "Step 6: Configure Security Group". You will need to save also the certificate to later connect to the instance.

  2. Log in by SSH to the instance:

@jpbalarini
jpbalarini / downloader_server.js
Created Jan 22, 2019
Pupeteer downloder server
View downloader_server.js
const puppeteer = require('puppeteer')
const express = require('express')
const bodyParser = require('body-parser')
const crypto = require('crypto')
const fs = require('fs')
const port = 3000
var app = express()
app.use(bodyParser.json())
@jpbalarini
jpbalarini / test_status_codes.sh
Last active Jan 22, 2019
Batch check URL status code
View test_status_codes.sh
#!/bin/bash
# usage: sh test_status_codes.sh URLs.txt
# example output: https://www.google.com 200
# It saves all output to url_statuses.txt
FILENAME="$1"
if [ -z "$FILENAME" ]; then
echo "Usage: test_status_codes.sh URLs.txt"
exit
fi
@jpbalarini
jpbalarini / rails_dev.md
Last active Feb 8, 2019
Mac OS Sierra Rails development
View rails_dev.md

How to configure your Mac OS for Ruby on Rails development

  1. Install Sublime Text from here
  2. Install Xcode from the AppStore
  3. Open Xcode and accept the licence
  4. Install command line tools. From the terminal run:
    xcode-select --install
    
  5. Install homebrew
@jpbalarini
jpbalarini / action_cable_send_backend.js
Created Jun 19, 2019
How to execute a method on rails via action cable
View action_cable_send_backend.js
socket = new WebSocket('ws://localhost:3000/api/v1/action_cable');
const onMessage = (ws, store) => evt => {
let msg = JSON.parse(evt.data);
if (msg.type === "ping") {
return;
}
console.log("FROM RAILS: ", msg);
}
socket.onmessage = onMessage(socket);
@jpbalarini
jpbalarini / application_controller.rb
Last active Oct 31, 2019
Ruby on Rails CORS Preflight Check
View application_controller.rb
before_action :cors_set_access_control_headers
def cors_preflight_check
if request.method == 'OPTIONS'
cors_set_access_control_headers
render text: '', content_type: 'text/plain'
end
end
protected
You can’t perform that action at this time.