Skip to content

Instantly share code, notes, and snippets.

View mistrikushal's full-sized avatar
🏠
Working from home

Kushal mistrikushal

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am mistrikushal on github.
  • I am kmistryrubydev (https://keybase.io/kmistryrubydev) on keybase.
  • I have a public key ASB4wGyJe6ayMnPZYlV9wftlxJeiSXZmo6ot6Q_cJ9INJAo

To claim this, I am signing this object:

@mistrikushal
mistrikushal / heroku pg backup restore
Last active September 18, 2017 18:05
Heroku PG backup and restore
# heroku pg restore from first app
$ heroku pg:backups:capture --app sushi
# download the backup (optional)
$ heroku pg:backups:url b001 --app sushi
# in above command b001 is the ID of a backup which will be displayed on terminal once backup is done
# check the backup information
$ heroku pg:backups:info b017 --app sushi
@mistrikushal
mistrikushal / prac.rb
Created January 10, 2017 10:42
practical test
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
@mistrikushal
mistrikushal / csv_generate.rb
Last active September 22, 2016 05:45
create csv in ruby on rails
# 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.
@mistrikushal
mistrikushal / time_difference_test.rb
Created September 8, 2016 10:29
Time difference test
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
Verifying that "kushalmistri.id" is my Blockstack ID. https://onename.com/kushalmistri
@mistrikushal
mistrikushal / test_multiply.rb
Last active January 26, 2016 14:43
multiply 2 numbers without X operator
# 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
@mistrikushal
mistrikushal / longest_word_test.rb
Created January 26, 2016 13:52
find a longest word from a given string
# 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}"
@mistrikushal
mistrikushal / ruby_puzzle_1.rb
Created January 11, 2016 11:50
a small ruby puzzle solution
# 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
to create a .zip of a directory using bash shell,
$ zip -r filename.zip directory_path_to_zip