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 Audit | |
| include Mongoid::Document | |
| include Mongoid::Timestamps | |
| include RailsAdminImport::Import | |
| class << self | |
| def create_with_type_message_meta(_type, _message, _user) | |
| self.create_without_type_message_meta({ | |
| :type => _type, | |
| :content => _message, |
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
| shared_context "widget" do | |
| let(:widget_klass) { self.described_class } | |
| let(:widget_name) { widget_klass.to_s.underscore.gsub(/_widget/, '') } | |
| let(:widget_instance) { root.find_widget(widget_name) } | |
| let(:current_user) { create(:user) } | |
| before { | |
| self.class.has_widgets do |r| | |
| r << widget(widget_name) | |
| 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
| MyObject = { | |
| respondToCallback: function (response, context) { | |
| // context will === "abc123" when called via doingSomething() | |
| }, | |
| doingSomething: function(callback) { | |
| var _foo = "abc123"; | |
| var _self = this; | |
| var _default_callback = function (resp, status, jqxhr) { | |
| _self.respondToCallback(response, _foo); | |
| }; |
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
| ng_products = Product.where(:"commodity.name" => /ng/i).each do |p| | |
| p.expiry_rule = :preceeding_weekday | |
| 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 AutomaticExpirationDate < Molecule::Mechanics::Repercussion | |
| extend Molecule::ExchangeConcepts | |
| def act(subj, *args) | |
| subj.pricing.expiry = self.class.expires_day_before(subj.tenor_start) if subj.option? | |
| # Molecule::ExchangeConcepts.expires_day_before is .get_expiry *without* the call to .calculate_expiry | |
| 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 Product | |
| field :traits, type: Array, default: [] | |
| after_initialize :load_traits! | |
| on_save :validates_methods | |
| def load_traits! | |
| self.traits.each do |trait| | |
| self << class | |
| self.send(:include, trait.camelize.constantize) |
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 Mongoid | |
| class << self | |
| def Money(value) | |
| Money.create_from_value(value) | |
| end | |
| end | |
| class Money | |
| class << self | |
| def create_from_value(value) |
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
| _________________________________________ | |
| / Festivity Level 1: Your guests are \ | |
| | chatting amiably with each other, | | |
| | admiring your Christmas-tree ornaments, | | |
| | singing carols around the upright | | |
| | piano, sipping at their drinks and | | |
| | nibbling hors d'oeuvres. | | |
| | | | |
| | Festivity Level 2: Your guests are | | |
| | talking loudly -- sometimes to each | |
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" | |
| require "benchmark/ips" | |
| thing = :baz | |
| puts "2 conditions, neither is true" | |
| Benchmark.ips do |x| | |
| x.report("conditional") do | |
| if thing == :foo || thing == :bar | |
| 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
| Rehearsal ------------------------------------------------------- | |
| {}.tap 0.000382 0.000257 0.000639 ( 0.000871) | |
| [[]].to_h 0.000031 0.000001 0.000032 ( 0.000032) | |
| {}.each_with_object 0.000027 0.000001 0.000028 ( 0.000028) | |
| ---------------------------------------------- total: 0.000699sec | |
| user system total real | |
| {}.tap 0.000030 0.000001 0.000031 ( 0.000029) | |
| [[]].to_h 0.000033 0.000011 0.000044 ( 0.000033) | |
| {}.each_with_object 0.000023 0.000012 0.000035 ( 0.000032) |