Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
#pdf_link a:after {
content: "<" attr(href) ">";
}
resource_path_name = Rails.root + 'config' + 'properties.xml'
resource_properties = java.util.Properties.new
resource_properties.load_from_xml(java.io.FileInputStream.new(resource_path_name.to_s))
# resource_properties['my.key'] # => 'value'
resource_properties.store_to_xml(java.io.FileOutputStream.new(resource_path_name.to_s), 'jruby rulez')
# java resource bundles initializer
if defined?(JRUBY_VERSION)
# include config directory in the class path
$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"
# because ResourceBundle.getBundle doesn't seem to use the JRuby class loader,
# we need to pass it explicitly.
def load_resource_bundle(basename, lang = java.util.Locale::ENGLISH)
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe 'Machinist' do
models = Dir[File.expand_path(File.dirname(__FILE__) + '/../app/models/*.rb')].
map{|file| File.basename(file, '.rb') } - %w{mailer}
models.map{ |model| model.classify.constantize }.each do |model|
it "should have a blueprint for the #{model} model" do
model.make.should be_instance_of(model)
end
# jhbuild on macos
git clone git://git.gnome.org/jhbuild --depth=1
cd jhbuild
./autogen.sh
make
make install
export PATH=$PATH:~/.local/bin
tar -cvjR --remove-files -f backup.tbz2 backup/
# Implements the "missing action" route by default
# see http://thelucid.com/2010/03/15/rails-can-we-please-have-a-delete-action-by-default/
ActionController::Resources::Resource.class_eval do
def add_default_actions_with_delete_action
add_default_actions_without_delete_action
add_default_action(member_methods, :get, :delete)
end
alias_method_chain :add_default_actions, :delete_action
def random_string(length)
(0...length).inject("") { |m,n| m << (?A + rand(25)).chr }
end
class PaypalPayment
def initialize(hash=nil)
hash.each_pair { |k,v| self.instance_variable_set("@#{k}".to_sym, v) } if hash.respond_to? :each_pair
end
attr_accessor :payment_gross, :mc_gross, :mc_currency, :payment_status, :pending_reason, #payment
:discount, :tax,
#transaction
:txn_type, :transaction_subject,
# payer
#!/usr/bin/env ruby
class Usually
undef_method *instance_methods.grep(/^(?!__|object_id)/)
def initialize(usual)
@usual = usual
end
def unless(cond, &unusual)