diff --git a/25th Aug, 2019/Function/Task - 1/farhan.rb b/25th Aug, 2019/Function/Task - 1/farhan.rb new file mode 100644 index 0000000..07e8fd5 --- /dev/null +++ b/25th Aug, 2019/Function/Task - 1/farhan.rb @@ -0,0 +1,36 @@ +VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i #regular expression for email validation + +def isEmailValid(email) + if !(email.size>=10 and email.size<=50) + return false + elsif !(email =~ VALID_EMAIL_REGEX) + return false + end + return true +end + +def isPasswordValid(password) + if password[/^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,32}$/] #regular expression for password validation + return true + end + return false +end + +puts "Enter Email : " +emailAddress=gets.chomp +puts "Enter Password : " +password=gets.chomp + +if(isEmailValid(emailAddress)) + puts "email is valid" +else + puts "email is not valid" +end + +if(isPasswordValid(password)) + puts "password is valid" +else + puts "password is not valid" +end + + diff --git a/25th Aug, 2019/OOP Concepts/Task - 1/farhan.rb b/25th Aug, 2019/OOP Concepts/Task - 1/farhan.rb new file mode 100644 index 0000000..e170125 --- /dev/null +++ b/25th Aug, 2019/OOP Concepts/Task - 1/farhan.rb @@ -0,0 +1,25 @@ +class Human + attr_accessor :Name, :Age, :Gender , :Height , :Weight # creates both getter and setter methods + def initialize #Constructor + end +end + +man = Human.new() +man.Name="farhan" +man.Age=25 +man.Gender="male" +man.Height=5.5 +man.Weight=65 + +human = Human.new() +human.Name="human" +human.Age="unknown" +human.Gender="unknown" +human.Height="unknown" +human.Weight="unknown" + +puts human.Weight + + + + diff --git a/25th Aug, 2019/Variables, Expressions, Loops, Conditons/Task -1/farhan.rb b/25th Aug, 2019/Variables, Expressions, Loops, Conditons/Task -1/farhan.rb new file mode 100644 index 0000000..576a981 --- /dev/null +++ b/25th Aug, 2019/Variables, Expressions, Loops, Conditons/Task -1/farhan.rb @@ -0,0 +1,23 @@ + +def isPalindrome(string) + temp=string.dup + if(string.downcase==temp.reverse!.downcase) + return true + else + return false + end +end + + +puts "Enter String : " +inputString=gets.chomp +temp=inputString.dup +puts "Length : "+inputString.size.to_s +puts "Reverse: : "+temp.reverse! +puts "isPalindrome: : "+isPalindrome(inputString).to_s +puts "lower-case: : "+inputString.scan(/[a-z]/).length.to_s +puts "upper-case: : "+inputString.scan(/[A-Z]/).length.to_s +puts "numbers: : "+inputString.scan(/[0-9]/).length.to_s +puts "special: : "+inputString.scan(/[^ A-Za-z0-9]/).length.to_s +puts "upper-case string: "+inputString.downcase +puts "lower-case string: "+inputString.upcase \ No newline at end of file diff --git a/26th Aug, 2019/File Operations/Task - 1/farhan.rb b/26th Aug, 2019/File Operations/Task - 1/farhan.rb new file mode 100644 index 0000000..d543072 --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/farhan.rb @@ -0,0 +1,80 @@ +INPUT_FILE_NAME="farhan_input.txt" +COMPRESSED_FILE_NAME="farhan_compressed.txt" +DECOMPRESSED_FILE_NAME="farhan_decompressed.txt" + +def writeDataInFile(data,fileName) + aFile = File.new(fileName, "r+") + if aFile + aFile.syswrite(data) + else puts "Unable to open file!" + end +end + +def characterCount(subString) + oldChar=subString[0] + charCount=1 + counterString="" + for i in 1..subString.length-1 do + if oldChar.match(subString[i]) + charCount+=1 + temp=charCount.dup + else + counterString+=charCount.to_s+oldChar + oldChar=subString[i] + charCount=1 + end + end + return counterString+=" " +end + +def compressor(string) + startPosition=0 + finalResult="" + loop do + spacePosition=string.index(' ',startPosition) + if spacePosition==nil + finalResult+=characterCount(string[startPosition..string.length].to_s+" ") + writeDataInFile(finalResult,COMPRESSED_FILE_NAME) + break + else + finalResult+=characterCount(string[startPosition..spacePosition].to_s) + startPosition=spacePosition+1 + end + end +end + +# def decompressor(string) +# startPosition=0 +# finalResult="" +# loop do +# spacePosition=string.index(' ',startPosition) +# if spacePosition==nil +# finalResult+=characterCount(string[startPosition..string.length].to_s+" ") +# writeDataInFile(finalResult,COMPRESSED_FILE_NAME) +# break +# else +# finalResult+=characterCount(string[startPosition..spacePosition].to_s) +# startPosition=spacePosition+1 +# end +# end +# end + + +def readdataFromFile(filename,whichFile) + if File.exists?(fileName) + if File.open(fileName) + temp="" + IO.foreach(fileName){|block|temp+=block} + if whichFile.to_i==1 + compressor temp.to_s + else + decompressor temp.to_s + else puts "Unable to open file!" + end + else + puts "File not found" + end +end + + + diff --git a/26th Aug, 2019/File Operations/Task - 1/farhan_compressed.txt b/26th Aug, 2019/File Operations/Task - 1/farhan_compressed.txt new file mode 100644 index 0000000..5169ca7 --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/farhan_compressed.txt @@ -0,0 +1 @@ +3a1m1a2r 2a1m3i1I \ No newline at end of file diff --git a/26th Aug, 2019/File Operations/Task - 1/farhan_input.txt b/26th Aug, 2019/File Operations/Task - 1/farhan_input.txt new file mode 100644 index 0000000..aabba0c --- /dev/null +++ b/26th Aug, 2019/File Operations/Task - 1/farhan_input.txt @@ -0,0 +1 @@ +aaamarr aamiiiI \ No newline at end of file diff --git a/26th Aug, 2019/Simple Mail/Task - 1/farhan.rb b/26th Aug, 2019/Simple Mail/Task - 1/farhan.rb new file mode 100644 index 0000000..1ac4daf --- /dev/null +++ b/26th Aug, 2019/Simple Mail/Task - 1/farhan.rb @@ -0,0 +1,26 @@ +require 'net/smtp' +require 'securerandom' + +def sendEmail(toEmail) + randomNumber=SecureRandom.random_number(99999..1000000) #It will generate 6 digit random number + puts "email : "+toEmail + msg = randomNumber.to_s + smtp = Net::SMTP.new 'smtp.gmail.com', 587 + smtp.enable_starttls + smtp.start("domain", fromEmail, password, :login) do #Here you should put your gmail id and password + smtp.send_message(msg, fromEmail, toEmail.to_s) #You also need to give permission for less secure app in your gmail + smtp.finish + end +end + + +if File.exists?("email.txt") + begin + arr = IO.readlines("email.txt") + sendEmail(arr[0].to_s) + rescue + puts "Unable to open file!" + end +else + puts "File not found" +end