Skip to content

Instantly share code, notes, and snippets.

@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 / activesupportconcern.rb
Created May 4, 2011 07:07
Active support concern handling
# Test1
module M
def foo
puts "M"
end
end
module N
include M
def foo
@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 / add.js.erb
Created August 17, 2011 08:56
redis i18n
<tr>
<td><%=@key.split(".").drop(1) %></td>
<td><%= @value%></td>
</tr>
@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
<%= 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 / 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