Skip to main content

Posts

Showing posts from January, 2016

Yii 2 Validation

Bài này note lại validation trên Yii cả 1.1 lẫn 2.xx Doc của Yii cũng tương đối nhưng không nhiều guide, tuts như Laravel hay các FW nổi hơn. Ngoài ra Doc của Yii của 2 version 1, 2 cứ loạn lên. Bản thân doc và API guide cũng dễ gây nhầm lẫn. http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html#integer Controller: public function actionCreate($project_list_id=null) { $request = Yii::$app->request; $inputs = $request->post(); if(!$project_list_id) { $project_list_id = $request->get('project_list_id'); } $is_new = !isset($project_list_id) ? true : false; $dropdownArray = $this->getDropdownArray(); $projectListModel = new ProjectListRecord(); $projectModel = new PmsRecord(); if(isset($project_list_id)) {   // check on edit or create $projectListModel = ProjectListRecord::findOne(['id' => $project_list_id, 'delete_flg' => 0]);        $projectModel = PmsRecord::findOne(['pr

rsync 1

http://askubuntu.com/questions/323775/monitor-watch-running-rsync-process/323782 You can do: strace -e open $(ps -o lwp= -LC rsync | sed 's/^/-p/') To see what it's doing, or lsof -ad3-999 -c rsync to see what files it currently has opened.

Host vào blogspot cập nhật

216.58.221.33 1.bp.blogspot.com 216.58.221.33 2.bp.blogspot.com 216.58.221.33 3.bp.blogspot.com 216.58.221.33 4.bp.blogspot.com 74.125.71.191 blogspot.com 74.125.71.191 blogger.com 74.125.71.191 www.blogger.com 74.125.71.191 draft.blogger.com 74.125.71.191 buzz.blogger.com 74.125.71.191 *.blogspot.com Nguồn  http://www.phamquangtruong.net/2015/11/2015-huong-dan-vao-blogspot-khi-bi-chan.html https://www.raymond.cc/blog/how-to-access-blocked-websites-bypassing-streamyx-internet-filter/

FFmpeg 2

Ghép nhiều video giống nhau (khung hình frame, frame rate fps, cùng codec...)  làm 1. Lệnh sau đây nó tiện hơn do tốc độ xử lý nhanh. https://trac.ffmpeg.org/wiki/Concatenate ffmpeg -f concat -i <(for f in *.wav; do echo "file '$PWD/$f'"; done) -c copy output.wav ffmpeg -f concat -i <(for f in *.wmv; do echo "file '$PWD/$f'"; done) -c copy output.wmv ffmpeg -f concat -i <(for f in *.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4 Lưu ý là 2 hay nhiểu video phải same nhau, nếu ko thì output ra sẽ có lỗi ở những video phía sau video đầu tiên. Nó sẽ lấy codec, fps, frame ... của video 1 làm chuẩn. Các video same nhau hay có từ sreencapture, smartphone... nói chung cùng 1 device tạo ra video. Với những video khác thông số thì cần mất công qua nhiều bước hơn, vd: ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts

Docker 1

Docker xịn hơn VM khác như VirtualBox, VMWare ở nhiều điểm. Vagrant Vagrant homestead https://blog.duyetdev.com/2015/12/docker-la-gi-co-ban-ve-docker.html#.VqmNA_l96Ht http://ianmurdock.com/ https://en.wikipedia.org/wiki/Aaron_Swartz

JS 2

var canSaveCookie = (function () { $.cookie("testSaveCookie", {}); var ok = $.cookie("testSaveCookie") !== null; $.removeCookie("testSaveCookie"); return ok; })(); function addTaskList(project_management_id, date) { $.ajax({ url: "<?= Yii::$app->request->baseUrl ?>/task-detail/ajax-list-task", dataType: 'json', data: {'project_management_id' :project_management_id, 'ask_date': date}, type: 'POST', success: function (res) { tasks = JSON.parse(res.items); // defaultEventClick(tasks[0]); console.log(tasks.length); // avoid duplicate append task list clearPopupTaskList(); $.each(tasks, function(id, value) {     $('#popup_task_id')        .append($("<option></option>")        .attr("value", value['id'])        .text(value['task_name'])); }); defa

VirtualBox 1

1. Cấu hình Vbox 2. Một số thao tác hay dùng: snapshot, shareFolder 1. Cấu hình a. Phím, nên bỏ Ctrl (Phải) mặc định là Host Key trên VirtualBox. Vd bạn nhấn Ctrl trên Chrome trong Vbox thành ra Restart :) chứ ko phải reload. b. Cài GuestCD c. Set IP động d.Cấu hình performance: vbox chạy thường full HDD (100% ổ cứng load) read/write làm cho máy rất đơ. Setting bỏ ACPI support, CPU về 1 ... 2. Thao tác Snapshot như là 1 backup, trên VPS cũng có Snapshot để back về khi có sự cố. Snapshot cũng tạo ra file rất nặng tùy theo kích thước máy ảo (vd 40GB dùng 20GB) thì snapshot cũng tạo ra file vdi tầm đó. Mặc định snapshot folder để ở ổ C (Users...) => cận thận set lại ko thì full ổ C. ShareFolder, dùng share của Vbox hoặc Dropbox. Trên Win +Mac thì share rất tươi cả linux windows (máy ảo)... còn trên ubuntu có vẻ hay lỗi.

Terminal 2

Terminal trên windows: Mặc định khi quét (select) text trên Win thì nó là chọn theo cột (column select) nghĩa là bạn có thể chọn riêng từng cột dữ liệu trên màn hình terminal thay vì chọn hết dòng này đến dòng khác. Trên Windows 10 thì đã đổi về select thông thường nghĩa là bạn quét chữ trên terminal nó sẽ select các dòng liên tục. Nhấn Alt + quét chữ. Trên win cũ thì muốn select các dòng liền mạch thì giữ Ctrl (hay Alt ko nhớ nữa) [ảnh minh họa] Trên Unix default là chọn cả nhiều dòng liên tục khi bạn quét text, muốn chọn cột thì Ctrl + mouse. Trên Win terminal khá tù, muốn tiện lợi thì cài git-bash hay powershell. Giao diện git-bash cũng cần tùy biến cho kích thước to hơn. Copy/Paste Windows: + Enter = copy, Right Click hoặc phím Insert (shift Insert) = Paste. Linux; + Ctrl+shift+C = copy vì Ctrl+C = terminate, dừng chương trình đang chạy. Hơn nữa Ctrl+Shift+C = copy không format dữ liệu (như font, size...) thì phải. + Ctrl + Shift +V = paste vào terminal, lí do là vì

Chuyển data từ Amazon S3 về server

Using Amazon S3 data in PHP - Switch from S3 to server VPS Bài này note lại một số lưu ý khi chuyển data từ S3 về server hay local, dừng dịch vụ S3. Các bước dừng dịch vụ S3: 1. Download dữ liệu từ S3 về. 2. Sửa mã để dùng data trên server (hay cloud khác) thay vì S3. Cập nhật Database. 3. Hoàn tất: testing và các vđ liên quan. 1. Download: dùng awscli (trên ubuntu, osx cài dùng pip ), web interface hay wget, CURL ... - Extract s3 url dùng mysql mysql -e "select picture from post where picture like 'https://s3%'" -u username -p db_name > s3_post_list.txt Dùng PHP nếu lệnh query phức tạp và đòi hỏi tính toán nhiều hơn. Như ở trên thì chỉ cần tìm record có trường picture có chữ https://s3-*** vì logic ở đây lưu cả URL S3. Nếu chỉ lưu tên object (như tên file, ảnh) trên S3 thì cần logic khác. Việc lọc bớt ảnh chỉ của S3 vì có thể ảnh là embed (link từ gippy hay 1 cloud nào đó) để tránh lấy nhầm ảnh ko phải từ S3. Sau khi có list ảnh thì download, vd dùng