- Ruby (Ruby license)
- PostgreSQL (PostgreSQL license)
- wkhtmltopdf (GPL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV["RAILS_ENV"] ||= 'test' | |
cur_dir = File.expand_path(File.dirname(__FILE__) + '/..') | |
$LOAD_PATH << "#{cur_dir}" | |
if defined? Rails | |
# Most likely going with the full env | |
puts "Running faster_helper with full Rails env..." | |
# Eagerly load the Rails so that stubbed dependencies still work | |
# http://stackoverflow.com/questions/11133712/using-rails-model-that-is-already-declared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
module Maybe | |
class Just < BasicObject | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'fileutils' | |
require 'date' | |
require 'uri' | |
# usage: ruby import.rb my-blog.xml | |
# my-blog.xml is a file from Settings -> Basic -> Export in blogger. | |
data = File.read ARGV[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'activerecord', '4.2.5' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'postgresql', | |
:database => 'x' | |
) |
Initially asked at RORO but I will elaborate with an example.
What we need to do is the following:
- we list a set of items (let's say posts) and want to show a drop-down menu next to each one (quick example)
- when the drop-down arrow is clicked the menu is loaded from the server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BackgroundWorkerStarter | |
attr_reader :env | |
def initialize(env) | |
@env = env | |
end | |
def start! | |
write_pid!(pid_file) if pid_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreditCard | |
include ActiveAttr::Model | |
attribute :number | |
attribute :expiry | |
attribute :cvn | |
attribute :name | |
validate :must_be_valid | |
validates :number, :expiry, :cvn, :name, presence: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1, not so cool (look at the 'less-than' and OR condition) | |
# plain AR: | |
Property.joins(:reservations). | |
where(status: 'reserved'). | |
where("reservations.status = ? OR reservations.reservation_type = ?", 'active', 'offline'). | |
where(reservations: {reservation_fee_received: false}). | |
where("reservations.fee_due_at < ?", DateTime.now) | |
# with squeel: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
def create | |
@article = Article.find(params[:article_id]) | |
@comment = @article.comments.build(params[:comment]) | |
@comment.save # etc | |
end | |
end |