Skip to content

Instantly share code, notes, and snippets.

View Rails Console Actionmailer test.rb
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
set_tracking_headers 'test_campaign'
@recipients = "benoror@gmail.com"
@from = "Equipo Nimbo X <hola@" + Rails.application.secrets.sparkpost_domain + ">"
@subject = "sparkpost email test with open & click tracking"
@body = "This is a test email. With a <a href=\"http://blog.nimbo-x.com/nimbo-x-gold/\">test link</a>."
View checkout.rb
require 'minitest/autorun'
require_relative 'checkout'
class TestCheckoutTest < Minitest::Test
def setup
@checkout = Checkout.new('strawberry')
end
View tac.rb
class Board
attr_reader :grid
def initialize(input_array_hash = {})
@grid = input_array_hash.fetch(:grid, board_default_grid)
end
def fetch_cell(x, y)
View tic
http://codereview.stackexchange.com/questions/88429/tic-tac-toe-implementation-in-ruby
**https://codequizzes.wordpress.com/2013/10/25/creating-a-tic-tac-toe-game-with-ruby/
ruby ~/dev-gt/test/ttt/lib/ttt.rb
For example, a Tic Tac Toe program requires data structures for storing
the board and conditional logic for knowing whose turn it is or if someone has won.
http://stackoverflow.com/questions/3233278/how-do-i-test-if-all-items-in-an-array-are-identical?rq=1
You can use Enumerable#all? which returns true if the given block returns true for all the elements in the collection.
@boy-jer
boy-jer / url_regex.rb
Last active Oct 24, 2015 — forked from ryana/url_regex.rb
@gruber's improved regex for matching URLs written in Ruby
View url_regex.rb
# From @gruber http://daringfireball.net/2010/07/improved_regex_for_matching_urls
#http://ryanangilly.com/post/8654404046/grubers-improved-regex-for-matching-urls-written
UrlRegex = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\`!()\[\]{};:\'\".,<>?«»“”‘’]))/i
@boy-jer
boy-jer / Gemfile
Created Oct 11, 2015 — forked from mchail/Gemfile
Zapier Webhooks in Rails with Resque
View Gemfile
gem "resque", :require => 'resque/server'
gem 'resque-history'
@boy-jer
boy-jer / search.rb
Last active Aug 29, 2015
Simple Model Search with Rails
View search.rb
http://erniemiller.org/2008/02/07/simple-model-search-with-rails/
#controller
class OffenceController < ApplicationController
def index
@offenses = []
@search = Search.new(Offense,params[:search])
if @search.conditions
@offenses = Offense.search(@search)
@boy-jer
boy-jer / multi-parameter_attributes_spec.rb
Created Dec 4, 2013 — forked from k-rudy/multi-parameter_attributes_spec.rb
Multiparameter Attributes support in Mongoid 4 (Rails 4.0.1) Code is taken from https://github.com/mongoid/mongoid/issues/2954 with minor amendments to work with Rails 4.0.1
View multi-parameter_attributes_spec.rb
# This class is needed since Mongoid doesn't support Multi-parameter
# attributes in version 4.0 before it's moved to active model in rails 4
#
# https://github.com/mongoid/mongoid/issues/2954
#
require "spec_helper"
require 'mongoid/multi_parameter_attributes'
describe Mongoid::MultiParameterAttributes do
View criteria.rb
module Mongoid
module ActiveRecord
module EagerLoadable
module Criteria
extend ActiveSupport::Concern
def includes_active_record(*relations)
relations.each do |relation|
metadata = RelationMetadata.new(relation)
You can’t perform that action at this time.