Sunday, September 21, 2014
Ruby on Rails Getting Started
Pre-request
Ruby Getting Started
http://ben-bai.blogspot.tw/2014/09/ruby-getting-started.html
SQLite Getting Started
http://ben-bai.blogspot.tw/2014/09/sqlite-getting-started.html
Note
You can also use rails installer to install ruby, sqlite and rails at once.
see http://railsinstaller.org/en
Simple Note
Follow tutorial
http://guides.rubyonrails.org/getting_started.html
But not works
Follow Installation Instructions at
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
to install Development Kit
Test Development Kit
Install Rails again
Still has some error, but seems rails is installed.
Follow tutorial, type "rails new blog" to create a blog and run server
Hello, Rails!
Ruby Getting Started
Simple Note
Go to http://rubyinstaller.org/downloads/ and
choose latest stable version (1.9.3 for now)
or
check the recommanded version in download page of RoR.
http://rubyonrails.org/download/
I prefer the stable one.
Download it
run installer
follow tutorial to run first gem
http://guides.rubygems.org/make-your-own-gem/#first-gem
testing process and result
https://github.com/benbai123/RubyOnRails/blob/master/Practice/Ruby_Getting_Started/test.png
Full test project at github
https://github.com/benbai123/RubyOnRails/tree/master/Practice/Ruby_Getting_Started
Friday, September 19, 2014
SQLite Getting Started
Simple Note
Go to http://www.sqlite.org/
Go to download page
Download Precompiled Binaries for Windows
(sqlite-shell and sqlite-dll here)
Unzip them into a folder (e.g. C:\programs\sqlite)
Add the folder above into Path (the Environment variable)
or you will need to cd to that folder each time.
Open cmd
Type "sqlite3 test.db"
test.db created
now you can use SQL to access test.db
you can also execute "sqlite3" then choose database with attach command,
e.g. attach "test.db" as test
see http://stackoverflow.com/questions/9057787/opening-database-file-from-within-sqlite-command-line-shell
Monday, July 7, 2014
Flyweight Pattern in Java
Simple Note
From reference "Flyweight pattern":
flyweight is a software design pattern. A flyweight is an object that minimizes memory use by sharing as much data as possible with other similar objects; it is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory. Often some parts of the object state can be shared, and it is common practice to hold them in external data structures and pass them to the flyweight objects temporarily when they are used.
Program
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/flyweight
Run TestMain.java to test.
Assume you need to calculate lots of sum of a range of Fibonacci Numbers.
There are 2 shared items in FibRangedSum:
1. Calculated results (a Map, with Multiton Pattern)
2. Fibonacci sequence (a List, not Multiton Pattern but still Flyweight Pattern)
References:
Flyweight pattern
Fibonacci number
Thursday, June 19, 2014
Java Weak Reference
Simple Note
From reference:
A weak reference, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references allow you to leverage the garbage collector's ability to determine reachability for you, so you don't have to do it yourself.
Program
https://github.com/benbai123/JSP_Servlet_Practice/blob/master/Practice/JAVA/Commons/src/test/WeakReferenceTest.java
References:
Understanding Weak References
Sunday, June 15, 2014
Composite Pattern in Java
Simple Note
From reference:
the composite pattern is a partitioning design pattern. The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.
Program
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/composite
Run TestMain.java to test.
A Calculator probably consists of several child Calculators, you can change mode from parent Calculator then get result as needed.
References:
Composite pattern
Saturday, June 14, 2014
Bridge Pattern in Java
Simple Note
From reference:
The bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently". The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.
When a class varies often, the features of object-oriented programming become very useful because changes to a program's code can be made easily with minimal prior knowledge about the program. The bridge pattern is useful when both the class as well as what it does vary often. The class itself can be thought of as the implementation and what the class can do as the abstraction. The bridge pattern can also be thought of as two layers of abstraction.
Difference between Bridge Pattern and Adapter Pattern:
See reference.
Program
https://github.com/benbai123/JSP_Servlet_Practice/tree/master/Practice/JAVA/DesignPattern/src/bridge
Run TestMain.java to test.
Assume there are several calculator implements interface DesiredCalculator and you access them via a Bridge class rather than access them directly.
Once the API of DesiredCalculator is changed, you just need to update the content within Bridge class, all other parts of your program can stay unchanged.
References:
Bridge pattern
Difference between Bridge pattern and adapter pattern
Subscribe to:
Posts (Atom)





