A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord
# Add color coding based on Rails environment for safety | |
if defined? Rails | |
banner = if Rails.env.production? | |
"\e[41;97;1m #{Rails.env} \e[0m " | |
else | |
"\e[42;97;1m #{Rails.env} \e[0m " | |
end | |
# Build a custom prompt |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: example | |
namespace: default | |
data: | |
APPLICATION_HOST: example.com | |
LANG: en_US.UTF-8 | |
PIDFILE: /tmp/server.pid | |
PORT: "3000" |
fizz = ["","","Fizz"].lazy.cycle | |
buzz = ["","","","","Buzz"].lazy.cycle | |
numbers = (1..Float::INFINITY).lazy | |
fizzbuzz = numbers.zip(fizz,buzz).map do |n,f,b| | |
(f.empty? && b.empty?) ? n.to_s : f + b | |
end | |
puts fizzbuzz.take(20).to_a |
// flatMap | |
// This code is equivalent to: | |
// option.flatMap(foo(_)) | |
option match { | |
case None => None | |
case Some(x) => foo(x) | |
} | |
// flatten | |
// This code is equivalent to: |
require 'active_record' | |
ActiveRecord::Base.logger = Logger.new(STDERR) | |
ActiveRecord::Base.colorize_logging = false | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:dbfile => ":memory:" | |
) |