A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord
class OAuth::GoogleAuthorizationsController < ApplicationController | |
CLIENT_ID = Rails.application.credentials.google.client_id | |
CLIENT_SECRET = Rails.application.credentials.google.client_secret | |
SCOPE = "openid email profile" | |
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth") | |
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token") | |
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo") | |
before_action :validate_state_token, only: :show |
require "active_record" | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Migration.class_eval do | |
create_table(:records) do |t| | |
t.string :column | |
end | |
end | |
data = 50_000.times.map { |i| Hash[column: "Column #{i}"] } |
class Ticket < ActiveRecord::Base | |
belongs_to :grouper | |
belongs_to :user | |
validate :user_cant_be_blacklisted, on: :confirmation | |
validate :user_cant_double_book, on: :confirmation | |
validate :grouper_cant_be_full, on: :confirmation | |
validate :grouper_cant_have_occurred, on: :confirmation |
When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:
const Article = require('../../../../app/models/article');
Those suck for maintenance and they're ugly.
Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.
Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.
source 'https://rubygems.org' | |
# Follows the bundler group pattern described here: | |
# http://iain.nl/getting-the-most-out-of-bundler-groups | |
# Gemfile.mine in root dir allows locally custom gems. | |
# NOTE: Doing this will change the Gemfile.lock - commit with care. | |
eval File.read(File.join(File.dirname(__FILE__), 'Gemfile.mine')) if File.exists? File.join(File.dirname(__FILE__), 'Gemfile.mine') | |
ruby '1.9.3' |
##Intro
Generator frameworks spend way too much time creating obscure and pointless DSL syntax just to make the code trendy and cute. This generator comes in the form of pure ruby, instantiates real model objects (which fire their pre-, post- and other hooks appropriately), and still allows for a simple syntax to override parameters of generated objects.
Standard Ruby syntax allows for easier adoption by new programmers and reinforces ruby paradigms, instead of breaking them down with a cute, often incomplete, and entirely superfluous DSL syntax.
Specific complaints against existing frameworks:
set :path_to_repo, "/path_to_repo/" | |
set :running_app_user, "appusername" | |
namespace :webscale do | |
desc "Cache a signed out version of the path. Usage: cap webscale:signed_out_cache_page -s path_to_cache=/films/on_netflix" | |
task :signed_out_cache, roles: :app do | |
cache_base_path = "#{path_to_repo}/public/signed_out" | |
cached_destination_path = "#{cache_base_path}#{path_to_cache}.html" | |
working_path = "#{cached_destination_path}.tmp" |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'rspec/autorun' | |
require 'capybara/rspec' | |
require 'webmock/rspec' | |
require 'factory_girl' | |
require 'factory_girl_rails' | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} |