1. Udacity ud120
2. Andrew Ng youtube Videos
3. kaggle learning (including python ,SQL ,Pandas, Deep learning and Data Visualization)
4. Google AI education
5. pyimagesearch website held by which has loads of opencv intros and object detection demo codes and detail applications sample codes. YOLO3. Must take a peek if you are interest in computer visions.
2018年11月30日 星期五
2018年7月29日 星期日
Pandas index and selection
pandas is a very handy module for data scientist using python.
There are some tricks that worth noted here for reference.
Skip the basic DataFrame and Series class, i'll put focus on data selection.
Most commonly used method for indexing are loc and iloc.
reviews.loc[[0,1,10,100],['country','province','region_1','region_2']
Above code select columns 'country','province','region_1','region_2' of row 0,1,10,100 from reviews DataFrame. loc is used for selection with string column name or index name.
reviews.iloc[[1,2,3,5,8],:]
This line used to select with numeric indexing of rows 1,2,3,5,8 from reviews dataframe
reviews.loc[[x for x in range(101)],['country','variety']]
More complex usage. Select first 100 rows of columns 'country' and 'variety'
reviews.country == 'Italy'
This line of code can produce a boolean Series which can be used for conditioning select.
For example:
reviews[reviews.country =='Italy']
This line can select reviews of country equal to 'Italy'
reviews.region_2.notnull()
notnull isnull can be used to produce a Series used to indexing whether the column is not NaN or is NaN
logical operation can also been used for dataframe selection
ds3 = reviews[reviews.country.isin(['Italy','France']) & (reviews.points >=90)].country
isin method equals to 'in' operation of python. notice the '&' equal to 'and' in python.
But we may got confused why it creates another operators for pandas indexing?
2018年6月15日 星期五
Feature optimize for machine learning-One-Hot Encoder
Recently begin study MLCC from google.
Besides complex mathematics underneath all kinds of optimizers, over 80% of work time will be spent on data collecting/processing/cleaning and define useful features to feed to optimizer.
Linear regressor requires numeric features. So for some of the data columns which contains characters/string(categorical), we can use so call "One hot encoding" method to convert these kind of data. skikit-learn offer module to easily get these done
LabelEncoder
OneHotEncoder
output is the transformed integer list from input list, but still not yet an one-hot list.
You still need to User OneHotEncoder to encode integer list to one-hot formateed list with below code
This discrete feature to numeric feature transformation is frequently used in ML. Noted Here.
Besides complex mathematics underneath all kinds of optimizers, over 80% of work time will be spent on data collecting/processing/cleaning and define useful features to feed to optimizer.
Linear regressor requires numeric features. So for some of the data columns which contains characters/string(categorical), we can use so call "One hot encoding" method to convert these kind of data. skikit-learn offer module to easily get these done
LabelEncoder
OneHotEncoder
from numpy import array
from numpy import argmax
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
input_data = ['happy','sad','cry','happy','blank','blank','sad','cry','happy','sad']
#need to convert to array structure
values = array(input_data)
# integer encode
label_encoder = LabelEncoder()
encoded_output_list = label_encoder.fit_transform(values)
print(encoded_output_list)
Output:
[2 3 1 2 0 0 3 1 2 3]
output is the transformed integer list from input list, but still not yet an one-hot list.
You still need to User OneHotEncoder to encode integer list to one-hot formateed list with below code
# binary encode
onehot_encoder = OneHotEncoder(sparse=False)
#need to reshape integer list shape from 1xn to nx1 since it fits
#feature columns more for later Machine learning usage
integer_encoded = integer_encoded.reshape(len(integer_encoded), 1)
onehot_encoded = onehot_encoder.fit_transform(integer_encoded)
print(onehot_encoded)
Output:
[[0. 0. 1. 0.]
[0. 0. 0. 1.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[1. 0. 0. 0.]
[1. 0. 0. 0.]
[0. 0. 0. 1.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
This discrete feature to numeric feature transformation is frequently used in ML. Noted Here.
2018年4月29日 星期日
How to set up cgi module for apache2
At this moment, i am studying CGI(common gateway interface) script with python. Need to setup a temporary local website for test. Some notes here.
Environment
1. ubuntu 14 server
2. apache2 install
I am not sure any python copy should be installed or not necessary.
First need to edit /etc/apache2/conf-enabled/serve-cgi-bin.conf
substitute the directory after "ScriptAlias" with the directory you want to put your cgi
script files.
Note. this directory must fall in access range of apache2. You can edit apache2.conf under
/etc/apache2/ directory to add your directory
cgi module is not enabled by default while apache2 installed. You have to manually add it by make a link to /etc/apache2/mods-enabled directory with below command
then reload apache2
It's all set. You can now put your first cgi script to your cgi-bin directory and test it with your favorite browser under http://localhost/cgi-bin/xxx.py
oh! one more thing! Remember to change access mode to your script file.
Environment
1. ubuntu 14 server
2. apache2 install
I am not sure any python copy should be installed or not necessary.
First need to edit /etc/apache2/conf-enabled/serve-cgi-bin.conf
<IfModule mod_alias.c> <IfModule mod_cgi.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfModule mod_cgid.c> Define ENABLE_USR_LIB_CGI_BIN </IfModule> <IfDefine ENABLE_USR_LIB_CGI_BIN> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all granted </Directory> </IfDefine> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
script files.
Note. this directory must fall in access range of apache2. You can edit apache2.conf under
/etc/apache2/ directory to add your directory
<Directory "/var/www/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> <Directory "/var/www/cgi-bin"> Options All </Directory>
$ cd /etc/apache2/mods-enabled $ sudo ln -s ../mods-available/cgi.load
$ sudo service apache2 reload
oh! one more thing! Remember to change access mode to your script file.
sudo chmod +x /usr/lib/cgi-bin/xxx.py
2018年4月3日 星期二
Python install Modules
Besides standard Library, there are lots of modules developed by independent contributors and academy or science group. You can use commands to download and install these modules with built in pip install program.
python -m pip install --user modulename
Here list some modules of categories
1. web framework
python -m pip install --user modulename
Here list some modules of categories
1. web framework
- Django
- Pyramid
- Web2py
- flask
2. Graphic processing
- PIL
- Pillow
3. Science and Math
- numpy
- Matplotlib
- pandas
- scikit-learn
4. command line operation
- fabric
- paramiko
5. Nature language processing
- nltk
- textblob
- jieba
6. network client
- requests
- pycurl
7. database protocol
- mysql-python
- pymongo
- psycopg2
Python Study Note (1)
Besides ordinary Python Manual reading, i would like to put some notes here to refresh my bad memory. There are many key words that i need to keep in mind when learning new computer language especially this language being a huge different compared to what i used for living(c, assembly).
Well skip the interpreter part which i see tiny chance of using it.
Typical python module definition file which have file extension of *.py have below format.
if you have multiple version of python install in your system, you can specify which version you want your program to run with.
There are some coding style that it would be nice to follow.
Well skip the interpreter part which i see tiny chance of using it.
Typical python module definition file which have file extension of *.py have below format.
if you have multiple version of python install in your system, you can specify which version you want your program to run with.
#below check your py.ini for defaults of "python" version #! python #below specify the encoding of this python source file. utf-8 is default. #-*-coding: utf-8-*- #then import some module you reference import numpy import sys,os def fun1(a): pass def main(): pass #below will use module file as script to run main, mainly for test purpose if __name__ == '__main__': main()
-
Use 4-space indentation, and no tabs.4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.
-
Wrap lines so that they don’t exceed 79 characters.This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
-
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
-
When possible, put comments on a line of their own.
-
Use docstrings.
-
Use spaces around operators and after commas, but not directly inside bracketing constructs:
a = f(1, 2) + g(3, 4). -
Name your classes and functions consistently; the convention is to use
CamelCasefor classes andlower_case_with_underscoresfor functions and methods. Always useselfas the name for the first method argument. -
Don’t use fancy encodings if your code is meant to be used in international environments. Python’s default, UTF-8, or even plain ASCII work best in any case.
-
Likewise, don’t use non-ASCII characters in identifiers if there is only the slightest chance people speaking a different language will read or maintain the code.
2018年3月7日 星期三
AI study note
AI is getting more and more real life applications recent couple years. By realize this, i think it is time to know more detail of it. There's more resources on the web then before.
The most famous online course in this field is opened by Andres Ng on coursera. He is the icon of current AI industry.
Andrew Ng Stanford University
There's also a simple introduction to AI learning by Shival Grupta
Shiva Gupta blog
Albeit there's no pre-request of programming language, but i decide to cut in follow Shival's path with Python and google's tensorflow.
The most famous online course in this field is opened by Andres Ng on coursera. He is the icon of current AI industry.
Andrew Ng Stanford University
There's also a simple introduction to AI learning by Shival Grupta
Shiva Gupta blog
Albeit there's no pre-request of programming language, but i decide to cut in follow Shival's path with Python and google's tensorflow.
2017年8月26日 星期六
linux learn note
install package
download package either by browser or wget a .deb file
sudo dpkg -i XXXXX.deb
if meet issues, try below
sudo apt-get -f install
sudo dpkg -i XXXXX.deb
to update current install package
sudo apt-get update
install svn
1. install apache2
sudo apt-get install apache2
configure apache2
....
2. install svn
sudo apt-get install subversion
configure svn and start svn daemon
To list packages install in system
pkg-config --list-all
To uninstall a make install
sudo make uninstall
if not work
try
checkinstall
or use
make -n install
to trace install steps and uninstall manually
download package either by browser or wget a .deb file
sudo dpkg -i XXXXX.deb
if meet issues, try below
sudo apt-get -f install
sudo dpkg -i XXXXX.deb
to update current install package
sudo apt-get update
install svn
1. install apache2
sudo apt-get install apache2
configure apache2
....
2. install svn
sudo apt-get install subversion
configure svn and start svn daemon
To list packages install in system
pkg-config --list-all
To uninstall a make install
sudo make uninstall
if not work
try
checkinstall
or use
make -n install
to trace install steps and uninstall manually
2017年8月22日 星期二
EFI switch Graphic Mode
UEFI switch between graphic/Text mode example.
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl);
if (ConsoleControl != NULL)
{
ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenGraphics);
}
Only below two modes can choose from.
EfiConsoleControlScreenText,
EfiConsoleControlScreenGraphics
Learn one thing. Even switch to graphic mode, you can still use EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL or even Print.
2015年3月31日 星期二
Overcome the Eight Barriers to Confidence
轉載文 建立自信心非常有用
To get a more confident You in the new year — or a more confident company, community, family, or team — first know what gets in the way. The best resolutions will go nowhere without the confidence to stick with them.
Confidence is an expectation of a positive outcome. It is not a personality trait; it is an assessment of a situation that sparks motivation. If you have confidence, you’re motivated to put in the effort, to invest the time and resources, and to persist in reaching the goal. It’s not confidence itself that produces success; it’s the investment and the effort. Without enough confidence, it’s too easy to give up prematurely or not get started at all. Hopelessness and despair prevent positive action.
To muster the confidence to work toward your goals, avoid these eight traps:
- Self-defeating assumptions.
- You think you can’t, so you don’t. A British Olympic runner is so rattled by a misstep that cost her a contest that she dropped out of the next. A company team decides that a popular world leader is so far out of their league that they don’t issue an invitation to speak at their customer event. Talented women sometimes “leave before they leave,” as Sheryl Sandberg puts it, assuming that they won’t be promoted (or succeed when they have children) so they start behaving like they’re departing years before departure, thus foreclosing their options. It’s one thing to be realistic, it’s another to behave like a loser before entering the game.
- Goals that are too big or too distant.
- I know how often leaders say they want to tackle BHAGs — “big hairy audacious goals.” But having only enormous goals can actually undermine confidence. The gap between a giant goal and today’s reality can be depressing and demotivating. Confidence comes from small wins that occur repeatedly, with each small step moving you closer to the big goal. But the small steps must be valued and turned into goals themselves. Winners think small as well as big.
- Declaring victory too soon.
- This is the dieter’s dilemma: lose the first few pounds, and feel so good that you reward yourself with chocolate cake, and when the pounds go back on, you feel so discouraged that you have more cake to feel better. I saw this pattern in a college football team that was coming off a 9-year losing streak (yes, 9 years!). After winning the first game in nearly a decade, a team member shouted that now we’ll win the championship. First, of course, they had to win the next game — which they didn’t. Step-by-step discipline builds confidence.
- Do-it-yourself-ing.
- It’s a trap to think you can go it alone, without a support system and without supporting others. Losing teams have stars, but they focus on their own records, not how well the whole team does; the resulting resentments and inequalities provoke internal battles that drag everyone down. To build your confidence, think about building the confidence of others and creating a culture in which everyone is more likely to succeed, whether through mentoring them or recognizing their strengths. Giving to others boosts happiness and self-esteem, as numerous research studies show. Supporting them makes it easier to ensure that they support you.
- Blaming someone else.
- Confidence rests on taking responsibility for one’s own behavior. Even in difficult circumstances, we have choices about how to respond to adversity. Whining about past harms reduces confidence about future possibilities. When the blame game is carried out within companies, everyone loses confidence, including external stakeholders. Confidence is the art of moving on.
- Defensiveness.
- It’s one thing to listen and respond to critics; it’s another to answer them before they’ve done anything. Don’t defend yourself if you’re not being attacked. Apologize for your mistakes, but don’t apologize for who or what you are. Instead, take pride in where you’ve come from and lead with your strengths.
- Neglecting to anticipate setbacks.
- Confidence involves a dose of reality. It is not blind optimism, thinking that everything will be fine no matter what. Confidence stems from knowing that there will be mistakes, problems, and small losses en route to big wins. After all, even winning sports teams are often behind at some point in the game. Confidence grows when you look at what can go wrong, think through alternatives, and feel you are prepared for whatever might happen.
- Over-confidence.
- Confidence is a sweet spot between despair and arrogance. Don’t let confidence slip over into the arrogant end. Over-confidence is the bane of economies (e.g., the irrational exuberance that preceded the global financial crisis), corrupt leaders (who assume they’re so necessary that they won’t get into trouble for a small expense account fudge), or individuals who swagger and feel entitled to success rather than working for it. Arrogance and complacency lead to neglect of the basics, deaf ears to critics, and blindness to the forces of change — a trap for companies as well as individuals. Sure enough, like the old proverb that “pride goeth before a fall,” the slide into a losing streak often begins with a winning streak. A little humility goes a long way to moderate arrogance and keep just the right amount of confidence.
Remember, it’s not enough just to feel confident. You have to do the work. But with an expectation of success, you can try new things, form new partnerships, contribute to shared success, and revel in small wins that move you toward bigger goals.
2012年12月16日 星期日
Objective-C 的精隨
There's three traits that differ objective-C with other object oriented language. They are sort of related but i will introduce them one by one.
Polymorphism:
Well different class sure can have same name class methods. This is not much different with other object-orient language but will cause much confuse in pure C. But this feature will be very important if combine with following two other objective-c only feature.Dynamic Typing:
This together with polymorphism will make codes more reusable since return type and parameters types no longer fixed. This can enables run-time determined object types to call same name methods which can invoke different method calls. ex.
//assume Fraction and Complex class all defined Print but show different format
id classobj;
aFraction * = [Fraction new];
aComplex *=[Complex new];
classobj = aFraction;
[classobj Print];
classobj = aComplex;
[classobj Print];
Well this is not significantly showing how Dynamic Typing's goodness. But pass attention that id object's method call is determined at runtime by which type of object it contains. This is highly not possible for other language.
Dynamic Binding
This feature means an object can determined at runtime which method it will invoke under circumstances at that time. Introduce selector concept and @selector directive. example as below
SEL action;
id graphicobject;
...
action = @selector (draw) ;
...
[graphicobject performSelector:action];
This will also introduce a series of method that under NSObject the perform support for dynamic typing and dynamic binding feature.
-(BOOL) isKindOfClass:class-object
-(BOOL) isMemberOfClass:class-object
-(BOOL) respondsToSelector:selector
-(BOOL) instancesRespondToSelector:selector
-(BOOL) isSubclassOfClass:class-object
-(id)performSelector:selector
-(id)performSelector:selector withObject:object
-(id)performSelector:selector withObject:object1 withObject:object2
2012年12月4日 星期二
Xcode 快捷鍵
轉載自http://www.cnblogs.com/yjmyzz/archive/2011/01/25/1944325.html
1. 文件
CMD + N: 新文件
CMD + SHIFT + N: 新项目
CMD + O: 打开
CMD + S: 保存
CMD + SHIFT + S: 另存为
CMD + W: 关闭窗口
CMD + SHIFT + W: 关闭文件
2. 编辑
CMD + [: 左缩进
CMD + ]: 右缩进
CMD + CTRL + LEFT: 折叠
CMD + CTRL + RIGHT: 取消折叠
CMD + CTRL + TOP: 折叠全部函数
CMD + CTRL + BOTTOM: 取消全部函数折叠
CTRL + U: 取消全部折叠
CMD + D: 添加书签
CMD + /: 注释或取消注释
CTRL + .: 参数提示
ESC: 自动提示列表
3. 调试
CMD + \: 设置或取消断点
CMD + OPT + \: 允许或禁用当前断点
CMD + OPT + B: 查看全部断点
CMD + RETURN: 编译并运行(根据设置决定是否启用断点)
CMD + R: 编译并运行(不触发断点)
CMD + Y: 编译并调试(触发断点)
CMD + SHIFT + RETURN: 终止运行或调试
CMD + B: 编译
CMD + SHIFT + K: 清理
4. 窗体
CMD + SHIFT + B: 编译窗口
CMD + SHIFT + Y: 调试代码窗口
CMD + SHIFT + R: 调试控制台
CMD + SHIFT + E: 主编辑窗口调整
5. 帮助
CMD + OPT + ?: 开发手册
CMD + CTRL + ?: 快速帮助
CMD + N: 新文件
CMD + SHIFT + N: 新项目
CMD + O: 打开
CMD + S: 保存
CMD + SHIFT + S: 另存为
CMD + W: 关闭窗口
CMD + SHIFT + W: 关闭文件
2. 编辑
CMD + [: 左缩进
CMD + ]: 右缩进
CMD + CTRL + LEFT: 折叠
CMD + CTRL + RIGHT: 取消折叠
CMD + CTRL + TOP: 折叠全部函数
CMD + CTRL + BOTTOM: 取消全部函数折叠
CTRL + U: 取消全部折叠
CMD + D: 添加书签
CMD + /: 注释或取消注释
CTRL + .: 参数提示
ESC: 自动提示列表
3. 调试
CMD + \: 设置或取消断点
CMD + OPT + \: 允许或禁用当前断点
CMD + OPT + B: 查看全部断点
CMD + RETURN: 编译并运行(根据设置决定是否启用断点)
CMD + R: 编译并运行(不触发断点)
CMD + Y: 编译并调试(触发断点)
CMD + SHIFT + RETURN: 终止运行或调试
CMD + B: 编译
CMD + SHIFT + K: 清理
4. 窗体
CMD + SHIFT + B: 编译窗口
CMD + SHIFT + Y: 调试代码窗口
CMD + SHIFT + R: 调试控制台
CMD + SHIFT + E: 主编辑窗口调整
5. 帮助
CMD + OPT + ?: 开发手册
CMD + CTRL + ?: 快速帮助
下面也是一些有用的快捷键(转自http://www.cppblog.com/brucejini/archive/2010/12/24/137367.html)
Command + Shift + E :扩展编辑器
Command + [ :左移代码块
Command + ] :右移代码块
Tab :接受代码提示
Esc :显示代码提示菜单
Ctrl + . (句点):循环浏览代码提示
Shift + Ctrl + . (句点):反向循环浏览代码提示
Ctrl + / :移动到代码提示中的下一个占位符
Command + Ctrl + S :创建快照
Ctrl + F :前移光标
Ctrl + B :后移光标
Ctrl + P :移动光标到上一行
Ctrl + N:移动光标到下一行
Ctrl + A : 移动光标到本行行首
Ctrl + E : 移动光标到本行行尾 --杨过注:这二个太有用了,刚开始用XCode,一直奇怪为啥Home与End键为啥不能直接定位到行首、行尾?
Ctrl + T :交换光标左右两边的字符
Ctrl + D:删除光标右边的字符
Ctrl + K :删除本行
Ctrl + L : 将插入点置于窗口正中
Command + Alt + D:显示open quickly 窗口
Command + Alt + 上方向键 :打开配套文件
Command + D :添加书签
Option + 双击:在文档中搜索
Command + Y :以调试方式运行程序
Command + Alt + P : 继续(在调试中)
Command + Alt + 0 :跳过
Command + Alt + I :跳入
Command + Alt + T :跳出
2012年9月21日 星期五
How to include and make use of .uni files to your EDKII/UDK applications.
Well. Today i need to build up a helper to my efi application. I check for the sample in network package. I found one way. Steps as below.
- put all your helper text into a uni file. for example: myhelp.uni
- add myhelp.uni to [Sources]. This will trigger the HII compiler to autogen related HII data structure.
- Initialize your HII handle with HiiAddPackages mHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, BASE_NAMEStrings, NULL); IMPORTANT! the third parameter should be your BASE_NAME in your inf file with "Strings" appended. This is due to autogen will use this fixed variable name.
- You can use ShellPrintHiiEx function to display Messages. ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_INVALID_INPUT), mHiiHandle);
2012年7月12日 星期四
While Secure Boot Active run Shell Application
As you know, secure boot is one of the crucial features that MS Win8 emphasize on. To protect the entire system since the boot time. Albeit secure boot feature is not explicitly exclude tradition CSM, but current IBV implementation put secure boot under CSMless mode. This will lead to user can not boot from USB dongle into DOS to access traditional tools like IRU or flash rom. Instead, UEFI shell kick in. But there's some tricky steps to enable boot to UEFI shell when secure boot enable.
makecert -n "CN=PkRoot" -r -sv PkRoot.pvk PkRoot.cer
You can replace "PkRoot" whatever name you like. This will generate a private key and a certificate. Remember the password you type.
Also memorize Kek key password. It will be used to sign efi applications.
xxx is the password for kek private key.
xxx still be password of Kekroot.pvk
But there's one VERY critical step left.
- You need to generate a certificate. To achieve this, you need to install latest Windows Kit. Under it's install directory find an executable file named "makecert.exe" depend on your working computer's X86 or X64. execute following command.
makecert -n "CN=PkRoot" -r -sv PkRoot.pvk PkRoot.cer
You can replace "PkRoot" whatever name you like. This will generate a private key and a certificate. Remember the password you type.
- Then proceed to generate Kek key and certificate using the platform key you just generated.
Also memorize Kek key password. It will be used to sign efi applications.
- Transform kek private key to pfx format (PKCS#12)
xxx is the password for kek private key.
- Now you can use KekRoot.cer and KekRoot.pfx to sign whatever efi application or driver you want to execute on your platform. Command as below.
xxx still be password of Kekroot.pvk
But there's one VERY critical step left.
- You need to include the KekRoot.cer to your BIOS image and put it in ALLOW certificate. Different IBV should probably have different ways to include ALLOW certificate. You should check with your IBV for detail.
2012年5月1日 星期二
Objective C 學習隨記(三)
Category (類目)
class 觀念的延伸, 對於一個class的methods, 你可以分成不同的category, 然後在不同的實作檔定義, 這對大型的專案共同開發同一個class很有用, 另一個好處是可以加入新的方法到一個class而不會影響修改到原有的定義
實作方法例如:
in 2dops.m
@interface GraphicObject (2Dops)
-(void)drawObject:(GraphicObject*) gb;
-(void)moveObject:(GraphicObject*) gb:(int) x:(int) y;
@end
in 3dops.m
@interface GraphicObject(3Dops)
-(void)rorateObject:(GraphicObject*) gb: (int) x-axis: (int) y-axis;
@end
另有無命名的category, 其實作必須要跟class 的實作在同一個實作檔案
Protocol(協定)
objC可以宣告介面, 宣告方式如下
@protocol ProtocolName
-(id) protocolmethods: (ParameterType) Para1;
@end
class如果要conform此protocol, 就要實作protocolmethod
在class宣告地方
@interface classname:NSObject <ProtocolName>
method 實作方法跟class method一樣
2012年4月25日 星期三
Objective C 學習隨記(二)
objC 跟C 雖然是很類似的程式語言, 但是用慣了C 寫一些firmware的人要轉學objC 還是有一些觀念要適應一下! 下面介紹的就是一個objC專有的語法, 如果能靈活運用, 將省去不少重複的程式
同名異式
動態型別
動態連結
其實這三個觀念都環繞著一個特殊的資料型態 "id"
最根本的原因是objC裡, object type並不是在compiling type決定,而是在runtime決定
一個以id 宣告為type的物件, 它的type內容是可變的
例如
id mathobj;
Fraction *aFrac = [Fraction alloc] init];
Complex *bComp = [[Complex alloc] init];
mathobj = aFrac;
[mathobj print];
mathobj = bComp;
[mathobj print];
因為有繼承這個objC主要功能的關係, 很多物件都相互有同名的method, 當然內容可能各不一樣, 就可以用id這種型態, 動態呼叫不同的物件同名method
這部分又衍生一些檢查的功能
例如檢查這個class 的selector (method) 是否存在
selector是以SEL為type的物件
運用方法如下例
SEL action;
id graphicobject
...
action = @selector(draw)
...
[graphicobject performSelector: action];
也就是說selector可以動態選擇要執行的method
Try & Catch 例外處理
objC的exception 處理方式:
把有可能發生exception的程式段以
@try{
...
}
包起來
後面在撰寫處理程序
@catch(NSException exception){
...
}
@finally 是不管有沒有丟出exception都會執行的程式區
@throw可以自己丟出exception
2012年4月22日 星期日
Objective C 學習隨記(一)
最近因為Iphone4s 很熱, 開始對這Apple劃時代的產品產生興趣, apple跳脫舊科技公司產品的思維, 賣的不只是冰冷的硬體, 他還創造了一個ecosystem方便軟體工程師可以很方便的從開發環境到測試最後到線上銷售, 一條龍不需要太大的進入門檻, 這無疑讓軟體設計師可以不需要自組一個公司處理銷售服務, 完全只需要發揮創意! 想想台灣雖然身為科技島, 但是全都偏向代工, 對於創新的產業著墨不深, 當apple 和 google相繼開發出軟體開發平台, 這無疑的對台灣產業轉型, 提供一個最佳的機會, 畢竟創意才是科技的根本
Ok 轉回主題, 不管是iphone還是ipad, 都是在apple公司開發的iOS上跑, 而iOS是從MacOSX 針對embedded device最佳化修改成的OS, 等同於Android是google基於linux 架構針對embedded device修改而成, 當然apple為了增加它應用程式(俗稱apps)的多樣性, 它徹底揚棄Microsoft對於開發人員設定的門檻, 這不得不說MS的失策, MS早在2000年初就進入smartphone的市場, 當時smartphone幾乎是MS獨佔, MS對每隻smartphone收的loyalty 超高, 加上MS對於Visual Studio收費真是高的嚇人, 所以會去開發它win ce apps的很少, 造成買了device卻沒甚麼apps可用的窘境, 一直到現在window mobile還在垂死掙扎, 就不多批評了.
不管iOS或Mac OSX應用程式都是用同一套開發工具,是免費的Xcode, 現在最新版本是4.0 , 使用的程式語言是objective C 這系列主要就是我讀一本書 "Programming in Objective-C" 4th edition的一些筆記
objective-C 應該說是C的進化物件導向版本, 觀念非常像C++ class inherit 的觀念
@property int a,b; //
@property代表 a跟b的 setter 和 getter由compiler自動產生, 要和implementation理加@synthesize a,b;
-(return type) methodname:(type)para1:(type)para2;
@end
@synthesize a,b;
-(type) methodname: (type)para1:(type)para2
{
//statements
}
@end
一般在實做class時要先allocate,再init 格式是
[[classname alloc] init] [classname alloc]會回傳一個class instance, 再呼叫class instance的init功能 也可以用 [classname new] 取代上述
Ok 轉回主題, 不管是iphone還是ipad, 都是在apple公司開發的iOS上跑, 而iOS是從MacOSX 針對embedded device最佳化修改成的OS, 等同於Android是google基於linux 架構針對embedded device修改而成, 當然apple為了增加它應用程式(俗稱apps)的多樣性, 它徹底揚棄Microsoft對於開發人員設定的門檻, 這不得不說MS的失策, MS早在2000年初就進入smartphone的市場, 當時smartphone幾乎是MS獨佔, MS對每隻smartphone收的loyalty 超高, 加上MS對於Visual Studio收費真是高的嚇人, 所以會去開發它win ce apps的很少, 造成買了device卻沒甚麼apps可用的窘境, 一直到現在window mobile還在垂死掙扎, 就不多批評了.
不管iOS或Mac OSX應用程式都是用同一套開發工具,是免費的Xcode, 現在最新版本是4.0 , 使用的程式語言是objective C 這系列主要就是我讀一本書 "Programming in Objective-C" 4th edition的一些筆記
objective-C 應該說是C的進化物件導向版本, 觀念非常像C++ class inherit 的觀念
class宣告
@interface Classname : NSobject //:NSObject 代表繼承於NSObject@property int a,b; //
@property代表 a跟b的 setter 和 getter由compiler自動產生, 要和implementation理加@synthesize a,b;
-(return type) methodname:(type)para1:(type)para2;
@end
class定義
@implementation Classname@synthesize a,b;
-(type) methodname: (type)para1:(type)para2
{
//statements
}
@end
一般在實做class時要先allocate,再init 格式是
[[classname alloc] init] [classname alloc]會回傳一個class instance, 再呼叫class instance的init功能 也可以用 [classname new] 取代上述
2012年3月5日 星期一
Blt function in GOP driver
Blt function is one of the three functions defined in UEFI GOP driver spec. And it is the only function that actually perform the draw operations. It has 4 operation modes.
- EfiBltVideoFill: Fill the rectangle of (DestinationX,DestinationY) to (DestinationX+Width,DestinationY+Height) wih BltBuffer pixel (0,0), only 1 pixel in BltBuffer is used.
- EfiBltVideoToBltBuffer: Read data from Video Buffer to BltBuffer (delta is used here)
- EfiBltBufferToVideo: Write data from BltBuffer to Video Buffer
- EfiBltVideoToVideo: Copy data from a rectangle in the VideoBuffer to another position in the VideoBuffer (BltBuffer and delta not used)
2012年2月13日 星期一
LTV > CPA ?
Mr.Jamie 提到的一個觀念 創業最重要的公式 LTV > CPA
提高LTV
降低CPA
LTV (life time value) 代表的是每一個customer 在你的服務期間的總和花費, 如果你提供的是一個有形的產品, 那期間就代表產品的生命週期, value就是產品的價格, 如果提供的是一種服務, 那期間就代表服務的期限, value就是服務的收費
CPA (cost per acquisition) 代表爭取到一個客戶所要的花費, 這不只是產品的生產成本, 還包括廣告行銷投入的成本與客戶回應比率
而在創業期間第一優先的目標就是 LTV > CPA , 達到這條件之後, 每多一個customer得到的profit才是正的, 爭取更多的客戶才有意義
提高LTV
降低CPA
LTV (life time value) 代表的是每一個customer 在你的服務期間的總和花費, 如果你提供的是一個有形的產品, 那期間就代表產品的生命週期, value就是產品的價格, 如果提供的是一種服務, 那期間就代表服務的期限, value就是服務的收費
CPA (cost per acquisition) 代表爭取到一個客戶所要的花費, 這不只是產品的生產成本, 還包括廣告行銷投入的成本與客戶回應比率
而在創業期間第一優先的目標就是 LTV > CPA , 達到這條件之後, 每多一個customer得到的profit才是正的, 爭取更多的客戶才有意義
2012年2月10日 星期五
EFI GOP Driver
GOP (Graphic Output Protocol) driver 是 EFI架構下取代傳統VBIOS 黑箱的 EFI Driver, 另外for embedded system bootloader 上的graphic driver叫EPOG(embedded Pre-OS Graphic).
Protocol 主要包含3個function 及 1個data structure
GOP Driver 的共有GUID
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
{0x9042a9de,0x23dc,0x4a38, \
0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a}
typedef struct EFI_GRAPHICS_OUTPUT_PROTCOL {
EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
} EFI_GRAPHICS_OUTPUT_PROTOCOL;
- QueryMode: Returns information for an available graphics mode that the graphics device and the set of active video output devices supports.(是詢問graphic controller 和 系統所有接上的顯示器所支援的顯示模式)
- SetMode:Set the video device into the specified mode and clears the visible portions of the output display to black. 則是設定顯示裝置一個特定的顯示模式
- Blt:Software abstraction to draw on the video device’s frame buffer.則是直接透過寫入framebuffer 畫矩形圖片
取材UEFI spec 2.3 chap. 11.9
訂閱:
文章 (Atom)