Skip to content

Instantly share code, notes, and snippets.

View swanandp's full-sized avatar
🖥️

Swanand Pagnis swanandp

🖥️
View GitHub Profile
@swanandp
swanandp / swanand_rmagick_outputter.rb
Created January 13, 2012 18:10
An ugly extension to add text underneath the barcode image generated by Barby
module Barby
class SwanandRmagickOutputter < RmagickOutputter
register :to_jpg_2
def to_jpg_2(*a)
to_blob('jpg', *a)
end
#Returns a string containing a JPEG image
def to_blob(format, *a)
@swanandp
swanandp / authlogic_config_example.rb
Created August 4, 2011 13:17
Shows off a few samples for acts_as_authentic configuration
class User < ActiveRecord::Base
# gradual engagement is needed, to allow admin creation of users
# users should create authorization data only when they need to
# access some system feature that requires authentication
# So ... our gradual engagement scheme for authlogic:
# 1. admin creates user, setting only name and phone number (required)
# admin may set email address (optional)
# 2. user is sent email invitation with link to activate their account
# admin can re-send email at user's request
# 3. user sets login and password/password_confirmation using activation form
@swanandp
swanandp / regexp_blank_line_match.rb
Created July 15, 2011 07:35
Regular Expression to remove Blank Lines, but keep indentation on other lines
# Regular expression for removing blank lines from a text:
#Replace this regex
/(\s+)^\r?\n?$(\s+)/mix
# With
$2 # The second match
@swanandp
swanandp / acts_as_list_position_test.rb
Created June 10, 2011 12:11
One issue on acts_as_list said that first.first? and first.last? both returned true
7.times do
ListMixin.create!
end
assert ListMixin.first.first?
assert ListMixin.last.last?
assert !ListMixin.last.first?
assert !ListMixin.first.last?
module M
def test
puts "test"
end
end
class X
include M
def test
puts "instance"