Skip to content

Instantly share code, notes, and snippets.

@amardaxini
amardaxini / cmm_scrapper.rb
Last active August 29, 2015 13:56
CNN news story parser
require 'rubygems'
require 'net/http'
require 'nokogiri'
require 'pry'
require 'open-uri'
module CnnScrapper
class CnnParser
URL = "http://edition.cnn.com"
Stock Options
79 14 3 21 104 54 12 9 94 1 96 103
require 'rubygems'
require 'pry'
a =[79, 14, 3, 21, 104, 54, 12, 9, 94 , 1 , 96, 103]
max_profit =0
max_value = a[a.size-1]
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'pry'
url = "http://www.myntra.com/brands?nav_id=2"
doc = Nokogiri::HTML(open(url))
brand_list = doc.at_css(".brands-list")
brand_name = []
brand_list.children.css("span").find_all{|y|brand_name<< y.text}
@amardaxini
amardaxini / contact.rb
Created April 30, 2013 08:20
Contact Form in Rails without databse
class Contact
include ActiveModel::Validations
include ActiveModel::Serializers
include ActiveModel::MassAssignmentSecurity
include ActiveModel::Conversion
include ActiveModel::Naming
EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
@amardaxini
amardaxini / imdb_parse.rb
Last active December 16, 2015 17:48
Write a parser for aggregating actor name and movie count they appear in, for the top 250 IMDB movies. (http://www.imdb.com/chart/top)
require 'rubygems'
require 'net/http'
require 'nokogiri'
require 'pry'
require 'open-uri'
module Imdb
class Person
class << self; attr_accessor :persons end
@persons = []
attr_accessor :name,:no_of_movies
@amardaxini
amardaxini / parse_log.rb
Created April 27, 2013 10:08
log parser test
require 'rubygems'
require 'pry'
class ParseLog
attr_accessor :response
def initialize
@response= {}
end
def parse_log(file_path="/Users/amardaxini/Downloads/sample.log")
@amardaxini
amardaxini / ups.rb
Last active December 11, 2015 02:18
module Ups
class Configuration
attr_accessor :user_id,:password,:licence
def initialzie
user_id,password,licence=nil,nil,nil
end
end
class << self
attr_accessor :configuration
end
<%= form_tag('/auctions',:method=>:get) do %>
<%= select_tag "category_id", options_from_collection_for_select(Category.all, "id", "name") %>
<%= submit_tag %>
<% end %>
#In your controller
def index
if params[:category_id]
category= Category.find(params[:category_id])
@auctions = category.auctions
else
@amardaxini
amardaxini / serialize.html.erb
Created March 29, 2012 08:41
Serialize Options
#If you have config1 as serialize parameter it store hash than
# serialize :config1,Hash
<%= form_tag(@user_config) do |f| %>
<%= text_field_tag "user_config[config1][test2]" %>
<%= text_field_tag "user_config[config1][test1]" %>
<%= submit_tag %>
<% end %>
# Now you have an array
@amardaxini
amardaxini / add.js.erb
Created August 17, 2011 08:56
redis i18n
<tr>
<td><%[email protected](".").drop(1) %></td>
<td><%= @value%></td>
</tr>