Step one is to install Exuberant Ctags on your system. For those on an Ubuntu system, this is as simple as:
sudo apt-get install ctags
desc "Edit a post (defaults to most recent)" | |
task :edit_post, :title do |t, args| | |
args.with_defaults(:title => false) | |
posts = Dir.glob("#{source_dir}/#{posts_dir}/*.*") | |
post = (args.title) ? post = posts.keep_if {|post| post =~ /#{args.title}/}.last : posts.last | |
if post | |
puts "Opening #{post} with #{editor}..." | |
system "#{ENV['EDITOR']} #{post} &" | |
else | |
puts "No posts were found with \"#{args.title}\" in the title." |
module Support | |
module WorkerExampleGroup | |
include RSpec::Rails::RailsExampleGroup | |
def self.included(base) | |
base.metadata[:type] = :worker | |
end | |
end | |
end |
# | |
# At CoverHound, we use conditional validations all over the form. However, there is no proper way to do | |
# this in Rails. Instead, we can provide an array of attributes (validated_fields attribute) | |
# and ensure they are the only ones to get validated. | |
# | |
module ConditionalValidations | |
attr_accessor :validated_fields | |
def field_is_required?(field) |
def primes(max) | |
nums = Array.new(max + 1, 1) | |
nums[0] = nums[1] = 0 | |
(2..Math.sqrt(max)).each do |sieve| | |
if nums[sieve] == 1 | |
(2 * sieve).step(max, sieve).each do |num| | |
nums[num] = 0 | |
end | |
end |
FROM ubuntu:trusty | |
MAINTAINER Youssef Kababe "youssef.kbe@gmail.com" | |
RUN apt-get update | |
RUN apt-get install -y wget | |
RUN apt-get install -y libpcre3-dev | |
RUN apt-get install -y zlib1g-dev | |
RUN apt-get install -y make | |
RUN wget http://nginx.org/download/nginx-1.6.1.tar.gz |
require 'rubygems' | |
require 'rack/oauth2' | |
client = Rack::OAuth2::Client.new( | |
:identifier => YOUR_CLIENT_ID, | |
:secret => YOUR_CLIENT_SECRET, | |
:redirect_uri => YOUR_REDIRECT_URI, # only required for grant_type = :code | |
:host => 'rack-oauth2-sample.heroku.com' | |
) |
Fast/efficient approach:
-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
-> 1.3197s
Slow/naïve approach: