Skip to content

Instantly share code, notes, and snippets.

@dangerrg
Last active September 2, 2021 14:32
Show Gist options
  • Select an option

  • Save dangerrg/1ca1df312c6c4a6d8aae970d628c48bd to your computer and use it in GitHub Desktop.

Select an option

Save dangerrg/1ca1df312c6c4a6d8aae970d628c48bd to your computer and use it in GitHub Desktop.

Revisions

  1. dangerrg renamed this gist Sep 2, 2021. 1 changed file with 0 additions and 0 deletions.
  2. dangerrg revised this gist Sep 2, 2021. 2 changed files with 0 additions and 105 deletions.
    79 changes: 0 additions & 79 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,79 +0,0 @@
    source 'https://rubygems.org'

    git_source(:github) do |repo_name|
    repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
    "https://github.com/#{repo_name}.git"
    end

    ruby '2.6.3'

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 5.1.7'
    # Use postgresql as the database for Active Record
    gem 'pg', '>= 0.18', '< 2.0'
    # Use Puma as the app server
    gem 'puma', '~> 3.7'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2'
    # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
    gem 'turbolinks', '~> 5'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.5'
    # Use Redis adapter to run Action Cable in production
    # gem 'redis', '~> 4.0'
    # Use ActiveModel has_secure_password
    gem 'bcrypt', '~> 3.1.7'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
    # Adds support for Capybara system testing and selenium driver
    gem 'capybara', '>= 2.15'
    gem 'selenium-webdriver'
    end

    group :development do
    # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
    gem 'web-console', '>= 3.3.0'
    gem 'listen', '>= 3.0.5', '< 3.2'
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    gem 'spring'
    gem 'spring-watcher-listen', '~> 2.0.0'
    end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

    # Add Bootstrap for styling the application
    gem 'bootstrap', '~> 4.3.1'
    # Add JQuery as bootstrap dependency in Rails 5.1+
    gem 'jquery-rails'
    # Add Popper as bootstrap dependency for popups
    gem 'popper_js'
    # Add kaminari for setting pagination in our application
    gem 'kaminari'
    # Imagae uploads
    gem 'carrierwave', '~> 1.1.0'
    # AWS S3 storage
    gem 'figaro'
    gem "fog-aws"
    gem 'aws-sdk'
    # Geocoding with geocoder + GoogleMapsAPI
    gem 'geocoder'
    # Add markdown to give users more flexibility when writting posts or comments
    gem 'redcarpet', github: 'vmg/redcarpet'
    gem 'coderay'
    # For different versions of an image (it works together with carrierwave)
    gem 'mini_magick'
    # Use SendGrid adapter to run Action ActionMailer in production
    gem 'sendgrid-ruby'
    26 changes: 0 additions & 26 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -1,26 +0,0 @@
    class MessageMailer < ApplicationMailer
    require 'sendgrid-ruby'
    include SendGrid

    def contact(message)
    @message = message

    from = Email.new(email: 'no-reply@casineros-cubanos.com')
    to = Email.new(email: @message.email)
    subject = 'casineros cubanos Blog'
    content = Content.new(type: 'text/plain', value: "Hi dear #{@message.name}! Thanks for your massage, we will get back to you soon.")
    mail = SendGrid::Mail.new(from, subject, to, content)

    sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
    begin # to read error messages
    response = sg.client.mail._("send").post(request_body: mail.to_json)
    rescue Exception => e
    puts e.message
    end

    puts response.status_code
    puts response.body
    puts response.headers

    end
    end
  3. dangerrg revised this gist Sep 2, 2021. 4 changed files with 210 additions and 0 deletions.
    79 changes: 79 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    source 'https://rubygems.org'

    git_source(:github) do |repo_name|
    repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
    "https://github.com/#{repo_name}.git"
    end

    ruby '2.6.3'

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 5.1.7'
    # Use postgresql as the database for Active Record
    gem 'pg', '>= 0.18', '< 2.0'
    # Use Puma as the app server
    gem 'puma', '~> 3.7'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2'
    # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
    gem 'turbolinks', '~> 5'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.5'
    # Use Redis adapter to run Action Cable in production
    # gem 'redis', '~> 4.0'
    # Use ActiveModel has_secure_password
    gem 'bcrypt', '~> 3.1.7'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
    # Adds support for Capybara system testing and selenium driver
    gem 'capybara', '>= 2.15'
    gem 'selenium-webdriver'
    end

    group :development do
    # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
    gem 'web-console', '>= 3.3.0'
    gem 'listen', '>= 3.0.5', '< 3.2'
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    gem 'spring'
    gem 'spring-watcher-listen', '~> 2.0.0'
    end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

    # Add Bootstrap for styling the application
    gem 'bootstrap', '~> 4.3.1'
    # Add JQuery as bootstrap dependency in Rails 5.1+
    gem 'jquery-rails'
    # Add Popper as bootstrap dependency for popups
    gem 'popper_js'
    # Add kaminari for setting pagination in our application
    gem 'kaminari'
    # Imagae uploads
    gem 'carrierwave', '~> 1.1.0'
    # AWS S3 storage
    gem 'figaro'
    gem "fog-aws"
    gem 'aws-sdk'
    # Geocoding with geocoder + GoogleMapsAPI
    gem 'geocoder'
    # Add markdown to give users more flexibility when writting posts or comments
    gem 'redcarpet', github: 'vmg/redcarpet'
    gem 'coderay'
    # For different versions of an image (it works together with carrierwave)
    gem 'mini_magick'
    # Use SendGrid adapter to run Action ActionMailer in production
    gem 'sendgrid-ruby'
    79 changes: 79 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    source 'https://rubygems.org'

    git_source(:github) do |repo_name|
    repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
    "https://github.com/#{repo_name}.git"
    end

    ruby '2.6.3'

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 5.1.7'
    # Use postgresql as the database for Active Record
    gem 'pg', '>= 0.18', '< 2.0'
    # Use Puma as the app server
    gem 'puma', '~> 3.7'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2'
    # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
    gem 'turbolinks', '~> 5'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.5'
    # Use Redis adapter to run Action Cable in production
    # gem 'redis', '~> 4.0'
    # Use ActiveModel has_secure_password
    gem 'bcrypt', '~> 3.1.7'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
    # Adds support for Capybara system testing and selenium driver
    gem 'capybara', '>= 2.15'
    gem 'selenium-webdriver'
    end

    group :development do
    # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
    gem 'web-console', '>= 3.3.0'
    gem 'listen', '>= 3.0.5', '< 3.2'
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    gem 'spring'
    gem 'spring-watcher-listen', '~> 2.0.0'
    end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

    # Add Bootstrap for styling the application
    gem 'bootstrap', '~> 4.3.1'
    # Add JQuery as bootstrap dependency in Rails 5.1+
    gem 'jquery-rails'
    # Add Popper as bootstrap dependency for popups
    gem 'popper_js'
    # Add kaminari for setting pagination in our application
    gem 'kaminari'
    # Imagae uploads
    gem 'carrierwave', '~> 1.1.0'
    # AWS S3 storage
    gem 'figaro'
    gem "fog-aws"
    gem 'aws-sdk'
    # Geocoding with geocoder + GoogleMapsAPI
    gem 'geocoder'
    # Add markdown to give users more flexibility when writting posts or comments
    gem 'redcarpet', github: 'vmg/redcarpet'
    gem 'coderay'
    # For different versions of an image (it works together with carrierwave)
    gem 'mini_magick'
    # Use SendGrid adapter to run Action ActionMailer in production
    gem 'sendgrid-ruby'
    26 changes: 26 additions & 0 deletions gistfile2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    class MessageMailer < ApplicationMailer
    require 'sendgrid-ruby'
    include SendGrid

    def contact(message)
    @message = message

    from = Email.new(email: 'no-reply@casineros-cubanos.com')
    to = Email.new(email: @message.email)
    subject = 'casineros cubanos Blog'
    content = Content.new(type: 'text/plain', value: "Hi dear #{@message.name}! Thanks for your massage, we will get back to you soon.")
    mail = SendGrid::Mail.new(from, subject, to, content)

    sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
    begin # to read error messages
    response = sg.client.mail._("send").post(request_body: mail.to_json)
    rescue Exception => e
    puts e.message
    end

    puts response.status_code
    puts response.body
    puts response.headers

    end
    end
    26 changes: 26 additions & 0 deletions message_mailer.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    class MessageMailer < ApplicationMailer
    require 'sendgrid-ruby'
    include SendGrid

    def contact(message)
    @message = message

    from = Email.new(email: 'no-reply@casineros-cubanos.com')
    to = Email.new(email: @message.email)
    subject = 'casineros cubanos Blog'
    content = Content.new(type: 'text/plain', value: "Hi dear #{@message.name}! Thanks for your massage, we will get back to you soon.")
    mail = SendGrid::Mail.new(from, subject, to, content)

    sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
    begin # to read error messages
    response = sg.client.mail._("send").post(request_body: mail.to_json)
    rescue Exception => e
    puts e.message
    end

    puts response.status_code
    puts response.body
    puts response.headers

    end
    end
  4. dangerrg revised this gist Sep 2, 2021. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions Salsa Blog - Micro Social Network.md
    Original file line number Diff line number Diff line change
    @@ -60,13 +60,16 @@ https://casineros-cubanos.herokuapp.com/ (This version does not include the cont

    It sends automatic email responses to the user after submitting the form. On top of this, it will be used to send reminders and notify registered users when updates on the website are made. This works as expected in the development environment, but not in production.

    As developers, we learn that every single environment behaves completely different from each other. For me, it is a real challenge to make this feature work in the production environment. Initially, I got a lot of errors, but I could solve them. However, there is still one error: ``superclass mismatch for class Category (TypeError)`` which I have not been able to solve yet as the Gem installation gives a bug.
    ## Chalenges
    As developers, we learn that every single environment behaves completely different from each other.

    Nevertheless, I could send emails from the project to myself, in other words, I could test the implementation. Even though I get this bug, my professors told me to put it anyway in the project to demonstrate this implementation.
    1.- For me, it is a real challenge to make this feature (`Sendgrid`) to work in the production environment. Initially, I got a lot of errors, related to setup and `invalid or expired key` but I could solve them. However, the most challenging part was to solve the error: ``superclass mismatch for class Category (TypeError)`` which was provoked by due a typo in the class `category` table, wich is associated with the other models of the app.

    ## Amazon AWS S3 storage:
    2.- Another significant challenge was send out _`emails`_ in production. The as the `sendgrig-ruby` Gem installation was giving me a bug related with incompatibilities in some `dependencies`. That issue I solved with `heroku-ads-on`: "Twilio SendGrid" work-around.

    It is for users to upload images. I took advantage of Carrierwave and Minimagic gems to accomplish it. Also to ensure that users can only upload images and no other files.
    ## Amazon `AWS S3` storage:

    It is for users to upload images. I took advantage of `Carrierwave` and `Minimagic` gems to accomplish it. Also to ensure that users can only upload images and no other files.

    ## GoogleMaps API: (Geocoder gem)

  5. dangerrg created this gist Aug 30, 2021.
    92 changes: 92 additions & 0 deletions Salsa Blog - Micro Social Network.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    # Cuban Casineros (Casineros Cubanos)

    ## Description


    This web application is a Salsa Blog, called Casineros Cubanos, and it's about Salsa dance and music.

    It's like a micro-social network, intending to connect people who love Salsa and allow others to learn more about Cuban and Latino culture.

    With this on Blog, people can share their knowledge, passion, and experience, related to Salsa music and dance.
    Users can create, edit and categorize posts of a related topic. Also, they can upload videos and photos, make comments on other user's articles, on the blog page.

    **_Built with Ruby on Rails_**

    `Ruby: v~ 2.6.3`

    `Rails: v- 5.2.6`

    **List of _GEMS_:**

    Main gems included in this project:

    - `kaminari` for pagination
    - `carriewave` to handle images uploads
    - `geocoder` to integrate geolocation in Rails with the Google Maps API
    - `figaro` to handle app variables configuration for deployment
    - `bcrypt` to secure users password
    - `fog-aws` to manipulate files on Amazon S3 Storage
    - `aws-sdk` to make easier the integration of AWS with Rails
    - `pg` to connect the Rails app to the Postgres database
    - `action-mailer` to send emails through a contact form and comments to the users
    * `redcarpet` for markdown support
    * `sendgrid-ruby` to send emails through Sendgrid services provider
    * `bootstrap` for some general styling


    ## Database

    Postgres is the database used for all environments:

    - `Development` environment
    - `Test` environment
    - `Production` environment

    ## Default users:
    | Role | Login | Password |
    |-----------|--------------------|------------|
    | Admin | lydia@salseros.cu | `password` |
    | Registered| debora@salseros.cu | `password` |
    | Guest / Visitor | `No required` | `No required` |


    ## Services

    Heroku, for the deployment of this web app:

    https://casineros-cubanos.herokuapp.com/ (This version does not include the contact form view)

    ## Sendgrid + ActionMailer: (Contact form)

    It sends automatic email responses to the user after submitting the form. On top of this, it will be used to send reminders and notify registered users when updates on the website are made. This works as expected in the development environment, but not in production.

    As developers, we learn that every single environment behaves completely different from each other. For me, it is a real challenge to make this feature work in the production environment. Initially, I got a lot of errors, but I could solve them. However, there is still one error: ``superclass mismatch for class Category (TypeError)`` which I have not been able to solve yet as the Gem installation gives a bug.

    Nevertheless, I could send emails from the project to myself, in other words, I could test the implementation. Even though I get this bug, my professors told me to put it anyway in the project to demonstrate this implementation.

    ## Amazon AWS S3 storage:

    It is for users to upload images. I took advantage of Carrierwave and Minimagic gems to accomplish it. Also to ensure that users can only upload images and no other files.

    ## GoogleMaps API: (Geocoder gem)

    The initial intention for adding this feature in the project was only to display a static map of Lausanne with a few Salsa schools and Dance clubs in the area. However, the result is even better than my expectations because now users can:

    Create new locations and save them in the database Search for places near a specific area of their choosing Interact with fully dynamic maps to Edit and Update places And navigate, zoom in, zoom out, and control the maps as they want I am really happy with this feature because it helped me to understand better the capabilities of the Geocoder gem and to improve my abilities with Javascript. It is also a really good base and experience for my future projects as a developer.

    ## Youtube Iframe API:

    I used it to build a dynamic video player that is making use of Javascript for users to listen and watch salsa music videos.

    ## Summary

    The differences between my proposal and my final project are as the following:


    I decided to apply `local translations` instead of using `globalize` gem for content translations. I think it's more suitable in this case to use local translations as it's a blog, and not selling products company.

    I changed `Facebook API` (Facebook authentication) for `IFrame API`. With IFrame API I was also able to demonstrate de use of Javascript. I found `IFrame API` more interesting for me to work within this project.

    ## Extra

    I included the `Markdown` feature to give users more flexibility to write and preview articles and comments they make. This gem is well structured and can be configured to prevent malicious content.