Search and replace the the string in Javascript

replace(search str, replace_str):  Replaces the very first occuance oif the search string.

string = 'Praise the Lord';
string = replace('Praise', 'Jesus is');
alert(string);

This returns: "Jesus is the Lord"



Continue Reading

RUBY: Creating dynamic directory in ruby

system()  method executes any commands that we can able to execute through terminal or konsole(console).

e.g
folder = "/tmp"
system("mkdir #{folder}") if !File.directory?(folder)

If you found any errors in the above coding , try to include the ftools library.

e.g
require 'ftools'
folder = "/tmp"
system("mkdir #{folder}") if !File.directory?(folder)

Continue Reading

Write a file oin ruby on rails


log_path = '/home/project/logs'
system("mkdir #{log_path}") if !File.directory?(log_path)
log_content = "test content"
File.open("#{log_path}/log_#{Time.now.to_i}.txt", 'a') { |file|
  file.write "#{log_content}"
}
Continue Reading