Skip to content

Instantly share code, notes, and snippets.

View ka8725's full-sized avatar
🚀
Ruby on Rails expert with business development mindset | WideFix Founder

Andrei Kaleshka ka8725

🚀
Ruby on Rails expert with business development mindset | WideFix Founder
View GitHub Profile
RSpec.configure do |config|
config.before do
Category.subclasses.each do |c|
c.instance_variable_set(:@instance, nil)
end
Category.instance_variable_set(:@instances, nil)
end
end
x = '123'
x[0, x.length] = 'aa' # x.replace('aa')
STEP_DECORATORS_MAPPING = {
step1: Decorator1,
step2: Decorator2
}
step = :step1
STEP_DECORATORS_MAPPING[step].new(...)
/usr/local/opt/rbenv/versions/2.1.0/lib/ruby/2.1.0/bigdecimal/util.rb:18: [BUG] Segmentation fault at 0x00000000000000 | ETA: 00:04:13
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
require 'minitest/autorun'
BOOLEAN_MAPPINGS = {
'true' => true,
'false' => false
}
def typecast_hash_values(hash)
hash.each do |k, old_value|
if (new_value = BOOLEAN_MAPPINGS.fetch(old_value, old_value)) != old_value
class DeviseCreateUsers < ActiveRecord::Migration
def migrate(direction)
super
# Create a default user
User.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if direction == :up
end
def change
create_table(:users) do |t|
## Database authenticatable
module LiquidPresenters
class Plan < SimpleDelegator
def to_liquid
@to_liquid ||= HashWithIndifferentAccess.new({
id: self.id,
name: self.name,
description: self.description,
status: self.status,
class_id: self.plan_class_id
})
require 'active_record'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db.sqlite3')
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.references :company, index: true
end
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db.sqlite3')
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
end
end
class ActiveRecord::Base
@ka8725
ka8725 / gist:9419051
Created March 7, 2014 20:12
mailtatcher replacement
$ python -m smtpd -n -c DebuggingServer localhost:1025
This is how receiving email looks like:
---------- MESSAGE FOLLOWS ----------
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: User activation - localhost:8000
From: info@google.ru