星期五, 12月 25, 2015
星期三, 12月 16, 2015
word vba
Sub ListUsedBookmark()
'
' ListNotUsedBookmark 巨集
'
'
Dim oField As Field
Dim sCode As String
Dim bFoundOne As String
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldSequence Then
sCode = oField.Code
' If InStr(sCode, "ref") <> 0 Then
' If oField.Result.Text = "57" Then
' Debug.Print oField.Result.Text
' End If
' End If
End If
'找出有cite到的reference
If oField.Type = wdFieldRef Then
sCode = oField.Code
If InStr(sCode, "REF") <> 0 Then
Debug.Print oField.Result.Text
End If
End If
Next
End Sub
'
' ListNotUsedBookmark 巨集
'
'
Dim oField As Field
Dim sCode As String
Dim bFoundOne As String
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldSequence Then
sCode = oField.Code
' If InStr(sCode, "ref") <> 0 Then
' If oField.Result.Text = "57" Then
' Debug.Print oField.Result.Text
' End If
' End If
End If
'找出有cite到的reference
If oField.Type = wdFieldRef Then
sCode = oField.Code
If InStr(sCode, "REF") <> 0 Then
Debug.Print oField.Result.Text
End If
End If
Next
End Sub
星期六, 11月 28, 2015
星期二, 10月 20, 2015
Django 設定建議
Django 設定好文章
reference:
http://www.revsys.com/blog/2014/nov/21/recommended-django-project-layout/
https://docs.djangoproject.com/en/1.8/intro/reusable-apps/
在Django中,樣板templates目錄及statics目錄可以有很多種設定方法:
Project based: 在setting.py中,設定
#設定靜態檔案的系統根目錄
STATIC_ROOT = os.path.join(BASE_DIR, '/static_root')
STATIC_URL = '/static/'
*其中STATIC_URL是當Server看到/static/目錄的request, 則Server會到STATIC_ROOT下映射去找資料,如果找不到,則會到每個 App目錄下去找static子目錄查詢內容。
*在template中的用法 (helpers function)
static: To link to static files that are saved in STATIC_ROOT Django ships with a static template tag.
#設定樣版檔案的系統目錄
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
*當Python看到/template/目錄的request, 則Server會到TEMPLATE_DIRS 下映射去找資料,如果找不到,則會到每個 App目錄下去找/templates/子目錄查詢內容。
*在每個app的/template/目前下,建議再建立app名字同名子目錄,方便render函式辨視及搜尋不同app的樣版檔案。例如render(polls/index.html),則系統會依路徑去找,所以會依下列方式 去找
mysite/templates/polls/index.html ,如果找不到,就會找
mysite/polls/templates/polls/index.html
#設定上傳檔案的系統根目錄
MEDIA_ROOT = os.path.join(BASE_DIR, '/upload_root')
MEDIA_URL = '/upload/'
*在FileField的upload_to會把檔案存在MEDIA_ROOT指定的路徑中。
*在template中的用法 (helpers function)
get_media_prefix: Similar to the get_static_prefix, get_media_prefix populates a template variable with the media prefix MEDIA_URL, e.g.:
{% load static %}
data-media-url="{% get_media_prefix %}">
#設定每個APP urls 路由方式
reference:
http://www.revsys.com/blog/2014/nov/21/recommended-django-project-layout/
https://docs.djangoproject.com/en/1.8/intro/reusable-apps/
在Django中,樣板templates目錄及statics目錄可以有很多種設定方法:
Project based: 在setting.py中,設定
#設定靜態檔案的系統根目錄
STATIC_ROOT = os.path.join(BASE_DIR, '/static_root')
STATIC_URL = '/static/'
*其中STATIC_URL是當Server看到/static/目錄的request, 則Server會到STATIC_ROOT下映射去找資料,如果找不到,則會到每個 App目錄下去找static子目錄查詢內容。
*在template中的用法 (helpers function)
static: To link to static files that are saved in STATIC_ROOT Django ships with a static template tag.
{% load static % }
src="{% static "images/hi.jpg" %}"
#設定樣版檔案的系統目錄
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
Deprecated since version 1.8: Set the DIRS option of a DjangoTemplates backend instead. 1.8版要改設一定為DIRS
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
join(BASE_DIR, 'templates'),
],....}
*當Python看到/template/目錄的request, 則Server會到TEMPLATE_DIRS 下映射去找資料,如果找不到,則會到每個 App目錄下去找/templates/子目錄查詢內容。
*在每個app的/template/目前下,建議再建立app名字同名子目錄,方便render函式辨視及搜尋不同app的樣版檔案。例如render(polls/index.html),則系統會依路徑去找,所以會依下列方式 去找
mysite/templates/polls/index.html ,如果找不到,就會找
mysite/polls/templates/polls/index.html
#設定上傳檔案的系統根目錄
MEDIA_ROOT = os.path.join(BASE_DIR, '/upload_root')
MEDIA_URL = '/upload/'
*在FileField的upload_to會把檔案存在MEDIA_ROOT指定的路徑中。
*在template中的用法 (helpers function)
get_media_prefix: Similar to the get_static_prefix, get_media_prefix populates a template variable with the media prefix MEDIA_URL, e.g.:
{% load static %}
data-media-url="{% get_media_prefix %}">
#設定每個APP urls 路由方式
polls/ __init__.py admin.py models.py tests.py urls.py views.py
mysite/urls.py其中^polls/結尾不能有$字號, Django 會移除己配對的字串,再把後續字串送到app目錄下的urls模組處理。from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^polls/', include('polls.urls')), url(r'^admin/', include(admin.site.urls)), ]
polls/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
星期五, 7月 31, 2015
ios auto layout and size class
nice reference:
Size Classes 解決各種螢幕大小的問題
- h: any, w:any是大家共的的layout, 放在這上面的控制項,每個iphone 解析度都看的到
- h: regular, w:compact是直式螢幕,放在這上面的控制項,只有直式iphone 解析度看的到
Constraints 限制則是用來定位控制項大小及位置的方式
IOS8 Constraints and Size Classes
星期五, 7月 10, 2015
Python Flask Quick Guide
Django 功能強,但是不易學習,在設定上比較麻煩,Flask比較容易上手,可以快速架出restful 服務
Videos:
https://www.jetbrains.com/pycharm/documentation/
使用rest api及angular js的好影片
PyCharm Web Magic: Building a Pinterest Clone
Deploying Flask on Google App Engine
使用template方式架的影片
PyCharm - Flask Tutorial
Flask Authentication
http://blog.miguelgrinberg.com/post/restful-authentication-with-flask
Videos:
https://www.jetbrains.com/pycharm/documentation/
使用rest api及angular js的好影片
PyCharm Web Magic: Building a Pinterest Clone
Deploying Flask on Google App Engine
使用template方式架的影片
PyCharm - Flask Tutorial
Flask Authentication
http://blog.miguelgrinberg.com/post/restful-authentication-with-flask
星期六, 6月 27, 2015
Video Streaming Server, MP4, moov, and pseudo streaming
MP4 預設格式不適合seek in tcp streaming, 把moov atom移到MP4檔頭前,就可以加強seek功能
Streaming a video file to an html5 video player with Node.js so that the video controls continue to work?
http://stackoverflow.com/questions/24976123/streaming-a-video-file-to-an-html5-video-player-with-node-js-so-that-the-video-c
Seeking videos beyond the buffer line
http://1stdev.com/tremendum-transcoder/articles/seeking-videos-beyond-the-buffer-line/
HTTP Streaming 相關技術 pseudo, live
http://virdust.blogspot.tw/2011/11/http-streaming-pseudo-live.html
Streaming a video file to an html5 video player with Node.js so that the video controls continue to work?
http://stackoverflow.com/questions/24976123/streaming-a-video-file-to-an-html5-video-player-with-node-js-so-that-the-video-c
Seeking videos beyond the buffer line
http://1stdev.com/tremendum-transcoder/articles/seeking-videos-beyond-the-buffer-line/
HTTP Streaming 相關技術 pseudo, live
http://virdust.blogspot.tw/2011/11/http-streaming-pseudo-live.html
星期二, 6月 23, 2015
Django REST API and OAuth Good Reference, plus android client
A type-safe REST client for Android and Java
http://square.github.io/retrofit/
How to make a full fledged REST API with Django OAuth Toolkit
https://ep2014.europython.eu/en/schedule/sessions/81/
https://youtu.be/M6Ud3qC2tTk
星期日, 6月 21, 2015
Django Class Base View Examples
https://docs.djangoproject.com/en/1.8/ref/class-based-views/
Reference:
好投影片
Django class-based views: survival guide for novices
http://www.slideshare.net/giordanileonardo/django-cb-vssurvivalguidefornovicesv2
Best Practices for Class-Based Views
http://www.slideshare.net/starwilly/two-scoopsofdjangocbv
好範例,很小很容易理解
Django 1.8 Tutorial - 1. A Minimal Application Made Using Generic Class Based Views
http://riceball.com/d/content/django-18-minimal-application-using-generic-class-based-views
Notes:
練習中少了一些命令
settings.py -->'comment'
python manage.py makemigration
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Pycharm note:
把專案根目錄Make Directory as sources root 可以避免urls.py找不到相對import 檔提示問題
https://www.jetbrains.com/pycharm/help/configuring-folders-within-a-content-root.html
Getting started with Generic Class Based Views in Django
http://www.onespacemedia.com/news/2014/feb/5/getting-started-generic-class-based-views-django/
Generic
display views
|
Model Name as suffix name, e.g.,
author_xxx.html
|
DetailView
|
_detail.html
|
ListView
|
_list.html
|
|
|
Generic
editing views
|
|
FormView
|
|
CreateView
|
_form.html
|
UpdateView
|
_form.html
|
DeleteView
|
_confirm_delete.html
|
|
|
Reference:
好投影片
Django class-based views: survival guide for novices
http://www.slideshare.net/giordanileonardo/django-cb-vssurvivalguidefornovicesv2
Best Practices for Class-Based Views
http://www.slideshare.net/starwilly/two-scoopsofdjangocbv
好範例,很小很容易理解
Django 1.8 Tutorial - 1. A Minimal Application Made Using Generic Class Based Views
http://riceball.com/d/content/django-18-minimal-application-using-generic-class-based-views
Notes:
練習中少了一些命令
settings.py -->'comment'
python manage.py makemigration
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Pycharm note:
把專案根目錄Make Directory as sources root 可以避免urls.py找不到相對import 檔提示問題
https://www.jetbrains.com/pycharm/help/configuring-folders-within-a-content-root.html
Getting started with Generic Class Based Views in Django
http://www.onespacemedia.com/news/2014/feb/5/getting-started-generic-class-based-views-django/
Django 中文習學資源
Django筆記
5 Stars, 描述很完整,技術細節說明很清楚的學習資源
http://dokelung-blog.logdown.com/posts/235592-django-notes-table-of-contents
星期五, 6月 19, 2015
Django Static Html Processing and Data Model Migration
Good Explain:
Django对静态文件的处理——部署阶段
http://blog.makto.me/post/2012-11-09/static-files-in-django-deployment
Django对静态文件的处理——开发阶段
http://blog.makto.me/post/2012-11-10/static-files-in-django-development
Django筆記(5) - 模型與資料庫
http://dokelung-blog.logdown.com/posts/220606-django-notes-5-model-and-database
Django对静态文件的处理——部署阶段
http://blog.makto.me/post/2012-11-09/static-files-in-django-deployment
Django对静态文件的处理——开发阶段
http://blog.makto.me/post/2012-11-10/static-files-in-django-development
Django筆記(5) - 模型與資料庫
http://dokelung-blog.logdown.com/posts/220606-django-notes-5-model-and-database
星期六, 6月 06, 2015
Omnet++ INET UDPBasicApp生命週期觀察
Summary:
1. UDPBasicApp::initialize(int stage)
2. if (stage == INITSTAGE_LOCAL) {
selfMsg = new cMessage("sendTimer");
2.1 selfMsg變數表「排程狀態」,用來當事件參數 OperationalBase::handleMessage(cMessage *message),做狀態機,控制用。
3. stage ++
4. 直到stage=12, i.e, isInitializeStage(stage)==true, 執行 handleNodeStart(nullptr);
5. handleNodeStart, 排程
selfMsg->setKind(START);
scheduleAt(start, selfMsg);
以上是戴入omnet.ini就會執行的code
6. 至於真正的封包排程, schedule要等到按run才會執行, 此時 if (isOperational)為真
7. 事件發生,執行handleMessage, 會再呼叫 handleMessageWhenUp(message);
8. 會再呼叫processStart(), 正式app的啟動,
case START:
processStart();
break;
9. processStart()呼叫 processSend();
10. processSend()依設定的sendInterval參數, 送出封包後,再排程下次傳送時間點
11. 重覆7-11, 執行
case SEND:
processSend();
-----------------------------------------------------------------
Details:
omnet++載入時omnet.ini會執行
0. stage=0, i.e, INITSTAGE_LOCAL
1. 一開始初始化階段,執行程式碼
ApplicationBase::initialize(stage);
if (stage == INITSTAGE_LOCAL) {
EV_INFO << "hsuth: INITSTAGE_LOCAL"<< endl;
程式碼,進行初始化。
}
2. 每次跑完stage++
3. 在stage=12時, isInitializeStage(stage)會傳回 true, 此時會跑 handleNodeStart(nullptr);
void OperationalBase::initialize(int stage)
{
if (isInitializeStage(stage)) {
NodeStatus *nodeStatus = dynamic_cast(findContainingNode(this)->getSubmodule("status"));
setOperational(!nodeStatus || nodeStatus->getState() == NodeStatus::UP);
if (isOperational) {
EV_INFO << "hsuth: OperationalBase::handleNodeStart"<< endl;
handleNodeStart(nullptr);
}
}
}
會呼叫
bool UDPBasicApp::handleNodeStart(IDoneCallback *doneCallback)
{
EV_INFO << "hsuth: UDPBasicApp::handleNodeStart"<< endl;
simtime_t start = std::max(startTime, simTime());
if ((stopTime < SIMTIME_ZERO) || (start < stopTime) || (start == stopTime && startTime == stopTime)) {
selfMsg->setKind(START);
scheduleAt(start, selfMsg);
}
return true;
}
當按run時,才會跑排程
排程,時間到呼叫handleMessage, 在
void OperationalBase::handleMessage(cMessage *message)
{
if (isOperational)
handleMessageWhenUp(message);
else
handleMessageWhenDown(message);
}
會呼叫 UDPBasicApp::handleMessageWhenUp
接著會跑到
void UDPBasicApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage()) {
ASSERT(msg == selfMsg);
switch (selfMsg->getKind()) {
case START:
processStart();
break;
if (!destAddresses.empty()) {
selfMsg->setKind(SEND);
processSend();
}
}
執行
void UDPBasicApp::processSend()
{
sendPacket();
simtime_t d = simTime() + par("sendInterval").doubleValue();
if (stopTime < SIMTIME_ZERO || d < stopTime) {
selfMsg->setKind(SEND);
scheduleAt(d, selfMsg);
}
else {
selfMsg->setKind(STOP);
scheduleAt(stopTime, selfMsg);
}
}
重覆
void UDPBasicApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage()) {
ASSERT(msg == selfMsg);
switch (selfMsg->getKind()) {
case START:
processStart();
break;
case SEND:
processSend();
break;
1. UDPBasicApp::initialize(int stage)
2. if (stage == INITSTAGE_LOCAL) {
selfMsg = new cMessage("sendTimer");
2.1 selfMsg變數表「排程狀態」,用來當事件參數 OperationalBase::handleMessage(cMessage *message),做狀態機,控制用。
3. stage ++
4. 直到stage=12, i.e, isInitializeStage(stage)==true, 執行 handleNodeStart(nullptr);
5. handleNodeStart, 排程
selfMsg->setKind(START);
scheduleAt(start, selfMsg);
以上是戴入omnet.ini就會執行的code
6. 至於真正的封包排程, schedule要等到按run才會執行, 此時 if (isOperational)為真
7. 事件發生,執行handleMessage, 會再呼叫 handleMessageWhenUp(message);
8. 會再呼叫processStart(), 正式app的啟動,
case START:
processStart();
break;
9. processStart()呼叫 processSend();
10. processSend()依設定的sendInterval參數, 送出封包後,再排程下次傳送時間點
11. 重覆7-11, 執行
case SEND:
processSend();
break;
-----------------------------------------------------------------
Details:
omnet++載入時omnet.ini會執行
0. stage=0, i.e, INITSTAGE_LOCAL
1. 一開始初始化階段,執行程式碼
ApplicationBase::initialize(stage);
if (stage == INITSTAGE_LOCAL) {
EV_INFO << "hsuth: INITSTAGE_LOCAL"<< endl;
程式碼,進行初始化。
}
2. 每次跑完stage++
3. 在stage=12時, isInitializeStage(stage)會傳回 true, 此時會跑 handleNodeStart(nullptr);
{
if (isInitializeStage(stage)) {
NodeStatus *nodeStatus = dynamic_cast
setOperational(!nodeStatus || nodeStatus->getState() == NodeStatus::UP);
if (isOperational) {
EV_INFO << "hsuth: OperationalBase::handleNodeStart"<< endl;
handleNodeStart(nullptr);
}
}
}
會呼叫
bool UDPBasicApp::handleNodeStart(IDoneCallback *doneCallback)
{
EV_INFO << "hsuth: UDPBasicApp::handleNodeStart"<< endl;
simtime_t start = std::max(startTime, simTime());
if ((stopTime < SIMTIME_ZERO) || (start < stopTime) || (start == stopTime && startTime == stopTime)) {
selfMsg->setKind(START);
scheduleAt(start, selfMsg);
}
return true;
}
當按run時,才會跑排程
排程,時間到呼叫handleMessage, 在
void OperationalBase::handleMessage(cMessage *message)
{
if (isOperational)
handleMessageWhenUp(message);
else
handleMessageWhenDown(message);
}
會呼叫 UDPBasicApp::handleMessageWhenUp
接著會跑到
void UDPBasicApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage()) {
ASSERT(msg == selfMsg);
switch (selfMsg->getKind()) {
case START:
processStart();
break;
執行
void UDPBasicApp::processStart()
{
if (!destAddresses.empty()) {
selfMsg->setKind(SEND);
processSend();
}
}
執行
void UDPBasicApp::processSend()
{
sendPacket();
simtime_t d = simTime() + par("sendInterval").doubleValue();
if (stopTime < SIMTIME_ZERO || d < stopTime) {
selfMsg->setKind(SEND);
scheduleAt(d, selfMsg);
}
else {
selfMsg->setKind(STOP);
scheduleAt(stopTime, selfMsg);
}
}
重覆
void UDPBasicApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage()) {
ASSERT(msg == selfMsg);
switch (selfMsg->getKind()) {
case START:
processStart();
break;
case SEND:
processSend();
break;
取得sendInterval,一直重覆,直到simulation end
void UDPBasicApp::processSend()
{
sendPacket();
simtime_t d = simTime() + par("sendInterval").doubleValue();
if (stopTime < SIMTIME_ZERO || d < stopTime) {
selfMsg->setKind(SEND);
scheduleAt(d, selfMsg);
}
else {
selfMsg->setKind(STOP);
scheduleAt(stopTime, selfMsg);
}
}
星期日, 5月 31, 2015
AngularJS Free Course
Reference:
Code School: Shaping up with angular.js
http://campus.codeschool.com/courses/shaping-up-with-angular-js/intro
Code School: Shaping up with angular.js
http://campus.codeschool.com/courses/shaping-up-with-angular-js/intro
星期五, 5月 15, 2015
mac os 10.10.3 mail.app typing lag issue
Fix:
1. Open a message-editing window. Under the Edit menu, deselect all the options in the Spelling and Substitutions sub-menus. Test.
2. Many problems with Mail are caused by iCloud Drive. If you use the service, open the iCloud preference pane, click Options... next to the iCloud Drive box, and in the sheet that opens, uncheck the box marked Mail. See whether there's an improvement.
System wide: Go to System Preferences > Extensions > Actions and untick the "Markup" box
Mail only: Customize the new-message toolbar (open a new message, right-click/control-click on the tool bar, select "Customize Toolbar" and add or subtract something - especially the "Markup" icon, but changing anything may work)
星期五, 4月 24, 2015
如何在Windows下安裝SciPy, matplotlib
在Windows下安裝SciPy, matplotlib 實在是很麻煩的事,上網查了一下,決定試用
http://conda.pydata.org/miniconda.html
Miniconda是Anaconda下的工具,Anaconda把很多在Windows需要編譯的package都編好了,直接安裝就可以,可以省很多事....相較之前的痛苦,一整個輕鬆愉快
把舊的python砍掉重練. 下戴miniconda後重新安裝....
安裝packeage方式如下:
也可以產生像virtualenv的虛擬環境,解決dependency的問題
參閱https://gist.github.com/ccwang002/449159cc2a05b1011467
在pycharm重設 interpter的路徑就好了:
http://unlikenoise.com/setup-pycharm-anaconda-python-windows/
http://conda.pydata.org/miniconda.html
Miniconda是Anaconda下的工具,Anaconda把很多在Windows需要編譯的package都編好了,直接安裝就可以,可以省很多事....相較之前的痛苦,一整個輕鬆愉快
把舊的python砍掉重練. 下戴miniconda後重新安裝....
安裝packeage方式如下:
$ conda install numpy
也可以產生像virtualenv的虛擬環境,解決dependency的問題
參閱https://gist.github.com/ccwang002/449159cc2a05b1011467
> conda create -n ngs python=2.7 pip
使用它很簡單就
activate ngs
、deactivate
, 細節可以看 conda 的說明文件。總之在這邊> activate ngs
Activating environment ngs ...
[ngs]> conda install numpy scipy
...
Proceed ([y]/n)?
在pycharm重設 interpter的路徑就好了:
http://unlikenoise.com/setup-pycharm-anaconda-python-windows/
Acer S7 鍵盤問題Solution
2015/5/13更新:
下戴zerofix後執行,此法更方便,不用設定半天....
https://dl.dropbox.com/u/26748522/zechofix.html
Reference:
http://community.acer.com/t5/Ultra-Thin/Acer-s7-keyboard-issue-with-repeating-characters/td-p/24407
Acer S7 的鍵盤常常會重覆前一個字元,例如: talkk, yearr...造成輸入文字時嚴重的問題。
上網查了一下,很多外國人都有反應這個問題,目前解法是:
下戴zerofix後執行,此法更方便,不用設定半天....
https://dl.dropbox.com/u/26748522/zechofix.html
Reference:
http://community.acer.com/t5/Ultra-Thin/Acer-s7-keyboard-issue-with-repeating-characters/td-p/24407
Acer S7 的鍵盤常常會重覆前一個字元,例如: talkk, yearr...造成輸入文字時嚴重的問題。
上網查了一下,很多外國人都有反應這個問題,目前解法是:
基本上可以解決問題,缺點是按刪除鍵時不能一直壓著連續刪除,要改變使用習慣。
星期一, 4月 20, 2015
安裝Windows 版NumPy及SciPy
NumPy及SciPy在windows 安裝,都會有compile errors...
http://www.scipy.org/scipylib/download.html
要安裝的話,建議到sourceforge安裝預先compile的all-in-one版。
http://sourceforge.net/projects/numpy/files/
http://sourceforge.net/projects/scipy/files/
http://www.scipy.org/scipylib/download.html
要安裝的話,建議到sourceforge安裝預先compile的all-in-one版。
http://sourceforge.net/projects/numpy/files/
http://sourceforge.net/projects/scipy/files/
後記補充,由於這種方式安裝matplot等套件不方便,建議改用miniconda....
Python Text Classification using Naive Bayes and scikit-learn
Feature extraction (特徵擷取) [5]
CountVectorizer implements both tokenization (英文分詞) and occurrence counting(計算英文文字出現計數) in a single class:
>>>
>>> from sklearn.feature_extraction.text import CountVectorizer
This model has many parameters, however the default values are quite reasonable (please see the reference documentation for the details):
>>>
>>> vectorizer = CountVectorizer(min_df=1) >>> vectorizer CountVectorizer(analyzer=...'word', binary=False, decode_error=...'strict', dtype=<... 'numpy.int64'>, encoding=...'utf-8', input=...'content', lowercase=True, max_df=1.0, max_features=None, min_df=1, ngram_range=(1, 1), preprocessor=None, stop_words=None, strip_accents=None, token_pattern=...'(?u)\\b\\w\\w+\\b', tokenizer=None, vocabulary=None)
Let’s use it to tokenize and count the word occurrences of a minimalistic corpus of text documents:
說明:
fit函式代表tokenize,加入到字典陣列vocabulary
fit(raw_documents[, y]) | Learn a vocabulary dictionary of all tokens in the raw documents. |
transform(raw_documents) | Transform documents to document-term matrix. |
fit_transform(raw_documents[, y]) | Learn the vocabulary dictionary and return term-document matrix. |
>>>
>>> corpus = [ ... 'This is the first document.', ... 'This is the second second document.', ... 'And the third one.', ... 'Is this the first document?', ... ] >>> X = vectorizer.fit_transform(corpus) >>> X <4x9 matrix="" numpy.int64="" of="" sparse="" type="">'4x9> with 19 stored elements in Compressed Sparse ... format>
The default configuration tokenizes the string by extracting words of at least 2 letters. Each term found by the analyzer during the fit is assigned a unique integer index corresponding to a column in the resulting matrix. This interpretation of the columns can be retrieved as follows:
>>>
>>> vectorizer.get_feature_names() == ( ... ['and', 'document', 'first', 'is', 'one', ... 'second', 'the', 'third', 'this']) True >>> X.toarray() array([[0, 1, 1, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 2, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0], [0, 1, 1, 1, 0, 0, 1, 0, 1]]...)
說明:
經過特徵擷取後,可以利用get_feature_names()取得特徵索引字串字典,接著對映到結果計數陣列。
呼叫X.toarray()可以看出,每個文件,例[0, 1, 1, 1, 0, 0, 1, 0, 1]所對映到的英文字計數....
'This is the first document.' ->['and', 'document', 'first', 'is', 'one','second', 'the', 'third', 'this']
get_feature_names() | Array mapping from feature integer indices to feature name |
References:
1. Machine Learning Tutorial: The Naive Bayes Text Classifier
2. Naive Bayes
3. Working With Text Data — scikit-learn 0.16.1 documentation
4. Text Classification
5. Feature extraction
Videos:
高一下數學3-0引言01什麼是機率
高一下數學3-3A觀念01條件機率的概念
星期四, 4月 16, 2015
node js tcp socekt end and close different
Good Reference: http://maxogden.com/node-streams.html
end(): Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data. only closes the writing stream of the socket, the remote host can keep his writing stream open and send you data.
end(): Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data. only closes the writing stream of the socket, the remote host can keep his writing stream open and send you data.
destroy(): Ensures that no more I/O activity happens on this socket. Only necessary in case of errors (parse error or so).
Event: 'end'#
Emitted when the other end of the socket sends a FIN packet.
By default (allowHalfOpen == false) the socket will destroy its file descriptor once it has written out its pending write queue. However, by setting allowHalfOpen == true the socket will not automatically end() its side allowing the user to write arbitrary amounts of data, with the caveat that the user is required to end() their side now.
Event: 'error'#
Error object
Emitted when an error occurs. The 'close' event will be called directly following this event.
Event: 'close'#
had_error Boolean true if the socket had a transmission error
Emitted once the socket is fully closed. The argument had_error is a boolean which says if the socket was closed due to a transmission error.
星期日, 3月 15, 2015
Uniform Server, Ripple Chrome Extension, Nodejs, ExpressJS, Swig, D3JS, RickShaw.js, Socket.io
http://www.uniformserver.com/
Ripple Chrome Extension
可以模擬各種行動裝置大小,方便做行動網頁設計。
Node Swig 樣版
http://paularmstrong.github.io/swig/
採用跟 python django同樣的模版語言,容易維護。
MangoDB
儲存資料
d3.js
Express JS
rickshaw.js
http://code.shutterstock.com/rickshaw/
利用d3來做各種線圖。
Socket.io
利用websocket來做browser即時通訊
Node Swig 樣版
http://paularmstrong.github.io/swig/
採用跟 python django同樣的模版語言,容易維護。
MangoDB
儲存資料
d3.js
Express JS
rickshaw.js
http://code.shutterstock.com/rickshaw/
利用d3來做各種線圖。
Socket.io
利用websocket來做browser即時通訊
Windows Terminal, Command Line Shell Suggestion
ConEmu is opensource console emulator with tabs, which represents multiple consoles and simple GUI applications as one customizable GUI window.
推薦,中文輸入記得進入Setting中,把monospace選項取消,中文字就可以正常移動。
推薦,中文輸入記得進入Setting中,把monospace選項取消,中文字就可以正常移動。
星期一, 3月 09, 2015
apache2.conf vs site-avaliable virtualhost configuration 設定
Reference:
http://stackoverflow.com/questions/22579159/apache2-conf-vs-site-avaliable-virtualhost-configuration
結論: site-available 裡的設定最後還是會被merge到apache2.conf。二種方式是一樣的,只是 site-available的方式比較方便管理多個網站。
http://stackoverflow.com/questions/22579159/apache2-conf-vs-site-avaliable-virtualhost-configuration
結論: site-available 裡的設定最後還是會被merge到apache2.conf。二種方式是一樣的,只是 site-available的方式比較方便管理多個網站。
星期二, 3月 03, 2015
Express Node JS D3
Node.js TCP 資料處理
Issues when reading a string from TCP socket in Node.js
http://stackoverflow.com/questions/12872563/issues-when-reading-a-string-from-tcp-socket-in-node-js
用 Express 和 MongoDB 寫一個 todo list
http://dreamerslab.com/blog/tw/write-a-todo-list-with-express-and-mongodb/
Visualising a real-time DataSift feed with Node and D3.js
http://www.benh.co.uk/datasift/visualising-a-datasift-feed-with-node-and-d3/
Rickshaw Examples畫時間圖好script
http://code.shutterstock.com/rickshaw/examples/
Best Practices for Node.js Development
https://devcenter.heroku.com/articles/node-best-practices#keep-track-of-outdated-dependencies
Issues when reading a string from TCP socket in Node.js
http://stackoverflow.com/questions/12872563/issues-when-reading-a-string-from-tcp-socket-in-node-js
用 Express 和 MongoDB 寫一個 todo list
http://dreamerslab.com/blog/tw/write-a-todo-list-with-express-and-mongodb/
Visualising a real-time DataSift feed with Node and D3.js
http://www.benh.co.uk/datasift/visualising-a-datasift-feed-with-node-and-d3/
Rickshaw Examples畫時間圖好script
http://code.shutterstock.com/rickshaw/examples/
Best Practices for Node.js Development
https://devcenter.heroku.com/articles/node-best-practices#keep-track-of-outdated-dependencies
星期日, 3月 01, 2015
Android IAP 相關文章
Reference:
Common Errors in Google In-App Billing
http://ascii-iicsa.blogspot.tw/2014/08/common-errors-in-google-in-app-billing.html
[Android] In-App Billing Version 3 筆記
http://wisdomskyduan.blogspot.tw/2014/09/android-in-app-billing-version-3.html
Android In-app billing (IAB) version 3
http://blog.kenyang.net/2014/10/android-in-app-billing-iab-version-3.html
Common Errors in Google In-App Billing
http://ascii-iicsa.blogspot.tw/2014/08/common-errors-in-google-in-app-billing.html
[Android] In-App Billing Version 3 筆記
http://wisdomskyduan.blogspot.tw/2014/09/android-in-app-billing-version-3.html
Android In-app billing (IAB) version 3
http://blog.kenyang.net/2014/10/android-in-app-billing-iab-version-3.html
星期六, 2月 28, 2015
su, sudo,sudo su
su
登入為root,需要輸入root的密碼,比較不安全。(fedora及大部份的distribution,建立系統時會建立root帳號及密碼)
sudo command
短暫取得root權限,執行後面指定的command命令。需要輸入自已己帳號的密碼,而不是root帳號的密碼。只有加入到sudoer檔案的帳號才可以執行sudo命令。優點,安全性較高,可避免登入到root帳號後,不小心下錯指令,導致大範圍失誤。( 在ubuntu系統中,預設不會建立root密碼啟用root登入功能。當需要執行root權限所需的命令時,都採用sudo command的方式來做。)
sudo su
同su功能,切換為root。即請sudo執行su命令,所不同的是輸入自己帳號密碼,而不是root密碼。原理當使用者輸入自己密碼後即取得root權限,此時再執行su,等同執行su root,就會切換成root身份。
為什麼要多此一舉? 因為在ubuntu系統中,預設不會建立root密碼啟用root登入功能。當需要執行root權限所需的命令時,都採用sudo command的方式來做。有時候要執行很多系統命令時,可以採用sudo su方式,切換到root身份後再下指令會比較方便。
WireShark 封包抓取學習好文章
Good Reference:
一站式学习Wireshark(一):Wireshark基本用法
https://community.emc.com/thread/194901
十大免费又好用的网络分析工具
https://community.emc.com/message/788944#788944
一站式学习Wireshark(一):Wireshark基本用法
https://community.emc.com/thread/194901
十大免费又好用的网络分析工具
https://community.emc.com/message/788944#788944
apache 權限設定好文章
Reference:
What permissions should my website files/folders have on a Linux webserver?
http://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver
What permissions should my website files/folders have on a Linux webserver?
http://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver
星期三, 2月 25, 2015
iOS, Android, phonegap Push Notification
Good Reference:
iOS APNS 訊息推播 - Apple Push Notification Service 介紹
http://blog.toright.com/posts/2806/ios-apns-%E8%A8%8A%E6%81%AF%E6%8E%A8%E6%92%A5-apple-push-notification-service-%E4%BB%8B%E7%B4%B9.html
如何透過 PHP 發送 Apple Notification Push
http://blog.toright.com/posts/2846/%E5%A6%82%E4%BD%95%E9%80%8F%E9%81%8E-php-%E7%99%BC%E9%80%81-apple-notification-push.html
Android Push Notification推播通知訊息給Android客戶端
http://magiclen.org/android-push-notification/
Android GCM (Google Cloud Messaging):Server Side
http://blog.kenyang.net/2013/07/android-gcm-google-cloud.html
Android GCM (Google Cloud Messaging):Android Client Side
http://blog.kenyang.net/2013/07/android-gcm-google-cloud_1.html
iOS APNS 訊息推播 - Apple Push Notification Service 介紹
http://blog.toright.com/posts/2806/ios-apns-%E8%A8%8A%E6%81%AF%E6%8E%A8%E6%92%A5-apple-push-notification-service-%E4%BB%8B%E7%B4%B9.html
如何透過 PHP 發送 Apple Notification Push
http://blog.toright.com/posts/2846/%E5%A6%82%E4%BD%95%E9%80%8F%E9%81%8E-php-%E7%99%BC%E9%80%81-apple-notification-push.html
Android Push Notification推播通知訊息給Android客戶端
http://magiclen.org/android-push-notification/
Android GCM (Google Cloud Messaging):Server Side
http://blog.kenyang.net/2013/07/android-gcm-google-cloud.html
Android GCM (Google Cloud Messaging):Android Client Side
http://blog.kenyang.net/2013/07/android-gcm-google-cloud_1.html
Django and Facebook API
Good Reference:
Signing Up and Signing In: Users in Django with Django-AllAuth
https://speakerdeck.com/tedtieken/signing-up-and-signing-in-users-in-django-with-django-allauth
使用allauth套件對新手最方便
DjangoCon 2013 - Rapid prototyping and communicating with clients
http://www.slideshare.net/katychuang/kat-rapid-prototyping
django網站規劃好文章
Signing Up and Signing In: Users in Django with Django-AllAuth
https://speakerdeck.com/tedtieken/signing-up-and-signing-in-users-in-django-with-django-allauth
使用allauth套件對新手最方便
DjangoCon 2013 - Rapid prototyping and communicating with clients
http://www.slideshare.net/katychuang/kat-rapid-prototyping
django網站規劃好文章
星期一, 2月 23, 2015
星期二, 2月 17, 2015
Android Custom View
Good Reference:
http://blog.csdn.net/lmj623565791/article/details/24252901
comments:
1. 定義屬性檔,檔名不重要,重要的是內容
2. 屬性檔內的<declare-styleable>標簽會被編譯為R.styleable.XXX,在Custom View 中的Constructor 中要去存取標簽的內容,取得設定值,設定成員變數內容
3. 在OnDraw中,根據之前取得的成員變數內容繪置Custom View
4. OnMeasure 要處理wrap_content的寬度設定,否則layout會有問題。
http://blog.csdn.net/lmj623565791/article/details/24252901
comments:
1. 定義屬性檔,檔名不重要,重要的是內容
2. 屬性檔內的<declare-styleable>標簽會被編譯為R.styleable.XXX,在Custom View 中的Constructor 中要去存取標簽的內容,取得設定值,設定成員變數內容
3. 在OnDraw中,根據之前取得的成員變數內容繪置Custom View
4. OnMeasure 要處理wrap_content的寬度設定,否則layout會有問題。
星期一, 2月 16, 2015
Compile Google VP9 with visual studio 2013
System: windows 8.1 64 bit
Reference:
http://www.webmproject.org/code/build-prerequisites/
http://blog.csdn.net/kl222/article/details/23101115
1. Download Yasm 32bit
http://yasm.tortall.net/Download.html
Note: Must download 0.8.0 version, otherwise, there will cause compile errors
rename yasm-0.8.0-win32.exe to yasm.exe
Set environment path:
2. Download MinGW
http://sourceforge.net/projects/mingw/files/Installer/
3. Install MSYS
4. Execute the command line environment of VS2013
5. type d:\mingw\msys\1.0\msys.bat
5. type cd d:/project/vp9/libvpx-v1.3.0/build
6. type $ ../configure --disable-shared --enable-static --enable-static-msvcrt --disable-docs --disable-examples --target=x86-win32-vs12 --prefix=/usr/local/msvc
7. type make
9. find vpx.sln
10. open and correct it
11. take care of test_libvpx references, and set the linker option of vpx /SAFESEH:NO
12. make
14. Good luck.
訂閱:
文章 (Atom)