Friday, April 18, 2014

How do you create a log file with the name that of script?

require 'Date'
require 'Fileutils'
require 'Logger'

$today = Date.today.strftime("%Y%m%d")
$log = Logger.new("#{File.basename($0, '.*')}.#$today.log", 'daily')

How do you create a log file with name that of batch script?

@echo off
set me=%~n0
set list=Error Log Admin
for %%i in ( %list% ) do (
   if not exist %%i ( mkdir %%i 2>%me%_error.log )
)

Thursday, April 17, 2014

Monday, April 14, 2014

How can you install a list of modules if already not there?

my @module = ('Text::CSV::Separator 0.20',
                       'Getopt::Lucid',
                          'Apache::Htpasswd',
                          'IO::CaptureOutput',
 );
for(@module) {
  eval;
if($@) {
$_=~/\w+\W(\S+)/;
print "Module $1 does not exist! Trying to install it.\n";
system("ppm", "install", "$_");
}
else {
print "Module $_ exists!\n";
}
}

Wednesday, April 2, 2014

How do you evaluate expressions in situ in ruby?

The evaluation of embedded expressions can be achieved using "#{}".
e.g, "abcd #{5*3} efg"

How can you add command prompt or power shell to context (Right Click) menu in Windows?

Create a ".reg" file containing the following line and double click on it.

Windows Registry Editor Version 5.00

; Add command prompt to right click menu in a folder
[HKEY_CLASSES_ROOT\Directory\Background\shell\Command Prompt]
[HKEY_CLASSES_ROOT\Directory\Background\shell\Command Prompt\command]
@="cmd.exe /s /k pushd %V"

; Add command prompt to right click menu on a folder
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt]
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt\command]
@="cmd.exe /s /k cd %L"

[HKEY_CLASSES_ROOT\Directory\shell\PowerShell]
[HKEY_CLASSES_ROOT\Directory\shell\PowerShell\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"