[AngularJS] Directive筆記一下
[Kinect] Day 1 - 讓程式碼先能動
Kinect Data Source
- Color
- Infrared
- Depth
- Body
- BodyIndex
For Windows 8.1 App
- 開啟microphone, webcam權限
- 加入WindowsPreview.Kinect
- 建置CPU設定為x86
取得kinectSensor的方式
1 | this.sensor = KinectSensor.GetDefault(); |
Readers
1 | InfraredFrameReader reader = this.sensor.InfraredFrameSource.OpenReader(); |
Frame references
- Send in frame event args
- AcquireFrame : access to the actual frame
- RelativeTime : allow to templorally correlate frames
1 | private void InfraredReaderFrameArrvied(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args) |
Frame
- Gives access to the frame data
- Make a local copy of access the underlying buffer directly
- Contains metadata for the frame
- Color, Format, width, height,etc.
- Important: Not Disposing frames will cause you to not receive more frames
Demo Code
1 | using System; |
Demo2
1 | using System; |
[Laravel] Laravel with Angular
當laravel想要好好的跟angular在一起時,Route都是他們之間的第三者。 前一陣子有發現一個還不錯的方式可以讓Laravel的Route失效。那就是利用
App::missing(function($exception)
{
return View::make('index');
});
```
這樣子的設定,就可以不用讓Laravel一直回傳index頁面. 如果需要其他路由設定時,就直接在上面新增即可.
當這樣子設定時,html頁面就可以放在public folder下面,不用使用blade template. 好處是,不用再多學習blade的語法。angular的操作也比較直覺。
[Azure] Website Always On
當mvc website第一次讀取的速度都會很慢,這個原因是因為要做complie的動作, 那如何避免這個現象發生呢,
- 將azure website的規格升級到basic以上的規格並開啟alowasy on.
- 寫webjob(請參考這篇文章http://wp.sjkp.dk/windows-azure-websites-and-cloud-services-slow-on-first-request/)
- 利用http://www.thecloudup.com/, 幫你做第二點事情(免費)
[AngularJS] 混亂的html5mode
Angular裡面有一個方法可以把# (hash tag) 給拿掉,那就是將html5mode開啟
1 | $locationProvider.html5Mode(true).hashPrefix('!') |
但是如果angular route是架構在asp.net mvc上面,那就會有route打架的情形發生, 或著reload page會出現頁面錯誤的訊息 網路上面的資訊也有很多種版本,以下我也提供一下我的版本
主要重點, asp.net的routeConfig裡面也要同時間定義angular route的部份,但是controller/action是指到index page
1 | routes.MapRoute("member_edit", |
1 | .state('main.edit', { |
這樣子的設定, 可以讓其他頁面直接用網址的方式開啟那個頁面(請搜尋 deep link angualr)
當設定完成後,卻又發現另外一個問題,問題是, 我在選單連結的部份,有一些是要跑mvc本身的actionlink的動作, 但是angular會先處理 < a > 的動作,所以要跳過這個動作,可以利用 window.location.replace 來處理
[Javsscript] for loop VS forEach when there is async function
今天在檢查一段程式的時候,再跑一段根據array的資料新增或更新到資料庫中,卻發現都是更新同一筆紀錄 原本的寫法
1 | for(var i=0; i < arr.length; i++){ |
這是因為javascript async non-blocking的關係,所以資料庫新增自己跑自己的,for迴圈跑自己的,當新增時要取資料庫裡面資料時,會取到不對的值
解法:用array.forEach來替代for loop
1 | arr.forEach(function(item,idx){ |
當我改寫成這樣子後,就正常了
[Azure] Azure Storage 2.0 – Some blob changes to be aware of -Ref
Reference Website Url http://happyfunpartytime.com/2012/11/azure-storage-2-0-some-blob-changes-to-be-aware-of/
大綱:
如果從官網上面抄下來的範例如果直接貼在vs裡面,會出現錯誤,那根據原本字面上的意思來找相類似的method來用
1 | CloudBlob thumbnailBlob = objContainer.GetBlobReference(filename); |
換成
1 | var thumbnailBlob = objContainer.GetBlobReferenceFromServer(filename); |
結果,一直給我跑404.
這GetBlobReserenceFromServer的用意是去server上面找filename的blob reference回來. 所以當我們要建立新的blob, 這就文不對題了。 所以要改用
1 | CloudBlockBlob blob = objContainer).GetBlockBlobReference(filename); |
這樣子就okey了.
1 | blob.UploadFile(fileData.LocalFileName); |
這個也改掉了, 要改成
1 | CloudBlockBlob.UploadFromFile(filenameWithPath, FileMode) |
CloudBlockBlob也有提供不同的上傳方式,請參閱MSDN
[Azure] DocumentDB
使用Azure新的NoSQL – DocumentDB(還在preview版本中)
怎們建立網頁上面有說. 這裡只記錄一些操作上的動作
- DocumentDB裡面有分幾個元素 Database, DocumentCollection, document
元素之間的關係
1 | Database -> DocumentCollection(with id name=xxxx) -> document(s) |
string dataBaseName = 「testDB」; var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
var database = client.CreateDatabaseQuery().FirstOrDefault(db => db.Id == dataBaseName);
if (database == null) { database = await client.CreateDatabaseAsync( new Database { Id = dataBaseName }); }
1 | ## 這個寫法如果用在webapi上面,會有出現等不到回應的情形發生,所以解決方法是變成同步, 寫法會變成 |
database = client.CreateDatabaseAsync(new Database{Id = dataBaseName}).Result;
1 |
|
User _user = new User(){name=『abc』}; var document1 = await client.CreateDocumentAsync(documentCollectionLink, _user);
這裡的documentCollectionLink是指 DocumentCollection collection = client.CreateDocumentCollectionQuery(database.SelfLink).FirstOrDefault(db => db.Id == dataBaseName); 或者是剛新增出來的collection DocumentCollection collection = client.CreateDocumentCollectionAsync(database.SelfLink, new DocumentCollection { Id = 「some name」 });
documentCollectionLink = collection.SelfLink;
1 |
|
var doc = Client.CreateDocumentQuery
return Client.ReplaceDocumentAsync(doc.SelfLink, item);
1 |
|
var doc = Client.CreateDocumentQuery
return Client.DeleteDocumentAsync(doc.SelfLink);
1 |
|
Client.CreateDocumentQuery