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
def say_hi_to(block) | |
puts "Say hi #{block.call}" | |
end | |
say_hi_to Proc.new { "hasan" } | |
#=> Say hi hasan |
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
l = lambda { |a, b| ... } | |
l.call('A') | |
#=> Error need to pass 2 arguments |
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
def whats_your_name? | |
l = Proc.new { return "Karim" } | |
l.call | |
return "Rahim" | |
end | |
#=> "Karim" |
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
def hola | |
puts 'hola' | |
end | |
def say_hola(block) | |
block.call | |
end | |
say_hola method(:hola) |
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
# Export collection name and their properties list in HTML format. | |
require 'mongo' | |
include Mongo | |
# Connect with mongodb server | |
client = MongoClient.new('localhost', 27017) | |
# Load database |
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
#!/bin/bash | |
echo "---------------------------------------" | |
echo " Welcome to Quick Schema Importer " | |
echo "---------------------------------------" | |
ROOT=$PWD | |
CONF="" |
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 ThreadPool | |
attr_accessor :size, :pool | |
def logger | |
BeatDeckMachine::logger | |
end | |
def initialize(size) | |
@size = size | |
@jobs = Queue.new |
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
# 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 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 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 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 AmericanStyle | |
extend ActiveSupport::Concern | |
included do | |
has_many :american_ingredients | |
end | |
module ClassMethods | |
def macaroni_cheese; ... end | |
end |