Skip to content

Instantly share code, notes, and snippets.

class Invoice < ActiveRecord::Base
belongs_to :user
has_many :invoice_lines
belongs_to :shipping_address, :polymorphic => true
belongs_to :billing_address, :polymorphic => true
UNPAID = 1
PAID = 2
undefined method `to_remind' for #<Class:0xb68fccb0>
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1959:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:380:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:380:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2143:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:206:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_collection.rb:376:in `method_missing'
/home/rails/leihs/leihs2demo/releases/20100305104537/app/models/user.rb:330:in `to_remind'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:10
class Account < ActiveRecord::Base
has_many :account_transactions, :as => :debit_account
has_many :account_transactions, :as => :credit_account
def credits
return AccountTransaction.find(:all, :conditions => {:credit_account_id => self.id})
end
def debits
return AccountTransaction.find(:all, :conditions => {:debit_account_id => self.id})
class ShippingRate < ActiveRecord::Base
has_many :shipping_costs
has_many :suppliers
validates_presence_of :name
# Input: Weight in grams
# Output: Price for delivery according to associated ShippingCosts
def calculate_for_weight(weight)
@psy-q
psy-q / dpkg -l
Created January 28, 2011 08:39
Package list that makes leihs run with RMagick
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-================================-==========================-============================================
ii adduser 3.110 add and remove users and groups
ii ant 1.7.0-6 Java based build tool like make
ii ant-gcj 1.7.0-6 Java based build tool like make
ii antlr 2.7.7-10 language tool for constructing recognizers,
ii apache2 2.2.9-10+lenny9 Apache HTTP Server metapackage
@psy-q
psy-q / gist:831544
Created February 17, 2011 11:35
What's taking so much damn memory?
top - 12:34:49 up 2 days, 8:53, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 24 total, 1 running, 23 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.0%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 524288k total, 524288k used, 0k free, 0k buffers
Swap: 524288k total, 201484k used, 322804k free, 0k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6118 lincomp 37 0 420m 322m 3164 S 0 62.9 0:51.90 ruby
4597 root 34 0 314m 148m 4384 S 0 28.9 0:00.92 apache2
4635 www-data 39 0 432m 147m 2272 S 0 28.8 0:05.38 apache2
@psy-q
psy-q / gist:998880
Created May 30, 2011 13:02
Cucumber stopped working
rca@macaroni:~/work/code/ror/madek$ bundle install --deployment
Fetching source index for http://rubygems.org/
Fetching source index for http://gems.github.com/
Fetching git://github.com/tpo/irwi.git
remote: Counting objects: 1325, done.
remote: Compressing objects: 100% (636/636), done.
remote: Total 1325 (delta 634), reused 1109 (delta 492)
Receiving objects: 100% (1325/1325), 128.52 KiB, done.
Resolving deltas: 100% (634/634), done.
Installing rake (0.8.7)
@psy-q
psy-q / gist:1292127
Created October 17, 2011 07:29
Can't switch rubies in a bash script
#!/bin/bash
ruby -v # Returns ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
/usr/local/rvm/bin/rvm use 1.9.2 # Outputs: Using /usr/local/rvm/gems/ruby-1.9.2-p290
ruby -v # Returns ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
@psy-q
psy-q / gist:1327425
Created October 31, 2011 12:47
Rough outline of web service API that would be necessary to marry Stizun to LedgerSMB
Stizun is a small web store we are developing for lincomp.ch. Stizun is developed here:
https://github.com/psy-q/stizun
We would like to move anything that has to do with users and user accounts, invoices, orders,
products and parts to an ERP system so that Stizun is only a thin online store frontend to the
ERP system.
What we'd need to be able to do, ideally via REST:
@psy-q
psy-q / Capistrano output
Created October 31, 2011 14:54
Capistrano bundler integration using the wrong release for installing bundle
[rca@lala leihs]$ cap staging deploy
* executing `staging'
triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
triggering before callbacks for `deploy'
* executing `retrieve_db_config'
servers: ["rails.zhdk.ch"]
** sftp download /home/leihs/leihs-test/database.yml -> /tmp/leihs_db_config.yml
[rails.zhdk.ch] /home/leihs/leihs-test/database.yml