Skip to content

Instantly share code, notes, and snippets.

@sj26
sj26 / Gemfile
Last active September 23, 2021 05:47
Example mailcatcher setup with foreman
source "https://rubygems.org"
gem "foreman"
gem "rack"
gem "sinatra"
gem "mail"
@paulnsorensen
paulnsorensen / _spec_performance.html.erb
Created June 6, 2014 16:10
Disabling CSS animations in tests
<%# http://www.venombytes.com/2013/03/11/faster-browser-specs %>
<% if Rails.env.test? -%>
<style type="text/css">
.notransition * {
/*CSS transitions*/
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
-ms-transition: none !important;
@JunichiIto
JunichiIto / alias_matchers.md
Last active May 9, 2025 08:50
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@andystanton
andystanton / ghost2jekyll.py
Last active July 30, 2017 16:15
Ghost2Jekyll: Converts ghost 0.4.2 sqlite db posts to jekyll 2.3.0 markdown posts.
#!/usr/bin/env python3
# This script is provided to show how I migrated from Ghost 0.4.2
# to Jekyll 2.3.0 and is used at your own risk. Back up your blog
# before trying it out.
def getPostTemplate():
with open('post-template.md', 'r') as f:
posttemplate = f.read()
f.closed
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@gaffneyc
gaffneyc / test.rb
Created November 19, 2014 21:41
Disable logging in the test environment
Rails.application.configure do
# Don't write output to test.log
config.logger = ::ActiveSupport::Logger.new("/dev/null")
config.logger.formatter = lambda { |*_| nil }
config.logger.level = 10 # FATAL is 4
end
@jwood
jwood / application.html.erb
Last active March 15, 2021 16:03
Disable animations
<!-- app/views/layouts/application.html.erb -->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... -->
<% if Rails.application.config.disable_animations %>
<%= stylesheet_link_tag('disable_animations') %>
<!-- Turn off animations in jQuery -->
<script>$.fx.off = true;</script>
@nickserv
nickserv / config.yml.erb
Created April 21, 2015 14:43
Using ERB with a YAML config file in Ruby
:uri: http://example.com/?host=<%= hostname %>
@JeffBelback
JeffBelback / docker-destroy-all.sh
Last active June 12, 2025 15:08
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
containers=`docker ps -a -q`
if [ -n "$containers" ] ; then
docker stop $containers
fi
# Delete all containers
containers=`docker ps -a -q`
if [ -n "$containers" ]; then
docker rm -f -v $containers
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 12, 2025 21:24
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end