2008年3月31日 星期一

bento database location

Home > Library > Application Support > Bento > bento.bentodb

2008年3月30日 星期日

xcode build and gcc for universal binary

xCode
General-->Cross-Develop Using Target SDK:
Max-OS x 10.5
Then you can use features available on 10.5

build -> Architectures ( from target file):
按住mouse,之後手動輸入i386, x86_64, ppc ppc64

build --> Mac OS X Deployment Target
Mac os X 10.4
This is the minimum OS version you want to support

gcc
use -arch i386 -arch ppc
ex:
the object file generated is test.o
file test.o:
test.o (for architecture ppc7400): Mach-O object ppc
test.o (for architecture i386): Mach-O object i386

判斷 intel or power pc on mac

// for powerPC
#if __BIG_ENDIAN__
printf("big endian\n");
// for Intel
#else
printf("little endian\n");
#endif

無蝦米 on mac

(1)安裝openVanilla

(2)安裝liu3.cin到 本機硬碟>>資料庫>>OpenVanilla>>0.8.0>>Modules>>OVIMGeneric

(3)重開機

(4)open international --> openVanilla0.8.0 打勾

(5) openVanilla0.8.0-->input methods-->liu57打勾

CSS

CSS 格式

basic:
ex:
h1, h2 {
color: gray;
background: white;
}

class:
class can apply to many elements
ex:
*.warning or .warning
for each element with warning class

ex:
p.warning
for p element with warning class

the element can has more than one class
ex: <p class = "urgent warning">

串聯:
ex:
.warning.urgent
for the element with warning and urgent class
( There are problems for IE version < 7 using 串聯 )

id
use #
an id can only appear once in one HTML element
id has higher priority than class
class and id會識別大小寫

ex: *#cat = #cat
id cat applies to all elements

attribute selector:
( IE version < 7 does not support)
ex:
h1[class]
apply to <h1 class="xxx">

ex:
cat[eat]
apply to <cat eat="xxx">

ex: *[eat]
apply to all elements with eat="xxx"

串聯:
ex:
a[href][title]
apply to a element with href="xxx" and title = "xxx"

ex:
cat[eat="1"]
apply to cat with eat element = "1"

span.cat = span[class~="cat"]
apply to span element with class = "cat"

descendent selector(後代選取項)
ex:
h1 em {
color: gray;
}
apply to em element belongs to h1 element

ex:
ul ol ul em
apply to
< ul >
< ol >
< ul >
< em >

for後代選取項,選取項之間的層極可以無限大
ex: ul em
apply to
< ul >
< ol >
< ul >
< em >

選取子代組件
ex:
h1 > strong
apply only to
< h1 > < strong >
not < h1 > < em > < strong >

ex: table.sun td > p
apply to 身為td子代的p,而td是table的後代,且table的class ="sun"

2008年3月29日 星期六

ul

list-style: none;
remove the default bullet

2008年3月27日 星期四

pdisk

Apple partition table editor
(the disk must use Apple_partition_scheme. If it uses GUID_partition_scheme, pdisk can not use)

(1) input e
edit device's map
input /dev/disk2
the name of device to change is /dev/disk2

(2input c)
create a partition, with default= Apple_HFS
First block: 64
Length in blocks: 20000
Name of partition: par1

input t
change partition type
input MyPartitionType

(3) input w
write the partition table

2008年3月26日 星期三

language for website

ruby on rails ?
python with Django ?
PHP ?
webObject ?

查 distribution 版本

/etc下面通常會有一個 xxxx-release, xxxx 就是 distribution 的名字

2008年3月23日 星期日

build a basic web site with ruby on rails2

1. use rail to create default directories and files
rails -d mysql bookStore
-d mysql: use mysql as database

2. Tell rail information about database
configure config/database.yml

3. create the database
rake db:create:all

4.create the model for user account
script/generate model Account
app/models/account.rb is created
db/migrate/001_create_accounts.rb is created

app/models/account.rb
class Account < ActiveRecord::Base

end

db/migrate/001_create_accounts.rb
class CreateAccounts < ActiveRecord::Migration
def self.up
create_table :accounts do |t|
t.string :name
t.string :password
t.string :email
t.timestamps
end
end

def self.down
drop_table :accounts
end
end

5. do migration(create the table in the database)
rake db:migrate

rest for rails

rest:
Representational State Transfer

最近想買的書

Transcending CSS: The Fine Art of Web Design

Professional Ruby on Rails

2008年3月22日 星期六

box model for css

For css, every elements in html is a box


padding: the space between content and border
margin: the space between elements

css example

css can style webpage
css file is usually separated from html file

a css file example:

body{
font-size: small;
}

h1, h2 {
color: #007e7e;
}

font-size is small for boy and each element in the body
color #007e7e is for h1 and h2

table in html

table: form a table
caption: caption of the table. It is above the table by deafult
tr : form a table row
th: form the table header
td: from table data(cell)

textmate

shortcuts:

ESC: auto completion

control + ESC : show gear menu to choose bundle

complete tag for html:
ex: type table, then control +&lgr;

tab-trigger snippet
input words, then enter tab, the content is completed
ex: (1)enter doctype (2)enter tab (3)choose XHTML-0.1
result:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

run the command
option+command+r, then enter command

2008年3月21日 星期五

registerService

為了要讓clients可以找到driver,
要先呼叫registerService()

ex:
有個driver com_MySoftwareCompany_driver_SampleINQUIRYDriver,
在它的start function呼叫registerService()

bool com_MySoftwareCompany_driver_SampleINQUIRYDriver::start(IOService* provider)
{
bool success;

IOLog("SampleINQUIRYDriver::start()\n");

success = super::start(provider);

if (success) {
// Publish ourselves so clients can find us
registerService();
}

return success;
}

info.plist's IOMatchCategory and IOProbeScore

IOMatchCategory is a special property list element that allows multiple drivers to match on a single nub.

Hence, if there are two drivers for IOSCSILogicalUnitNumber, they are both attached to device.

If you want only the most suitable driver, do not set IOMatchCategory. And use IOProbeScore to give the driver you want higher score

2008年3月19日 星期三

size and IOConnectMethodStructureIStructureO

傳入IOConnectMethodStructureIStructureO之類function的output buffer size大小,
即為此buffer的大小,
所以即使buffer容量為10 byte,
若size傳入5 byte,
最後只會寫入5 byte的資料到buffer。

sense buffer in scsi

sg_io_hdr_t structure's sbp field:

points to user memory of at least 'mx_sb_len' bytes length where the SCSI sense buffer will be output.

SCSITaskStatus

in SCSITask.h

kSCSITaskStatus_GOOD = 0x00,
kSCSITaskStatus_CHECK_CONDITION = 0x02,
kSCSITaskStatus_CONDITION_MET = 0x04,
kSCSITaskStatus_BUSY = 0x08,
kSCSITaskStatus_INTERMEDIATE = 0x10,
kSCSITaskStatus_INTERMEDIATE_CONDITION_MET = 0x14,
kSCSITaskStatus_RESERVATION_CONFLICT = 0x18,
kSCSITaskStatus_TASK_SET_FULL = 0x28,
kSCSITaskStatus_ACA_ACTIVE = 0x30,
kSCSITaskStatus_TaskTimeoutOccurred = 0x01,
kSCSITaskStatus_ProtocolTimeoutOccurred = 0x02,
kSCSITaskStatus_DeviceNotResponding = 0x03,
kSCSITaskStatus_DeviceNotPresent = 0x04,
kSCSITaskStatus_DeliveryFailure = 0x05,
kSCSITaskStatus_No_Status = 0xFF

enum

ex:
enum PEOPLE { MAN, WOMAN };

enum PEOPLE person= MAN;

2008年3月18日 星期二

build a basic web site with ruby on rails

1. use rail to create default directories and files
rails -d mysql bookStore
-d mysql: use mysql as database

2. Tell rail information about database
configure config/database.yml
(1) first version
development:
adapter: mysql
encoding: utf8
database: book_development
username: deeplove
password: 111
socket: /tmp/mysql.sock

test:
adapter: mysql
encoding: utf8
database: book_test
username: deeplove
password: 111
socket: /tmp/mysql.sock

production:
adapter: mysql
encoding: utf8
database: book_production
username: deeplove
password: 111
socket: /tmp/mysql.sock
----------------------------------
(2) simpler version
defaults: &defaults
adapter: mysql
encoding: utf8
username: deeplove
password: 111
socket: /tmp/mysql.sock

development:
database: book_development
<<: *defaults

test:
database: book_test
<<: *defaults

production:
database: book_production
<<: *defaults

3. create the database
rake db:create:all
rake for ruby is like make for C

useful rake tasks:
(1)create:all :
Create all the local databases defined in config/database.yml

(2)db:drop:all
Drops all the local databases defined in config/database.yml

(3)db:rollback
Rolls the schema back to the previous version. Specify the number of steps with STEP=n

(4)db:version
Retrieves the current schema version number

4. use scaffolding to create view, model and controller for the table

script/generate scaffold Book title:string date:datetime
db/migrate/001_create_books.rb is created
The content:

class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.string :title
t.datetime :date

t.timestamps
end
end

def self.down
drop_table :books
end
end
--------------------------------
to create table or modify table:
up method

roll back to state before migration
down method
ex: change state from 002 to 001

perform the migration(create the table actually)
rake db:migrate
remember to start sql server before do migration

5. add column to existing table:

add money column on books table
(1)script/generate migration AddMoneyToBook
db/migrate/002_add_money_to_book.rb are created

(2)edit 002_add_money_to_book.rb
class AddMoneyToBook < ActiveRecord::Migration
def self.up
add_column :books, :money, :string
end

def self.down
remove_column :books, :money
end
end

(3)rake db:migrate

ps: how to roll back:
rake db:rollback
or
rake db:rollback STEP=n

6. set the route
route define what controller and action respond to url you enter
when the url's page is not in the public folder, it will find for controller and action
format: hostname/controller/action
ex:
htpp://127.0.0.1:3000/books/list
books is controller, list is action

htpp://127.0.0.1:3000/books
when no action name, index is the default

what if "htpp://127.0.0.1:3000"
(1)remove index.html in public folder
(2)add following line in config/routes.rb
map.root :controller => 'books'
map.root is a shorthand to name a route for the root path

7. run web server to test

run WEBrick Web server
script/server
the server is waiting connection on 127.0.0.1:3000

8. visit the website
http://127.0.0.1:3000
the page shown is in public/index.html


9. modify controller action and views

modify app/controllers/books_controller.rb
ex: add new method

def index
list
render :action => 'list'
end

def list
@books = Book.find(:all)
end
Book is the model name, find(:all) return all rows from books table in @books array

add app/views/books/list.rhtml

listing books

2008年3月17日 星期一

LOSleep and IOLog

Sleep the calling thread for a number of milliseconds

void IOSleep(unsigned milliseconds);

use IOSleep let the message write to log by IOLog complete

2008年3月15日 星期六

const and pointer

(1) const char *test= "hello";
the data pointed by test can not be changed
Hence, *test= "hi" is illegal
However, test="hi" is ok

(2) char *const test= "hello"
test is a constant pointer
Hence, *test="hi" is ok
However, test="hi" is illegal

(3) const char *const test= "test"
combine (1) and (2)
Hence, *test= "hi" is illegal, test="hi" is also illegal

2008年3月14日 星期五

chown

change directory or file的權限:

ex: sudo chown -R root AppleRAID.kext
AppleRAID.kext的user變成root
-R表示從AppleRAID開始,以下的hierarchy也跟著改變。

2008年3月13日 星期四

OSTypeAlloc

Allocate an instance of the desired object.
#define OSTypeAlloc(type)


ex:
OSTypeAlloc(com_apple_dts_SCSIEmulator);

errno

show error message

#include

printf("%s\n", strerror(errno)) ;

open a file

#include
#include
#include
int open(const char *pathname, int oflag,...);
int open64(const char *pathname, int oflag,...);

appleRAID



command:
diskutil createRAID mirror MyArray JHFS+ disk2s4 disk2s5

new RAID is disk3
it is composed of Untitled@4(disk2s4) and Untitled@5(disk2s5)

command:
delete raid:
diskutil destroyRAID disk3

appleRAID test program: artest
create new RAID set
artest --create --name myRAID --level mirror disk2s4 disk2s5

test AppleRAID-3.0.19 driver
when creating RAID, not use mirror
Because there are some errors in AppleRAIDMirrorSet.cpp

link_to

ex:
<%= link_to @story.name, @story.link %>
equals
<a href="<%= @story.link %>"><%= @story.name %></a>

diskutil

show disk information

show information of each disk:
diskutil list

create new RAID set:
createRAID mirror|stripe|concat setName format devices ...
ex: diskutil createRAID mirror MyArray JHFS+ disk2s4 disk2s5

Started RAID setup operation on disk disk2s4 Data_2_1
Adding booter for RAID partition 'disk2s4 Data_2_1'
Adding booter for RAID partition 'disk2s5 Data_2_2'
Adding disk 'disk2s4 Data_2_1' to new RAID set
Adding disk 'disk2s5 Data_2_2' to new RAID set
Creating RAID set (
disk2s4 Data_2_1,
disk2s5 Data_2_2
)
Bringing RAID partitions online
Waiting for new RAID to come online "C36FAD58-EF80-4DC7-AA4E-BAA85F15A222"
Creating file system on RAID volume "disk3"
[ + 0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100% ]
Finished RAID setup operation on disk disk3 MyArray

Device driver registration for disk

(1)allocate a gendisk for each disk
The gendisk structure is allocated using alloc_disk by passing minor number
Minor number means the number of partitions. Hence, 1 means no partition
(2)assign a request queue for each gendisk
(3)gendisk structures are registered using add_disk function

2008年3月12日 星期三

id and class

class
different elements can share the same class:
when you want to apply attribute to many elements, use class
an element can belong to many classes
ex: h1 class="red", h2 class="red"

how to define the class:
ex: p.green{
color: green;
}
class name is green. It only apply to p

ex: .green
class name is green. It can apply to all elements

id
id is for only one element
when you want to apply attribute to an unique element, use id
an element can only have one id
an element can have one id and belong to many classes
ex: error: h1 id= "red" , h2 id ="red"
error: p id ="red" , p id = "red"

how to define the id
ex: #test {
color: green;
}
id name is test, It can apply to all elements

p#test {
color: green
}
id name is test, it can only apply to p element

code block

two syntaxes
ex: (1) { puts "hello" }
(2) do
puts "hello"
end

define a method with call block
ex: def hello()
yield
end
yield will run the program in call block

call a method with call block
ex: hello { puts "hello" }

call a method with call block and arguments
ex: hello ("test", "good") {puts "hello"}

passing data to call block
ex:
method definition:
def hello()
yield "test", "good"
end
call method:
hello { | one, two | puts one + " "+ two }

call block with loop:
ex: ["test1", "test2"].each{ |value| puts value}

lsscsi

lists information about SCSI devices in Linux.

ex:
[0:0:8:0] disk FUJITSU MAM3184MP 0105 /dev/sda
scsi_host,channel,target_number,lun tuple for [0:0:8:0]

2008年3月11日 星期二

struct stat and stat function

#include
#include
struct stat {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
off_t st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
blksize_t st_blksize;
blkcnt_t st_blocks;
mode_t st_attr;
};

int stat(const char *restrict path, struct stat *restrict buf);
get file status

html 4.01

tell browser what version of html we use with loose standard:
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html/loose.dtd"

tell browser what version of html we use with strict standard:
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html/strict.dtd"

tell browser what encoding we use:
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"

how to suit standard:
1. img elements: add alt attribute
2. put inline element in the block element
ex: put img element in the p element
3. tell browser html version
4. tell browser encoding

html 4.01

tell browser what version of html we use:
!DOCTYPE html PUBLIC "-//W3C//DTD

delete driver catch

delete the extensions.mkext and extensions.kextcache in /System/Library

2008年3月10日 星期一

nested class

ex:
class Shape
class Circle
end
end


When you want to refer to Circle, use Shape::Circle

migration and rake

adjust database

ex:
class CreateStories < ActiveRecord::Migration
def self.up
create_table :stories do |t|
t.column :name, :string
t.column :link, :string
t.timestamps
end
end

def self.down
drop_table :stories
end
end

rake:
like make for C

to execute migration via rake:
rake db:migrate


create_table :stories, :force=>true do |t|
create the table even the table has been created by raw sql

generate a model

ex: ruby script/generate model Book

the files generated:
(1)book.rb:
class Book < ActiveRecord::Base
end

(2)book_test.rb
for unit test

(3)books.yml
a fixture, are files that contain data for unit test

(4) 001_create_books.rb
a migration file

2008年3月9日 星期日

embedded ruby(ERb)

include ruby in html file( in the view directory)
ex:
<%= 'This line is displayed in the browser' %≷
displayed in the browser

<% 'This line executes silently, without displaying any output' %≷
not displayed in the browser

template:
3 extensions:
rhtml: for HTML
rxml: for XML
rjs: for JaveScript( Ajax)

enter Rails console

ruby script/console

save data to database:
ex: test.save

rails and MVC

rails is designed by MVC concept

mapping between MVC and rails framework
Model: ActiveRecord
handle tasks related to database

View: ActionView
Controller: ActionController

crate a simple web using Rail

(1) create directory with files
rails -d mysql myWeb
(2) create database
create database myWeb_production;
create database myWeb_test;
create database myWeb_development;
ps: when execute rail command, it use development database by default

(3) create table
USE shovell_development;

CREATE TABLE `person` (

`id` int(11) NOT NULL auto_increment,

`name` varchar(255) default NULL,

`link` varchar(255) default NULL,

PRIMARY KEY (`id`)

);

database, yml and Rail

mapping between class name and table name
ex: if class name is Dog,
then ActiveRecord infers the name of table as dogs

configuration file is database.yml ( config/database.yml)

YAML:
YAML ain't markup language

run ruby in xCode

(1) use organizer:
Window --> organizer

(2) add folder with ruby file to organizer

(3) edit Actions:
Run--> edit Actions
in left panel: add item name
in right panel: Directory: Top level Organizer level
command path: /usr/bin/ruby
arguments: ruby file name, ex: test.rb

(4) Then we can run ruby program from run button

rails and WEBrick

create directory structure for Rail
ex: rails Test

create directory structure with selected database for Rail:
ex: rails -d mysql Test

WEBrick :
a web server written in Ruby
start WEBrick:
ex: ruby script/server blow Test directory
Then the server will listen on TCP port 3000

connect to WEBrick:
http://localhost:3000

rubygems

a utility to manage the libraries for Ruby

each Ruby library is known as a gem or RubyGem

update rubygems
sudo gem update --system

update rails
sudo gem install rails


sudo gem gem update rake:
rake is a make-like build tool for rails

list installed gems
gem list

2008年3月6日 星期四

NSNumber

#include

SCSI Domain Identifier

SCSI Domain Identifier = bus id = kIOPropertySCSIDomainIdentifierKey
SCSI Target identifier = scsi target id = kIOPropertySCSITargetIdentifierKey
SCSI Logical Unit Number = lun = kIOPropertySCSILogicalUnitNumberKey

range and symbol

Range:
ex:
('A'..'Z')
it is the range between 'A' and 'Z'

change range to array
ex: ('A'..'Z').to_a

check if something is in the range
ex: ('A'..'Z').include?('R')

Symbol:
ex: :good
: + name = symbol
it is more efficient than object
Usage: varying data as object, fixed data as symbol

Time

現在時間:
Time.now
--> Tue Mar 3 01:01:01 +0100 2007

ex:
Time.now + 10.minuets
Time.now + 10.hours
Time.now + 10.days

Time.at( epoch_second)
epoch_second is the number of seconds since Unit time epoch, at method return Time object

2008年3月5日 星期三

code block

code block
do end = { }

def each_vowol(&code_block)
%w{a e i o u}.each { |vowel| code_block.call(vowol) }
end

assign call block to variable:
use lambde
ex: a = lambde{ |x| puts x}

control flow

if and else
ex: if a <3
puts "<"
else
puts ">="
end

elsef = else if:

case:
ex: case fruit
when "a"
puts "a"
when "b"
puts "b"
else
puts "c"
end

while:
while a <3
puts "a"
end

until:
until a < 3
puts "a"
end

hash

test= { 'a' => 'A', 'b' => 'B' }

ex: test['a']
// get 'A'

iterate through hash
x.each{ |key, value| puts "abc"}

get keys
x.keys.inspect

delete element
x.delete("a")
x.delete_if { |key value| value < 25}

array

define array:
ex: x=[1,2,3,4]
y=[]

add element to array
x << "one"
or
x.push("one");

get last element of the array
x.pop

join every element in the array
x.join
x.join(',') // join with ,

split string into array
"hello".split(/\s+/).inspect
inspect give a textual representation of the object

array iteration:
[1,2].each{ |element| puts elements.to_s }
[1,2].collect{ |element| element*2 }
collect iterates through array and assign each element the result of expression

add two array:
x+y

array subtraction:
x-y

check array empty:
x.empty?

check item in the array:
x.include?("x")

get first and last element
x.first
x.last
x.first(2) // first 2 elements

array reverse:
x.reverse

%w( red blue)
create an array from a list of strings

regular expression and ruby

/^../ :
/ / to start and end regular expression
^ means beginning of line
. means any character

$ means the end of the line

\A means start of the string
\Z means the end of the string
\w means any character, digit or underscore
\W means anything that does not match \w
\d means any digit
\D means anything that does not match \d
\s whitespace( space, tab, newline)
\S Non-whitespace
+ means match 1 or more of that type of character, match as many as possible
* means match 0 or more of that type of character, match as many as possible
*? means match 0 or more of that type of character, match as few as possible
+ means match 1 or more of that type of character, match as few as possible
? means match 1 or 0 of that type of character
{x} means match x occurrences of that type of character
{x, y} means match as least x times and as most y times
\d+ means match as many digits in a row as possible
\ means escape

ex: "this is a test".scan(/\w\w) { |x| puts x }
scan trough string, find something that match \w\w

ex: "hello".scan(/[aeiou]/
match any of a,e,i,o,u
ex: "hello".scan(/[a-m]/
match any of a to m

matching:
use =~
ex: "this is a test" =~ /[0-9]/
if match, return true, else, return false

use match
ex: "hello".match("[0-9]")

IOSleep

IOSleep(unsigned milliseconds);
puts the currently executing thread to sleep for a certain period of time

2008年3月4日 星期二

ruby basic

start ruby:
irb

file extension:
.rb

run ruby file:
ex: ruby test.rb

define class, member and method:
class Animal
attr_accessor :name, :age
def bark
puts "bark"
end
end

member is defined by attr_accessor
method is defined by def

another getter/setter method:
ex: def face=(x)
@face=x
end
def face
@face
end

define method with parameter
def test(x, y)
puts "hello"
end

class member
ex: @@a=0


class method:
ex: class Car
@@window=0;
def self.add
@@window= @@window+1
end
end


new object
ex: test= Animal.new
test.name = "peter"
test.bark

print:
use print( 印完後在同一行)
ex: print "hello"

use puts (印完後在下一行)
ex: puts "hello"

inheritance:
class Dog < Animal
attr_accessor :voice
end

show class:
ex: dog.class

string method:
ex: "helllo".length
--> 5

if and unless:
unless is the opposite of if
ex: puts "hello" unless a > 3

loop:
ex: (1) 5.times do puts "test" end
(2) 5.times { puts "test" }
"test" is printed 5 times

ex: (3) 1.upto(5) { |number| puts number } // from 1 to 5, number is the parameter
(4) 10.downto(5){ } // from 10 to 5
(5) 0.step(50,5){ } // from 0 to 50, step is 5

constant:
variable name that begins with a capital letter
ex: Pi

conversion between int and float
x.to_f : int to float
x.to_i : float to int

char and ASCII number:
puts ?x // get x's ascii number
puts 120.chr // get ascii 120's char

embedded expressions in string:
ex: puts "#{x} + #{y} = #{x +y}"
use # and { } to include expression. Expression is calculated first and then translated to string


convert number to string:
ex: x.to_s

substitution:
ex; "foobarbar".sub('bar', 'abc')
---> fooabcbar
"foobarbar".sub(bar, 'abc')
---> fooabcabc

comment :
use #

if a method will modify something, it is commonly suffixed with !
ex: fox.upcase!
fox become FOX

if a method return boolean values, it is commonly suffixed with?
ex: fox.empty?

initialize method is call when an object is instantiated

watch doc:
ri with something you want to find
ex: ri Array

return:
when defining method in ruby, return is optional
because the last expression of the method return by default

ls color under MAC

讓ls顯示color
輸入alias ls='ls -G' 於.bash_profile

alias

自訂command
ex: alias cp='cp -i'
輸入cp即等於cp -i

inet_ntoa

inet_ntoa:
converts a network address in a struct in_addr to a dots-and-numbers format string.

inet_aton:
inet_aton() is the opposite, converting from a dots-and-numbers string into a in_addr_t

struct sockaddr and sockaddr_in and in_addr

struct sockaddr
{
unsigned short sa_family; /* address family, AF_xxx */
char sa_data[14]; /* 14 bytes of protocol address */
};


struct sockaddr_in
{
short int sin_family; /* Address family */
unsigned short int sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
unsigned char sin_zero[8]; /* Same size as struct sockaddr */
};

struct in_addr
{
in_addr_t s_addr;
};

2008年3月3日 星期一

select

int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);

If timeout is NULL , select will return after get sthing

getaddrinfo

#include
#include
#include

int ai_flags Input flags.
int ai_family Address family of socket.
int ai_socktype Socket type.
int ai_protocol Protocol of socket.
socklen_t ai_addrlen Length of socket address.
struct sockaddr *ai_addr Socket address of socket.
char *ai_canonname Canonical name of service location.
struct addrinfo *ai_next Pointer to next in list.

2008年3月2日 星期日

mptsas

sas driver on linux

mdprobe mptsas

mysql command

start mySQL:
sudo /usr/local/mysql/bin mysqld_safe

stop mySQL:
sudo /usr/local/mysql/bin mysqladmin shutdown

create an account:
mysql -h localhost -p -u root
GRANT ALL ON*.* TO'deeplove'@'localhost'IDENTIFIED BY'111';
create new user account "deeplove", with password 111,
connect to database from "localhost", ALL means you can do anything( SELECT, INSERT, ...)
*.* means you can connect to every database ( Dog.* means you can only connect to Dog database)

connect to database:
mysql -h localhost -p -u deeplove
-h means host, connect to localhost
-p means password , -u means user

create database:
ex: CREATE DATABASE dog;

create table:
mysql> USE dog;
mysql> CREATE TABLE dogTable (thing VARCHAR(20), legs INT, arms INT);
mysql> INSERT INTO dogTable (thing,legs,arms) VALUES('human',2,2);
mysql> INSERT INTO dogTable (thing,legs,arms) VALUES('insect',6,0);
use dog means use database "dog"

dogTable is the name of table
The table has three field, thing, legs, and arms

leave mysql:
QUIT

which is current database:
SELECT database();

show database information
\s

show tables
show tables in this database

show databases
show databases

show columns from books
show columns of table books

describe books
describe table books

select * from books
show the content of table books

delete from books where title='story';
delete the records with title = 'story' from table books

2008年3月1日 星期六

webobject

Apple's enterprise framework for developing scalable Web applications using proven object-oriented design principals

written in Java, can run everywhere

webObject framework is not installed by default. Download from ADC and install it

how to develop webObject:
1. install webObject framework from ADC
2. install eclipse sdk (at least 3.3.2)
ex: choose Eclipse Classic 3.3.2 under download page
3. install WOLips from eclipse
reference: http://wiki.objectstyle.org/confluence/display/WOL/Install+WOLips+with+Eclipse+Update+Manager

define variable in wod檔
use WOD Editor's completion abilities: ctrl+space

wiki server

mac os x 10.5 上的wiki server,方便建構網站