This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddIndexToFavourites < ActiveRecord::Migration | |
def self.up | |
add_index :favourites,[:user_id,:sell_info_id],:unique => true | |
end | |
def self.down | |
remove_index :favourites,[:user_id,:sell_info_id] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails generate migration add_password_to_users encrypted_password:string | |
class AddPasswordToUsers < ActiveRecord::Migration | |
def self.up | |
add_column :users, :encrypted_password, :string | |
end | |
def self.down | |
remove_column :users, :encrypted_password | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flash[:notice] = "Item successfully saved as your favourite!" | |
#很奇怪,看官方文档,rails3里应该flash消息应该可以直接用notice(类似: redirect_to :action=>:XXX,:notice => "msg"),但我试了不行,不知为何,所以这儿还是用的老的style,记下备忘。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(req.save == nil)? false:true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SellInfo < ActiveRecord::Base | |
belongs_to :book | |
belongs_to :user | |
scope :onsale,:conditions => ['deal_status is not "sold"'] | |
scope :saled,:conditions => {:deal_status => "sold"} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@unsold = SellInfo.where("user_id = ? and deal_status != 'sold'", current_user.id) | |
@sold = SellInfo.where("user_id = ? and deal_status = 'sold'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Condition and ReentrantLock | |
class BoundedBuffer { | |
final Lock lock = new ReentrantLock(); | |
final Condition notFull = lock.newCondition(); | |
final Condition notEmpty = lock.newCondition(); | |
final Object[] items = new Object[100]; | |
int putptr, takeptr, count; | |
public void put(Object x) throws InterruptedException { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#== Never use for, unless you know exactly why. Most of the time iterators should be used instead. for is implemented in terms of each (so you're adding a level of indirection), but with a twist - for doesn't introduce a new scope (unlike each) and variables defined in its block will be visible outside it. | |
arr = [1, 2, 3] | |
# bad | |
for elem in arr do | |
puts elem | |
end | |
# good | |
arr.each { |elem| puts elem } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt-get install python-software-properties | |
$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6 | |
$ sudo apt-get update | |
$ sudo apt-get install sun-java6-jdk | |
$ sudo apt-get remove openjdk-6-jdk --purge -y | |
$ sudo apt-get autoremove | |
sudo update-java-alternatives -s java-6-sun |
OlderNewer