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

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 / 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
@dasibre
dasibre / gist:7b3b39eab32131cacac7faab2599d970
Created March 10, 2018 11:22 — forked from seanlinsley/gist:2038003
A better form to edit multiple child records. Created for https://github.com/gregbell/active_admin/issues/1097
<%= 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>
@dasibre
dasibre / stateful.js
Created May 29, 2017 13:16 — forked from foca/stateful.js
Stateful is a simple implementation of the State Pattern for JavaScript.
// Stateful is a simple implementation of the state pattern for javascript.
//
// Read more on this design pattern here:
// -> http://sourcemaking.com/design_patterns/state
//
// Initialize Stateful by passing it an object, the name of the initial state
// (defaults to "default"), and an optional hash of interfaces that will be
// applied for each state. If these interfaces are not passed, they default to
// the object's constructor's States property. So, for example:
//
@dasibre
dasibre / child-test.js
Created December 9, 2016 14:26 — forked from cowboy/child-test.js
Node.js: I can't seem to capture a child process's stdout and stderr in Windows.
var parent = function() {
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [process.argv[1], 123]);
var stdout = '';
var stderr = '';
child.stdout.on('data', function(buf) {
console.log('[STR] stdout "%s"', String(buf));
stdout += buf;
});
child.stderr.on('data', function(buf) {
@dasibre
dasibre / pedantically_commented_playbook.yml
Created March 23, 2016 23:41 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.