Skip to content

Instantly share code, notes, and snippets.

View manojnaidu619's full-sized avatar
🎯
Focusing

Manoj Kumar manojnaidu619

🎯
Focusing
  • Bangalore,India
View GitHub Profile
@manojnaidu619
manojnaidu619 / gmail_login.rb
Created May 8, 2018 15:12
Gmail login ruby script using WATIR webdriver
require 'watir'
browser = Watir::Browser.new(:firefox)
browser.goto("https://www.gmail.com")
sleep 2
browser.text_field(class: "whsOnd zHQkBf").set "YOUR EMAIL ADDRESS HERE"
sleep 2
browser.span(index: 4).click
sleep 2
browser.text_field(name: "password").set "YOUR EMAIL PASSWORD HERE"
@manojnaidu619
manojnaidu619 / EVEN_and_ODD.rb
Last active May 12, 2018 10:02
A simple ruby script to Write n number of Odd or Even numbers into file.
puts "Enter 0 for even and 1 for Odd."
inp = gets.to_i
case inp
when 0
file = File.open("file_writer.txt",'w')
for i in 1..1000 do # Specify the range for EVEN loop
file.write(i, ' ') if i.even?
@manojnaidu619
manojnaidu619 / ARGV.rb
Created July 21, 2018 14:30
ARGV(Argument Vector) in ruby
args = ARGV
puts "No Arguments passed" if ARGV.empty?
for i in ARGV do
puts i
end
puts "Enter Credit card Number"
input = gets.to_s
if input =~ /[a-zA-Z[<>%\$~``!@#^&*()+=?;:{}\|''""'"]]/ # REGEX to validate Card Number
puts "Invalid Number"
else
val = input.gsub!(/[\D\s+]/, '') # val is the variable, storing the Card Number
if val =~ /^4/ and val.length >= 12 and val.length <= 19
puts "Visa"
elsif val =~ /^(5|2)[1-7][0-9]/ and val.length.eql?(16)
@manojnaidu619
manojnaidu619 / landing_page.html
Created August 10, 2018 16:55
A sample script to create a landing page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Landing Page</title>
<style>
#landing{
@manojnaidu619
manojnaidu619 / devise_error_messages.rb
Created August 23, 2018 15:34
Devise flash messages showing on the screen
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
<%- end -%>
@manojnaidu619
manojnaidu619 / products_search.rb
Last active September 10, 2018 06:16
Get the list of search products on Walmart
require 'open-uri'
require 'nokogiri'
puts 'What do you want to buy?'
product = gets.to_s
doc = Nokogiri::HTML(open("https://www.walmart.com/search/?query=#{product}")) # parsing HTML
file = File.new('search-results.txt', 'w+')
doc.xpath('//div[@class="search-result-product-title listview"]').each do |item| # Traversing through Xpath
file.write(item.text)
file.write("\n\n")
end
@manojnaidu619
manojnaidu619 / flash_in_rails.rb
Created September 10, 2018 06:21
Displaying Flash messages in Rails
<% if flash[:notice] %>
<div class="success message"><span class="close">x</span><%= flash[:notice] %></div>
<% elsif flash[:error] %>
<div class="error message"><span class="close">x</span><%= flash[:error] %></div>
<% elsif flash[:alert] %>
<div class="negative message"><span class="close">x</span><%= flash[:alert] %></div>
<% end %>
@manojnaidu619
manojnaidu619 / vowels_count.c
Created September 11, 2018 16:10
Number of vowel repetition in a string
#include <stdio.h>
#include <string.h>
int main(void) {
char str[100];
int len,j,a=0,e=0,i=0,o=0,u=0;
printf("Enter a string : ");
fgets(str,100,stdin); //taking string as input
len = strlen(str);
for(int j=0;j<len;j++){
@manojnaidu619
manojnaidu619 / Input->array.rb
Created September 13, 2018 11:07
Converts User Input to array
arr = Array.new # New array Object
a = gets
a.each_char{|e| arr.push(e)} # Push each element to array
arr.pop
p arr