This file contains hidden or 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
| User Exists? (1.3ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = $1 LIMIT $2 [["username", "michael"], ["LIMIT", 1]] | |
| User Create (0.5ms) INSERT INTO "users" ("username", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["username", "michael"], ["created_at", "2022-12-29 14:51:02.384023"], ["updated_at", "2022-12-29 14:51:02.384023"]] | |
| User Exists? (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = $1 LIMIT $2 [["username", "lebron"], ["LIMIT", 1]] | |
| User Create (0.2ms) INSERT INTO "users" ("username", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["username", "lebron"], ["created_at", "2022-12-29 14:51:02.386506"], ["updated_at", "2022-12-29 14:51:02.386506"]] | |
| User Exists? (0.3ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = $1 LIMIT $2 [["username", "michael"], ["LIMIT", 1]] | |
| TRANSACTION (0.3ms) ROLLBACK |
This file contains hidden or 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
| irb(main):032:0> value={:next_page_token=>nil, :group_definitions=>nil, :results_by_time=>[{:time_period=>{:start=>"2022-10-01", :end=>"2022-11-01"}, :total=>{"BlendedCost"=>{:amount=>"49.1803785401", :unit=>"USD"}}, :groups=>[], :estimated=>false}, {:time_period=>{:start=>"2022-11-01", :end=>"2022-12-01"}, :total=>{"BlendedCost"=>{:amount=>"79.0698396954", :unit=>"USD"}}, :groups=>[], :estimated=>false}, {:time_period=>{:start=>"2022-12-01", :end=>"2022-12-03"}, :total=>{"BlendedCost"=>{:amount=>"2.6918272089", :unit=>"USD"}}, :groups=>[], :estimated=>true}], :dimension_value_attributes=>[]} | |
| => | |
| {:next_page_token=>nil, | |
| ... | |
| irb(main):033:0* sum = value[:results_by_time]&.sum do |hash| | |
| irb(main):034:0* hash.dig(:total, 'BlendedCost', :amount)&.to_f || 0 | |
| irb(main):035:-> end | |
| => 130.9420454444 |
This file contains hidden or 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 'active_support/all' | |
| require 'minitest/autorun' | |
| class A | |
| class_attribute :x, default: {} | |
| end | |
| class B < A | |
| end |
This file contains hidden or 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 'benchmark' | |
| def insert_list(table_name:, columns:, values:) | |
| Arel::InsertManager.new.tap do |manager| | |
| table = Arel::Table.new(table_name) | |
| manager.into(table) | |
| columns.each { |name| manager.columns << table[name] } | |
| manager.values = manager.create_values_list(values) | |
| end | |
| end |
This file contains hidden or 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
| irb(main):007:0> cats = Cat.all | |
| irb(main):008:0> cats.reload | |
| Cat Load (0.4ms) SELECT "cats".* FROM "cats" | |
| => #<ActiveRecord::Relation [#<Cat id: 1, name: "Proffessor Fluff", picture: nil, created_at: "2021-01-04 19:36:21", updated_at: "2021-01-04 19:36:21">, #<Cat id: 2, name: "Cindy Clawford", picture: nil, created_at: "2021-01-04 19:37:00", updated_at: "2021-01-04 19:37:00">, #<Cat id: 3, name: "Meowise", picture: nil, created_at: "2021-01-04 19:37:30", updated_at: "2021-01-04 19:37:30">]> | |
| irb(main):009:0> Cat.last.update(name: 'Mr Meowise') | |
| Cat Load (0.4ms) SELECT "cats".* FROM "cats" ORDER BY "cats"."id" DESC LIMIT ? [["LIMIT", 1]] | |
| (0.1ms) begin transaction | |
| Cat Update (5.1ms) UPDATE "cats" SET "name" = ?, "updated_at" = ? WHERE "cats"."id" = ? [["name", "Mr Meowise"], ["updated_at", "2021-01-04 19:38:34.919564"], ["id", 3]] | |
| (5.3ms) commit transaction | |
| => true |
This file contains hidden or 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 AddAuthorToComment < ActiveRecord::Migration[6.0] | |
| def change | |
| add_reference :comments, :author, null: false, foreign_key: { to_table: :users } | |
| end | |
| end |
This file contains hidden or 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 AddFeatureGroupIdToFeatures < ActiveRecord::Migration[6.0] | |
| def change | |
| add_refererence :features, :feature_group, foreign_key: true | |
| end | |
| end |
This file contains hidden or 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 'benchmark' | |
| def vowel_cipher(string) | |
| string.tr "aAeEiIoOuU", "eEiIoOuUaA" | |
| end | |
| NEXT_VOWEL = {"a"=>"e", "A"=>"E", "e"=>"i", "E"=>"I", "i"=>"o", | |
| "I"=>"O", "o"=>"u", "O"=>"U", "u"=>"a", "U"=>"A"} | |
| def vowel_cipher_gsub(str) |
This file contains hidden or 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
| Running via Spring preloader in process 13691 | |
| Loading development environment (Rails 6.0.2.1) | |
| irb(main):001:0> CountryImporterJob.perform_now('africa') | |
| Performing CountryImporterJob (Job ID: 10d7fa89-fb75-4e98-b007-78e3544af766) from Async(default) enqueued at with arguments: "africa" | |
| (0.2ms) BEGIN | |
| Country Create (0.9ms) INSERT INTO "countries" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["name", "Algeria"], ["created_at", "2020-04-22 10:13:32.879869"], ["updated_at", "2020-04-22 10:13:32.879869"]] | |
| (1.7ms) COMMIT | |
| (0.2ms) BEGIN | |
| Country Create (0.5ms) INSERT INTO "countries" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["name", "Angola"], ["created_at", "2020-04-22 10:13:32.897737"], ["updated_at", "2020-04-22 10:13:32.897737"]] | |
| (1.1ms) COMMIT |
This file contains hidden or 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
| module MyApp | |
| module Assocations | |
| def self.included(base) | |
| base.extend ClassMethods | |
| end | |
| module ClassMethods | |
| def decorate_association(**options, &block) | |
| yield AssocationDecorator.new(self, options) |
NewerOlder