Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<title>PdfLayout</title>
<style>
@page {
size: A4;
margin-top: 56px;
margin-bottom: 15px;
margin-left: 8px;
@jpbalarini
jpbalarini / action_cable_send_backend.js
Created June 19, 2019 14:31
How to execute a method on rails via action cable
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 / downloader_server.js
Created January 22, 2019 14:35
Pupeteer downloder server
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 January 22, 2019 16:15
Batch check URL status code
#!/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 / application_controller.rb
Last active November 19, 2021 16:00
Ruby on Rails CORS Preflight Check
before_action :cors_set_access_control_headers
def cors_preflight_check
return unless request.method == 'OPTIONS'
cors_set_access_control_headers
render json: {}
end
protected
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 February 15, 2017 20:57
How to create a RoR Bitnami Amazon EC2 instance

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 / rails_dev.md
Last active January 26, 2020 12:37
Mac OS Sierra Rails development

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 / sendgrid_send_email.md
Last active August 29, 2015 14:08
Setting up email with Sendgrid

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