Skip to content

Instantly share code, notes, and snippets.

@dasibre
dasibre / gist:fa10fb1969eac94639059d026c3e6385
Created January 6, 2024 10:14 — forked from trcarden/gist:3295935
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@dasibre
dasibre / ssl_requirement_spec.rb
Last active July 21, 2020 11:30 — forked from speedmax/ssl_requirement_spec.rb
How to test rack middleware example
require 'spec_helper'
# Based on https://github.com/rails/ssl_requirement/blob/master/lib/ssl_requirement.rb
class SslRequirement
def initialize(app, options= {})
@app = app
@allowed = options[:allowed]
@required = options[:required]
end
@dasibre
dasibre / controller_example.rb
Created June 4, 2020 13:51
Rails CORS setting
before_action :cors_preflight_check
after_action :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT'
headers['Access-Control-Max-Age'] = "1728000"
end
def cors_preflight_check
@dasibre
dasibre / eval.rb
Created January 25, 2019 22:47
Eval
#Palindrome a word phrase that reads the same backwards
# write code that will return true for the following palindrome
# "A man, a plan, a canal: Panama"
module Palindrome
def self.is_palindrome(word)
end
end
# Palindrome.is_palindrome("A man, a plan, a canal: Panama") => true

How to setup Cypress on Rails apps

You need to update circle.yml:

machine:
  node: # add node dependency
    version:
      7.4

environment:
@dasibre
dasibre / integration_test_helper.rb
Created September 25, 2018 15:39 — forked from martinrehfeld/integration_test_helper.rb
Headless integration testing of facebook dialogs with capybara-webkit

## Most important settings

Create a new facebook app (1) and make sure the canvas url (2) in the basic tab matches the host and port configured with Capybara.server_port and Capybara.app_host. Activating sandbox mode (3) in the advanced tab enables you to roll without providing an SSL canvas url. You want to set the display mode (4) of your facebook dialogs to page, which is also the default.

  1. https://developers.facebook.com/apps
  2. http://screencast.com/t/lt6ORnb1sf
  3. http://screencast.com/t/tPSUyE6s
  4. https://developers.facebook.com/docs/reference/dialogs/
@dasibre
dasibre / minitest-integration.rb
Created September 25, 2018 15:38
configuring selenium capybara
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "minitest/autorun"
require "capybara/rails"
require "active_support/testing/setup_and_teardown"
Dir[Rails.root.join("test/support/**/*.rb")].each {|f| require f}
DatabaseCleaner.strategy = :truncation
@dasibre
dasibre / rules for good testing.md
Created June 18, 2018 17:55 — forked from Integralist/rules for good testing.md
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.

@dasibre
dasibre / singleton.rb
Created May 21, 2018 16:55 — forked from mssola/singleton.rb
Different ways to create the Singleton pattern in Ruby.
##
# This files shows some possible implementations of the Singleton pattern
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice
# in some cases. In this file I'm going to implement a simple logger.
#
##
# The first implementation that can come to our minds is to create a class
# that holds an instance as a class variable that can be accessed through
<%= semantic_form_for @parent do |a| %>
<%= a.inputs "Family Details" do %>
<%= a.input :name %>
<%= a.input :user %>
<%= a.input :region %>
<% end %>
<%= a.inputs "Children" do %>
<table>