| Action | Shortcut |
|---|---|
| 1. Go to the next highlighted word | Ctrl + K |
| 2. Go to the next/previous error | Ctrl + , / Ctrl + . |
| 3. Expand / collapse | Ctrl + Numpad + / Ctrl + Numpad - |
Friday, 24 December 2010
Eclipse shortcuts
Labels:
eclipse
Tuesday, 7 December 2010
ActiveRecord
Associations
Auto-generated methods
Explanations of some methods:
others.build(attributes = {}, …): Returns one or more new objects of the collection type that have been instantiated with attributes and linked to this object through a foreign key, but have not yet been saved.
attr_protected
Attributes named in this macro are protected from mass-assignment, such as new(attributes), update_attributes(attributes), or attributes=(attributes).
Auto-generated methods
Singular associations (one-to-one)
| | belongs_to |
generated methods | belongs_to | :polymorphic | has_one
------------------+------------+--------------+---------
#other | X | X | X
#other=(other) | X | X | X
#build_other() | X | | X
#create_other() | X | | X
#other.create!() | | | X
#other.nil? | X | X |
Collection associations (one-to-many / many-to-many)
| | | has_many
generated methods | habtm | has_many | :through
------------------------------+-------+----------+----------
#others | X | X | X
#others=(other,other,...) | X | X | X
#other_ids | X | X | X
#other_ids=(id,id,...) | X | X | X
#others<< | X | X | X
#others.push | X | X | X
#others.concat | X | X | X
#others.build(attributes={}) | X | X | X
#others.create(attributes={}) | X | X | X
#others.create!(attributes={})| X | X | X
#others.size | X | X | X
#others.length | X | X | X
#others.count | X | X | X
#others.sum(args*,&block) | X | X | X
#others.empty? | X | X | X
#others.clear | X | X | X
#others.delete(other,other,..)| X | X | X
#others.delete_all | X | X |
#others.destroy_all | X | X | X
#others.find(*args) | X | X | X
#others.find_first | X | |
#others.uniq | X | X | X
#others.reset | X | X | X
Explanations of some methods:
others.build(attributes = {}, …): Returns one or more new objects of the collection type that have been instantiated with attributes and linked to this object through a foreign key, but have not yet been saved.
attr_protected
Attributes named in this macro are protected from mass-assignment, such as new(attributes), update_attributes(attributes), or attributes=(attributes).
Mass-assignment to these attributes will simply be ignored, to assign to them you can use direct writer methods. This is meant to protect sensitive attributes from being overwritten by malicious users tampering with URLs or forms.
Labels:
RoR
Sunday, 5 December 2010
Monday, 29 November 2010
Trash folder in ubuntu
It might be a good idea to set the default download folder of the browser to be the trash folder, so that you can quickly empty the folder. In ubuntu, the trash folder is in [user home dir]/.local/share/Trash/files.
Labels:
tips
Sunday, 28 November 2010
Chinese to English Translation
1. 蜂胶: Propolis ([ˈprɔpəlis]), resinous mixture that honey bees collect from tree buds, sap flows, or other botanical sources. It is used as a sealant for unwanted open spaces in the hive.
2. 皮蛋: Preserved egg
3. 分散圈:Circle of confusion [photography]
2. 皮蛋: Preserved egg
3. 分散圈:Circle of confusion [photography]
Labels:
english
Tuesday, 23 November 2010
git usages
1. Fixing un-committed mistakes
If git reset takes a commit name as its parameter, it sets the current head to the specified commit and optionally resets the index and working tree to match. It defaults to HEAD (a keyword that refers to the most recent commit to the branch you're in).
Use --soft option when you want to stage all the previous commits but not commit them. This gives you a chance to modify the previous commit by adding to or taking away from it.
With --hard, it removes the commit from your repository and from your working tree. It's the equivalent of a delete button on your repository with no "undo". It's like the commit never happened, so it should be used with care.
2. Fixing commits
3. Reset and checkout
This means that git reset paths is the opposite of git add paths.
After running git reset paths to update the index entry, you can use git-checkout(1) to check the contents out of the index to the working tree. Alternatively, using git-checkout(1) and specifying a commit, you can copy the contents of a path out of a commit to the index and to the working tree in one go.
So generally, use git checkout paths to revert changes in the working tree and use git reset paths to unstage changes.
A good explanation of
4. Tracking remote branch
Tracking when creating a new branch:
The full syntax is:
$ git reset --hard HEADThis will throw away any changes you may have added to the git index and as well as any outstanding changes you have in your working tree.
If git reset takes a commit name as its parameter, it sets the current head to the specified commit and optionally resets the index and working tree to match. It defaults to HEAD (a keyword that refers to the most recent commit to the branch you're in).
Use --soft option when you want to stage all the previous commits but not commit them. This gives you a chance to modify the previous commit by adding to or taking away from it.
With --hard, it removes the commit from your repository and from your working tree. It's the equivalent of a delete button on your repository with no "undo". It's like the commit never happened, so it should be used with care.
2. Fixing commits
$ git commit --amend -C HEADThis amends the previous commit, and keeps the same log message. "-C commit" takes an existing commit object, and reuses the log message and the authorship information when creating the commit.
3. Reset and checkout
$ git reset [commit] [--] pathWith a path parameter, git reset resets the index entries for all paths to their state at [commit]. (It does not affect the working tree, nor the current branch.)
This means that git reset paths is the opposite of git add paths.
After running git reset paths to update the index entry, you can use git-checkout(1) to check the contents out of the index to the working tree. Alternatively, using git-checkout(1) and specifying a commit, you can copy the contents of a path out of a commit to the index and to the working tree in one go.
So generally, use git checkout paths to revert changes in the working tree and use git reset paths to unstage changes.
A good explanation of
reset and, its difference with checkout is here.
4. Tracking remote branch
Tracking when creating a new branch:
The full syntax is:
$ git checkout -track -b [local branch] [remote]/[tracked branch]Simpler version is:
$ git checkout -t origin/branchSetting up tracking for an existing branch:
& git branch --set-upstream branch upstream/branch
Labels:
git
Thursday, 14 October 2010
Model View Controller
MVC provides a good abstraction and framework for combining GUI and the underlying application logic. However, different frameworks provides slightly different infrastructure for implementing MVC. Here's a summary of them.
Ruby on Rails:
Ruby on Rails:
You can implement a similar framework in Java:
- Model - The model represents data and the rules that govern access to and updates of this data. In enterprise software, a model often serves as a software approximation of a real-world process.
- View - The view renders the contents of a model. It specifies exactly how the model data should be presented. If the model data changes, the view must update its presentation as needed. This can be achieved by using a push model, in which the view registers itself with the model for change notifications, or a pull model, in which the view is responsible for calling the model when it needs to retrieve the most current data.
- Controller - The controller translates the user's interactions with the view into actions that the model will perform. In a stand-alone GUI client, user interactions could be button clicks or menu selections, whereas in an enterprise web application, they appear as
GETandPOSTHTTP requests. Depending on the context, a controller may also select a new view -- for example, a web page of results -- to present back to the user.
Interaction Between MVC Components
- The view registers as a listener on the model. Any changes to the underlying data of the model immediately result in a broadcast change notification, which the view receives. This is an example of the push model described earlier. Note that the model is not aware of the view or the controller -- it simply broadcasts change notifications to all interested listeners.
- The controller is bound to the view. This typically means that any user actions that are performed on the view will invoke a registered listener method in the controller class.
- The controller is given a reference to the underlying model.
Modifying the MVC Design
A more recent implementation of the MVC design places the controller between the model and the view. This design is common in the Apple Cocoa framework.
The primary difference between this design and the more traditional version of MVC is that the notifications of state changes in model objects are communicated to the view through the controller. Hence, the controller mediates the flow of data between model and view objects in both directions. View objects, as always, use the controller to translate user actions into property updates on the model. In addition, changes in model state are communicated to view objects through an application's controller objects.
Labels:
software engineering
Subscribe to:
Posts
(
Atom
)