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"
@amardaxini
amardaxini / thumbnail.rb
Created February 2, 2011 14:50
resize image using gd2 or generate thumbnail of image
require 'rubygems'
require 'gd2-ffij'
class Thumbnail
include GD2
def self.thumb(file_name,thumb_name,resized_width=100,resized_height=100,options={})
#import image
image = Image.import(file_name)
#resize image by passing width and height
resize_image = image.resize(resized_width, resized_height,true)
# export an image to desired file format
@amardaxini
amardaxini / README.markdown
Created August 16, 2011 07:27 — forked from ariera/README.markdown
Nestable, sortable and dragable categories

Nestable, sortable and dragable categories:

In the project I'm working on we wanted to have a Category model which we wanted to be nestable. But we also liked the user to have a draggable interface to manage and rearrange the order of his categories. So we chose awesome_nested_set for the model and jQuery.nestedSortable for the UI.

It took me some time to arrange things to work properly so I wanted to share my work in case it helps anybody.

Before beginning

you might want to take a look at a demo app

  1. go to: http://awesomenestedsortable.heroku.com/groups/
  2. click in show of any group
@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><%=@key.split(".").drop(1) %></td>
<td><%= @value%></td>
</tr>
@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
@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 / 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 / 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
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}