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
# RSpec allows us to test private methods of a model. | |
for example, | |
class User | |
def is_active? | |
true | |
end | |
private :is_active? | |
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
if you see an error while installing mysql gem like, | |
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. | |
solution: | |
sudo apt-get install mysql-server | |
sudo apt-get install mysql-client libmysqlclient-dev | |
sudo apt-get install libmysqld-dev libmysqlclient-dev mysql-client |
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
to create a .zip of a directory using bash shell, | |
$ zip -r filename.zip directory_path_to_zip |
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
# check first non-repeating element from array | |
arr = [1,200,1,200,3,4,5] | |
res = Array.new | |
arr.detect{|e| res << e unless(arr.count(e) > 1) } | |
puts "First non-repeated element in Array"+arr.to_s+" is : "+ res.first.to_s | |
# check even times repeating elements in array | |
a = [5, 3, 5, 1, 5, 1, 3] | |
res_arr = Array.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
# logic to check longest word from a string | |
str = 'this string contains a looooooong word' | |
longest_word = str.split(' ').max_by(&:length) | |
puts "Longest word of the string is: #{longest_word}" |
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
# perform multiplication on 'a' and 'b' without using X operator | |
def mul(a, b) | |
x = 0 | |
b.times do | |
x = x + a | |
end | |
puts "Multiplication of #{a.to_s} X #{b.to_s} = #{x.to_s}" | |
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
Verifying that "kushalmistri.id" is my Blockstack ID. https://onename.com/kushalmistri |
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 'time' | |
require 'rubygems' | |
def calc_time_diff(current_time, end_time, end_time2=nil) | |
parsed_end_time = Time.parse(end_time) | |
parsed_current_time = Time.parse(current_time) | |
result = Hash.new | |
if parsed_end_time < parsed_current_time | |
secs_diff = (parsed_current_time - parsed_end_time).to_i.abs |
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
# Create a CSV in Write Mode | |
CSV.open("#{Rails.public_path}/file_name.csv", 'wb') do |csv| | |
# Add a first row into CSV which is column names | |
csv << ['First name', 'Last name', 'Email'] | |
end | |
# Now we have CSV file created in the public directory of the rails application and also it has columns ready | |
# Now Let's add some data into it. please note that the data in each cell of the row should be in order with the columns defined. |
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
COMMANDS = ['DEPEND', 'INSTALL', 'REMOVE', 'LIST'] | |
@component_dependencies = Hash.new | |
@installed_components = Array.new | |
def validate_command(command) | |
command_size = command.size | |
command_name = command.split(' ').first | |
return false unless COMMANDS.include?(command_name) | |
return false if command_name != command_name.upcase |
OlderNewer