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
# 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 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
#!/usr/bin/env ruby | |
# Make sure you have 'colorize' gem installed already. | |
require 'colorize' | |
current_branch = `git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,'` | |
push_cmd = `ps -ocommand | grep "git push"` | |
if current_branch =~ /\/master/ && push_cmd =~ /(\-f|force|delete)/ | |
puts '*********************************************'.colorize(:red) |
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 hola | |
puts 'hola' | |
end | |
def say_hola(block) | |
block.call | |
end | |
say_hola method(:hola) |
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 whats_your_name? | |
l = Proc.new { return "Karim" } | |
l.call | |
return "Rahim" | |
end | |
#=> "Karim" |
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
l = lambda { |a, b| ... } | |
l.call('A') | |
#=> Error need to pass 2 arguments |
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 say_hi_to(block) | |
puts "Say hi #{block.call}" | |
end | |
say_hi_to Proc.new { "hasan" } | |
#=> Say hi hasan |
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 say_hi_to(&block) | |
puts "Say hi #{block.call}" | |
end | |
say_hi_to { "hasan" } | |
#=> Say hi hasan |
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 Page < ActiveRecord::Base | |
attr_accessible :body, :metadata, :title, :store_id | |
# Relationships | |
belongs_to :store | |
# Validations | |
validates_presence_of :title, :body, :store_id | |
# Scopes |
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 Product | |
include FlexiModel | |
flexi_field :name, :string | |
flexi_field :price, :decimal | |
set_flexi_partition_id USER.store.id | |
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
require 'rubygems' | |
require 'spork' | |
#uncomment the following line to use spork with the debugger | |
#require 'spork/ext/ruby-debug' | |
Spork.prefork do | |
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' |