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
=begin | |
Time difference (duration) in year, quarter, month, bi-week, week and day. | |
Usages: | |
TimeDifference.between(start_date, end_date).in_months | |
TimeDifference.between(start_date, end_date).in_years | |
=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
client-side: | |
~~~~~~~~~~~ | |
require 'socket' | |
hostname = 'localhost' | |
port = 2000 | |
s = TCPSocket.open(hostname, port) | |
while line = s.gets | |
puts line.chop | |
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
# Usage: bundle exec rake sidekiq:restart RAILS_ENV=<environment name> | |
namespace :sidekiq do | |
sidekiq_pid_file = Rails.root+'tmp/pids/sidekiq.pid' | |
desc "Sidekiq stop" | |
task :stop do | |
puts "#### Trying to stop Sidekiq Now !!! ####" | |
if File.exist?(sidekiq_pid_file) | |
puts "Stopping sidekiq now #PID-#{File.readlines(sidekiq_pid_file).first}..." |
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
=begin | |
Author: Vigram K | |
Date: 27th August 2014 | |
Title: Extension for Date & DateTime classes | |
Adds following methods for date object, | |
first_monday_of_month, first_tuesday_of_month .. first_sunday_of_month | |
last_monday_of_month, last_tuesday_of_month .. last_sunday_of_month |
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 DateFormatter | |
def self.included(base) | |
date_columns = base.columns.select{|column| ["date","datetime"].include?(column.sql_type) } | |
date_columns.map(&:name).reject{|col_name| ["created_at", "updated_at"].include?(col_name)}.each{|column| | |
base.class_eval do | |
define_method column do | |
read_attribute(column.to_sym).custom_format | |
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 SingletonPattern | |
def self.included(base) | |
base.class_eval do | |
@@instance = base.class.new | |
def instance | |
@@instance | |
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 LinkedList | |
attr_accessor :list | |
def initialize | |
@list = [] | |
end | |
def add_node(data) | |
node = Struct.new(:data, :next) | |
new_node = node.new(data, nil) |