Skip to content

Instantly share code, notes, and snippets.

View TheNicholasNick's full-sized avatar

Nicholas Nick TheNicholasNick

View GitHub Profile
class BigDecimal
def self.do_cool_stuff
puts "cool stuff done"
end
end
@TheNicholasNick
TheNicholasNick / gist:161106
Created August 4, 2009 08:27
BigDecimal to Money (without the symbol)
# all my bigdeciamls going into this have been .round(2) beforehand
dollar[1] = dollar[1].split[1]
dollar[1] = "#{dollar[1][0, dollar[1].length-2].gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")}.#{dollar[1][dollar[1].length-2,2]}"
# credit where credit is due, I stole the gsub part from merb numeric helper - thanks merb!!
# the rest was bigdecimal docs :)
module War
class War::Character
include DataMapper::Resource
property :id, Serial
has n, :raid_participations, :class_name => 'War::RaidParticipants'
has n, :raids, :class_name => 'War::Raid', :through => :raid_participations, :child_key => [:character_id]
end
module Znq
module Dm;end
end
class Znq::Dm::DealGroup
include DataMapper::Resource
property :id , Serial
has n, :deals, :through => Resource, :class_name => "Znq::Dm::Deal", :child_key => [:deal_id]
@TheNicholasNick
TheNicholasNick / 0_overview.txt
Created July 10, 2009 09:00
load multiple sinatra apps
**After the fact**
namelessjon pointed me in the right direction.
map /asdasdasd do
run app
end
request.env['SCRIPT_NAME'] = "/asdasdasd"
also this is all in gem form: http://github.com/emk/sinatra-url-for/tree/master
I needed a way to have my apps be under scm and all config stuff be somewhere else.
.onsalesidebar <= sidebar {
/* extends .sidebar */
background-color: #FFA500;
}
class Post < BaseCouchRestModel
end
class Person < BaseCouchRestModel
end
class Tag < BaseCouchRestModel
end
Merb::BootLoader.before_app_loads do
# Hash extension for parsing form names into useable hash/object
class Hash
def expand_hash
sub_keys = self.keys.map { |key| key.to_s.match(/^[^-]+/).to_a.first if key.to_s.match(/-/) }.compact.uniq
result = {};
self.each do |key, value|
result[key] = value unless sub_keys.include?( key.to_s.match(/^[^-]*/).to_a.first )
end
# is there a "proper" way to do this?
# I want to return a pdf via prince if it is a pdf requested
# Otherwise return html reponse
class RefCove < Application
def show(id, cove_id)
provides :pdf, :html
@cove = Cove.get(cove_id)
raise NotFound if @cove.nil?
#!/bin/sh
#
# couchdb - this script starts and stops the couchdb server
#
# chkconfig: - 85 15
# description: Apache CouchDB document database server.
# processname: beam
# pidfile: /opt/couchdb/var/run/couchdb/couchdb.pid
# Source function library.