Skip to content

Instantly share code, notes, and snippets.

View rmw's full-sized avatar

Rebecca Miller-Webster rmw

View GitHub Profile
@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

@kinopyo
kinopyo / gist:5682347
Last active March 21, 2018 05:12
Ruby: to_s vs. to_str

Concept

(The blockquote style does not look so well so I just pasted directly, but these are all quoted from the links in the bottom of this page)

You should not implement to_str unless your object acts like a string, rather than just having a string representation. The only core class that implements to_str is String itself.

[to_i and to_s] are not particularly strict: if an object has some kind of decent representation as a string, for example, it will probably have a to_s method… [to_int and to_str] are strict conversion functions: you implement them only if you object can naturally be used every place a string or an integer could be used.

to_str is used by methods such as String#concat to convert their arguments to a string. Unlike to_s, which is supported by almost all classes, to_str is normally implemented only by those classes that act like strings. Of the built-in classes, only Exception and String implement to_str

@jamesgary
jamesgary / gist:5485643
Created April 29, 2013 23:35
Incremental Design - Rebecca Miller-Webster and Savannah Wolf - RailsConf 2013

Incremental Design

Rebecca Miller-Webster and Savannah Wolf

  • Rebecca: Developer, Savannah: Designer

  • How do you make design changes?

  • Big redesigns are often long and frustrating

  • Designers throw the design over the wall

  • Developers either are confused by it, or 'screw it up'

  • Redesigning page by page can lead to technical debt, and is awkward

@oggy
oggy / goliath-vs-unicorn
Created February 21, 2013 22:31
Demonstrates the superiority of Goliath over Unicorn for a single-process app handling file uploads. Also a fine excuse to use gems named Unicorn, Thor, and Goliath in a single ruby script.
#!/usr/bin/env ruby
# Demonstrates the superiority of Goliath over Unicorn for a single-process app
# handling file uploads.
#
# This program runs in 3 modes:
#
# ./goliath-vs-unicorn goliath - Runs the goliath server on the default port (9000)
# ./goliath-vs-unicorn unicorn - Runs the unicorn server on the default port (8080)
# ./goliath-vs-unicorn upload - Upload 5 files in parallel to the port given by -p
@raggi
raggi / validate_local_cache.sh
Last active December 11, 2015 23:39
A script to validate your local gem cache against the public s3 repositories. If you find mismatches that contain both local and remote values, please post them in comments.
#!/usr/bin/env sh
if ! which md5sum > /dev/null; then
echo Install md5sum
exit 1
fi
if ! which curl > /dev/null; then
echo Install curl
exit 1
# Block Adobe Activation
127.0.0.1 hl2rcv.adobe.com
127.0.0.1 t3dns.adobe.com
127.0.0.1 3dns-1.adobe.com
127.0.0.1 3dns-2.adobe.com
127.0.0.1 3dns-3.adobe.com
127.0.0.1 3dns-4.adobe.com
127.0.0.1 activate.adobe.com
127.0.0.1 activate-sea.adobe.com
127.0.0.1 activate-sjc0.adobe.com
@jasiek
jasiek / install-fast-require.sh
Created November 1, 2012 12:05
Installs Ruby 1.9.3-p194 with a patch set for faster require. (http://bugs.ruby-lang.org/issues/7158)
#!/bin/bash
pushd /tmp
COMMITS="8243d294600ca6e635bb617be23f34172e7676ab c23b88eff207744cccc42fa74f991eacdb419957 bf0c8f0fe1643c011fe9fa7dd14faeed604bd797 c7ec412a92e279f7f8d1ae88a2b1673dd64312f6"
PATCHES=""
for f in $COMMITS; do
wget --no-check-certificate https://github.com/gnprice/ruby/commit/$f.patch
PATCHES=$PATCHES,/tmp/$f.patch
done
rvm install -n fast_require 1.9.3-p194 --patch $PATCHES
@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@dmitriy-kiriyenko
dmitriy-kiriyenko / active_model_lint.rb
Created February 23, 2012 13:37
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end
@raulb
raulb / gist:1867822
Created February 20, 2012 04:17
Fadeout test with Jasmine
// If we want to test Asynchronous events we should use waits or waitsFor
// To test a fadeOut effect, waits(num ms) could be ok, but is not too smart in my opinion
// more info: https://github.com/pivotal/jasmine/wiki/Asynchronous-specs
// What happens if we want to test if any element is correctly deleted but before of that the element is going into a fadeOut
// event?. Which is happening is its opacity is going to 0 but immediately of that the element is undefined.
// This is my way to do it:
it("If one element is deleted correctly", function() {