Response::Download() in Laravel 4.x needs php_fileinfo extension. Sometimes web hosting server doesn’t have that extension on, althought it’s default for php 5.4.

so the way to work around is make a response, and add header to it. See code below

1
2
3
4
5
$file = File::get($filepath);
$response = Response::make($file, 200);
$response->header('Content-Type', $item->mime);
$response->header('Content-Disposition','attachment;filename="'.$filename.'"');
return $response;

之前有寫過一篇有關[Laravel] Laravel with Angular, 但是這個方法在Laravel 5.0裡面是不合用的

所以laravel 5.0的作法如下 在 app/Exceptions/Handler.php 裡修改render function

1
2
3
4
5
6
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
return response()->view('index')->header('Content-Type', 'text/html');
return parent::render($request, $e);
}

這個效果等於laravel 4.x的app::missing

Kinect Data Source

- Color
- Infrared
- Depth
- Body
- BodyIndex    

For Windows 8.1 App

- 開啟microphone, webcam權限
- 加入WindowsPreview.Kinect
- 建置CPU設定為x86

取得kinectSensor的方式

1
2
3
this.sensor = KinectSensor.GetDefault();
this.sensor.Open();
this.sensor.Close();

Readers

1
2
InfraredFrameReader reader = this.sensor.InfraredFrameSource.OpenReader();
reader.FrameArrived += InfraredReaderFrameArrvied;

Frame references

- Send in frame event args
- AcquireFrame : access to the actual frame
- RelativeTime : allow to templorally correlate frames
1
2
3
4
5
6
7
8
9
10
11
private void InfraredReaderFrameArrvied(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args)
{
using (InfraredFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
// Get What you need from the frame

}
}
}

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using WindowsPreview.Kinect;
using Windows.UI.Xaml.Media.Imaging;

namespace KinectStudy_01
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}

KinectSensor sensor;
InfraredFrameReader reader;
ushort[] irData;
byte[] irDateConverted;
WriteableBitmap irBitmap;

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
sensor = KinectSensor.GetDefault();
reader = sensor.InfraredFrameSource.OpenReader();
FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
irData = new ushort[fd.LengthInPixels];
irDateConverted = new byte[fd.LengthInPixels * 4];
irBitmap = new WriteableBitmap(fd.Width, fd.Height);
image.Source = irBitmap;

sensor.Open();
reader.FrameArrived += InfraredReaderFrameArrvied;
}


private void InfraredReaderFrameArrvied(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args)
{
using (InfraredFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
// Get What you need from the frame
frame.CopyFrameDataToArray(irData);
for (int i = 0; i < irData.Length; i++)
{
byte intensity = (byte)(irData[i] >> 8);
irDateConverted[i * 4] = intensity;
irDateConverted[i * 4 + 1] = intensity;
irDateConverted[i * 4 + 2] = intensity;
irDateConverted[i * 4 + 3] = 255;
}

irDateConverted.CopyTo(irBitmap.PixelBuffer);
irBitmap.Invalidate();
}
}

}
}
}

Demo2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using WindowsPreview.Kinect;
using Windows.UI.Xaml.Media.Imaging;

using Windows.UI.Xaml.Shapes;
using Windows.UI;


namespace KinectStudy_01
{
public sealed partial class MainPage : Page
{
KinectSensor sensor;
InfraredFrameReader reader;
ushort[] irData;
byte[] irDateConverted;
WriteableBitmap irBitmap;

Body[] bodies;
MultiSourceFrameReader msfr;

public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
sensor = KinectSensor.GetDefault();
reader = sensor.InfraredFrameSource.OpenReader();
FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
irData = new ushort[fd.LengthInPixels];
irDateConverted = new byte[fd.LengthInPixels * 4];
irBitmap = new WriteableBitmap(fd.Width, fd.Height);
image.Source = irBitmap;

bodies = new Body[6];
msfr = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Infrared);
msfr.MultiSourceFrameArrived += msfr_MultiSourceFrameArrived;

sensor.Open();
}

void msfr_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs args)
{
using (MultiSourceFrame frame = args.FrameReference.AcquireFrame())
{
if (frame != null)
{
using (BodyFrame bodyframe = frame.BodyFrameReference.AcquireFrame())
{
using (InfraredFrame ifFrame = frame.InfraredFrameReference.AcquireFrame())
{
if (bodyframe != null && ifFrame != null)
{
// Get What you need from the frame
ifFrame.CopyFrameDataToArray(irData);
for (int i = 0; i < irData.Length; i++)
{
byte intensity = (byte)(irData[i] >> 8);
irDateConverted[i * 4] = intensity;
irDateConverted[i * 4 + 1] = intensity;
irDateConverted[i * 4 + 2] = intensity;
irDateConverted[i * 4 + 3] = 255;
}

irDateConverted.CopyTo(irBitmap.PixelBuffer);
irBitmap.Invalidate();

// 取得身體的相關資料
bodyframe.GetAndRefreshBodyData(bodies);
bodyCanvas.Children.Clear();
foreach (Body body in bodies)
{
if (body.IsTracked)
{
// 取得頭的關節位置
Joint headJoint = body.Joints[JointType.Head];
if (headJoint.TrackingState == TrackingState.Tracked)
{
// 轉換成DepthSpacePoint
DepthSpacePoint dsp = sensor.CoordinateMapper.MapCameraPointToDepthSpace(headJoint.Position);
// 在該位置上畫圓圈
Ellipse headCircle = new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)) };
bodyCanvas.Children.Add(headCircle);
Canvas.SetLeft(headCircle, dsp.X - 25);
Canvas.SetTop(headCircle, dsp.Y - 25);
}
}
}
}
}
}
}
}
}
}
}

Xbox One 同時推出Kinect v2,提供更強大的硬體功能及軟體功能, 剛好手上的案子也差不多到一個段落了。 所以決定來學習Kinect的開發

前置準備

  1. Kinect for windows
  2. 如果已經有了xbox one, 可以只買kinect adapter轉接器就可以了 巴哈
  3. Kinect sdk 2

硬體需求

  1. CPU: i7(建議)
  2. RAM: 4GB(建議)
  3. GPU: DirectX11 (必須)
  4. USB 3.0(必須)
  5. OS: Windows 8.0/8.1(必須)

詳細細節請參考官方網站

已經買了adapter, 等東西寄到後就可以開始學習了

當laravel想要好好的跟angular在一起時,Route都是他們之間的第三者。 前一陣子有發現一個還不錯的方式可以讓Laravel的Route失效。那就是利用

App::missing(function($exception)
{	
	return View::make('index');
});
```

這樣子的設定,就可以不用讓Laravel一直回傳index頁面. 如果需要其他路由設定時,就直接在上面新增即可.

當這樣子設定時,html頁面就可以放在public folder下面,不用使用blade template. 好處是,不用再多學習blade的語法。angular的操作也比較直覺。

當mvc website第一次讀取的速度都會很慢,這個原因是因為要做complie的動作, 那如何避免這個現象發生呢,

  1. 將azure website的規格升級到basic以上的規格並開啟alowasy on.
  2. 寫webjob(請參考這篇文章http://wp.sjkp.dk/windows-azure-websites-and-cloud-services-slow-on-first-request/)
  3. 利用http://www.thecloudup.com/, 幫你做第二點事情(免費)

Angular裡面有一個方法可以把# (hash tag) 給拿掉,那就是將html5mode開啟

1
2
3
$locationProvider.html5Mode(true).hashPrefix('!')

// 這應該會要求設定<base href="/">

但是如果angular route是架構在asp.net mvc上面,那就會有route打架的情形發生, 或著reload page會出現頁面錯誤的訊息 網路上面的資訊也有很多種版本,以下我也提供一下我的版本

主要重點, asp.net的routeConfig裡面也要同時間定義angular route的部份,但是controller/action是指到index page

1
2
3
4
routes.MapRoute("member_edit",
"member/edit/{.Catchall}",
new { controller = "Home", action = "Index" },
namespaces: new[] { "Demo.Areas.member.Controllers" });
1
2
3
4
5
6
7
8
9
10
.state('main.edit', {
url: 'edit/:id',
views: {
'[email protected]': {
controller: 'editFavorController',
controllerAs: 'vm',
templateUrl: 'Home/EditFavor'
}
}
})

這樣子的設定, 可以讓其他頁面直接用網址的方式開啟那個頁面(請搜尋 deep link angualr)

當設定完成後,卻又發現另外一個問題,問題是, 我在選單連結的部份,有一些是要跑mvc本身的actionlink的動作, 但是angular會先處理 < a > 的動作,所以要跳過這個動作,可以利用 window.location.replace 來處理

今天在檢查一段程式的時候,再跑一段根據array的資料新增或更新到資料庫中,卻發現都是更新同一筆紀錄 原本的寫法

1
2
3
4
5
6
for(var i=0; i < arr.length; i++){
db.insert(xxx).then(function(){
...
all insert the same record
})
}

這是因為javascript async non-blocking的關係,所以資料庫新增自己跑自己的,for迴圈跑自己的,當新增時要取資料庫裡面資料時,會取到不對的值

解法:用array.forEach來替代for loop

1
2
3
4
5
arr.forEach(function(item,idx){
db.insert(xxx).then(function(){
...
})
});

當我改寫成這樣子後,就正常了