This file contains 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 Concerns | |
module LazyAttribute | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :lazy_attributes | |
end | |
module ClassMethods | |
def attr_lazy(name, &logic_impl) |
This file contains 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
namespace :somestuffs do | |
desc 'Importing some big stuff that requies lotta network stuff' | |
task :import | |
file, tasks = ENV['FILE'], Queue.new | |
# Parse out CSV file and retrieve each row and queue them up | |
# for further processing. | |
# | |
# Keeping it a thread allows us to let this process continue while other | |
# threads are not in RUNNING state. |
This file contains 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
# Integrate with ActiveMerchant and Expose active merchant related methods. | |
# | |
# This module also includes Validator for ActiveMerchant. | |
module Concerns::AsActiveMerchant | |
extend ActiveSupport::Concern | |
included do | |
validates_with Validators::ActiveMerchant, if: :cc_number_is_changed? | |
end |
This file contains 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 Message | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :subject, type: String | |
field :content, type: String | |
belongs_to :replied_to, class_name: 'Message', inverse_of: :replies, touch: true | |
belongs_to :sender, class_name: 'User', inverse_of: :sent_messages | |
has_many :replies, class_name: 'Message', inverse_of: :replied_to |
This file contains 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
def handle_action_created(action) | |
if action.from.kind_of?(Source) | |
$redis.lpush( | |
"#{self.class.name}:#{self.id}", | |
[action.from.node.id, action.from.node.neo_id].join(":") | |
) | |
end | |
end | |
# Perhaps we could do |
This file contains 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 AmericanStyle | |
extend ActiveSupport::Concern | |
included do | |
has_many :american_ingredients | |
end | |
module ClassMethods | |
def macaroni_cheese; ... end | |
end |
This file contains 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 OrderService | |
class << self | |
def find_or_create_purchase_for_order(order, credit_card_id, shipping_fee = 0.0) | |
user, vendor = order.buyer, order.seller | |
purchase = Purchase.find_by_user_id_and_order_id(user.id, order.id) | |
return purchase if purchase.present? | |
create_purchase order, credit_card_id, shipping_fee | |
end |
This file contains 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
# Twitter Client with control loop, If any too many requests error raised. | |
# It'll sleep for a certain time period and will wake up and continue from last batch. | |
# | |
# This is an addition to Twitter::Client 'gem twitter' | |
module BeatDeckMachine::Scrapers::OAuth::TwitterClientPatch | |
MAX_ATTEMPTS = 20 | |
extend ActiveSupport::Concern |
This file contains 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 ThreadPool | |
attr_accessor :size, :pool | |
def logger | |
BeatDeckMachine::logger | |
end | |
def initialize(size) | |
@size = size | |
@jobs = Queue.new |
This file contains 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
#!/bin/bash | |
echo "---------------------------------------" | |
echo " Welcome to Quick Schema Importer " | |
echo "---------------------------------------" | |
ROOT=$PWD | |
CONF="" |