2018年4月14日 星期六

parallels desktop之下windows 8.1修改partition (系統硬碟)工具 & windows8.1安全開機模式

我的windows 8.1原來是在bootcamp下執行的,後來因為要用xamarin開發,鮮用windows 開機,就直接用匯入的方式轉入parallels desktop的硬碟格式,這下問題來了,
原本在bootcamp下開機時mac os的系統硬碟還是會被標示佔用點空間,造成在parallels desktop設定中看到的空間使用量遠大於真正可以使用的系統硬碟空間的大小,
而且parallels desktop屢屢說可以釋放空間也釋放失敗,去parallels desktop的組態硬體設定硬碟大小也沒辦法縮小空間,
這時是要做硬碟空間調整的時候了.
1.首先要選對工具
下載「EaseUS Partition Master 」(我那時候是12.9)
用試用版就可以了
改了partition大小後及磁區的起始位址後,它會要你重開機,有時不成功,要兩三次才會調整完partition起始及大小
(AEO牌的就不太行了....)
2.改好了partition,用檔案總管及電腦管理中的硬碟管理比對硬碟調整後大小是否一致,總算省下了些空間,可以去parallels desktop的組態硬體設定硬碟了

一定要注意的地方:
在安裝EaseUS Partition Masterar時,會偷渡些東西要仔細看
像是yahoo的情蒐,就可以say no,但是avast antivirus free就要小心了
不小心裝了,就要他們的官網https://www.avast.com/zh-tw/uninstall-utility 去下載「avastclear」工具,否則無法移除
這工具還有個特點是一定要在安全模式下執行才行
而windows 8.1的安全模式請找「系統設定」程式中有個「開機」的頁籤,下面有個「安全開機」,打勾就可以了

(這就是安裝東西沒仔細看的結果,防毒軟體跟病毒有的比了)
這問題拖了好久才解決了.(畢竟工作還是最優先的嘛)

2018年4月3日 星期二

明明在ultraEditor中比對的長度是一樣的兩個文字檔,有些處理單位會認為是格式錯誤

明明在ultraEditor中比對的長度是一樣的兩個文字檔,有些處理單位上傳後會認為是格式錯誤
這時....儘信ultra editor不如無ultra editor,
原因不是出在文字行的內容,而是出在檔案格式
(只有在另存新檔時,才會看到「編碼」的差異)
如何從UTF-8轉成ANSI?
答案就是一個選項
===============================
System.IO.File.WriteAllLines(filePath, lines.ToArray(),Encoding.Default);
=====================================
這裡的default指的不是平台的locale編碼方式(big5......)
而是.....
取得作業系統目前 ANSI 字碼頁的編碼方式

2018年3月25日 星期日

讓extjs4使用你目前windows資源的一種方式--Cross-Origin Resource Sharing 的應用

在你的windows做一個http listener
========================================
                Thread xThread = new Thread(
                     delegate () {
                     HttpListener httpListener = new HttpListener();
                     httpListener.Prefixes.Add("http://localhost:2048/DoLocalJob/");
                     try {
                         httpListener.Start();
                     } catch (HttpListenerException hlex) {
                         Console.WriteLine(hlex);
                         return;
                     }
                     Console.WriteLine("Now ready to receive traces...");
                     while (true) {
                         var context = httpListener.GetContext(); // get te context
                         var data_text = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding).ReadToEnd();
                         Console.WriteLine("data_text is " + data_text);
                         var cleaned_data = System.Net.WebUtility.UrlDecode(data_text);
                         Console.WriteLine("clear data is " + cleaned_data);
                         Console.WriteLine("raw is " + context.Request.RawUrl);
                         byte[] buffer = Encoding.UTF8.GetBytes("OK");
                        HttpListenerResponse response = context.Response;
                        response.StatusCode = 200;
                        response.SendChunked = true;
  //如果沒有以下幾個header設定的話,Ext.Ajax.Request所收到的response都是空白的!!
                        response.ContentType = "application/json; charset=utf-8";
                        response.AppendHeader("Access-Control-Allow-Origin", "*");
                        response.AppendHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
                        response.AppendHeader("Access-Control-Allow-Headers", "Content-Type,x-prototype-version,x-requested-with");
                        response.ContentLength64 = buffer.Length;
                        Stream output = response.OutputStream;
                             if (context.Request.RawUrl.Contains("axn=MyAction")) {
                                 doLocalJobProcess();
                                 response.ContentLength64 = buffer.Length;
                                 output.Write(buffer, 0, buffer.Length);
                                 output.Flush();
                                 continue;
                             }
                             buffer= Encoding.ASCII.GetBytes("parameter error!!");
                             output.Write(buffer, 0, buffer.Length);
                             Console.WriteLine("send back " + cleaned_data);
                             output.Flush();
                             output.Close();
                         }
                     });
                xThread.Start();

========================================
local http server起來了,之後就是網頁的事了
=======================================
            Ext.Ajax.request({
                defaultHeaders: {
                    Accept: 'application/json',
                    'Content-Type': 'application/json'
                },
                useDefaultXhrHeader: false,
                cors: true,
                url: 'http://localhost:2048/DoLocalJob/axn=MyAction',
                method: 'POST',
                params: {
                       xxx:yyyy
                },
                timeout: 10240,
                success: function (response) {
                    if (response.responseText == 'OK') {
                         ......
                         ....
                         return;
                    }
                      //....其他錯誤....
                    return;
                },
                failure: function (response) {
                       //....http listener 沒起來,或是剛才說的header沒設好也會跑來這段
                    return;
                }
            });
===============================================

2018年3月24日 星期六

for Macbook OSX ,外接式螢幕找不到你要的解析度?試看看 「option」鍵吧

有時明明外接式螢幕可以撐到1920x1080的解析度
可是OSX只能給你1280x720,
有一個shareware(不是免費的,10天試用期)叫做「SwitchResX」的工具,可以試看看
(URL:http://www.madrau.com/ )
但,別急,如果你沒用過option鍵的話,先試看看,不行再去買switchResX
詳細參考:
https://support.apple.com/kb/PH25175?locale=zh_TW
=======================================
...
...
當您按一下「縮放」時請同時按下 Option 鍵,以顯示其他解析度供第二部顯示器使用。然後,為第二個顯示器選擇一個縮放解析度選項。
....
....
=======================================


別像我再傻傻的拔拔接接了,很難看耶......



2018年3月21日 星期三

VideoFileWriter 在 WriteVideoFrame存放畫面時居然出現「System.ArgumentException!?」

本來想玩openCV做商品辨識能力的智慧型倉儲,不過公司比較想做錄影存證,沒差,都好玩啦
不過在存放webcam的畫面進入mp4時,出現了System.ArgumentException
===========================================
using Accord.Video.FFMPEG;
using Accord.Controls;
using Accord.Video;
using Accord.Video.DirectShow;
.....
....
...
VideoFileWriter fileWriter = new VideoFileWriter();
....
private void Video_NewFrame1(object sender, NewFrameEventArgs eventArgs) {
            video = (Bitmap)eventArgs.Frame.Clone();
            picShowImg.Image = (Bitmap)eventArgs.Frame.Clone();
            if (isRecording) fileWriter.WriteVideoFrame(video);
            
 }
.....
.....
....
void bgnSaveVideo(){
                int h = 1024;
                int w = 768;
                string fileName = "d:\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4";
                fileWriter.Open(fileName, w, h, 24, VideoCodec.MPEG4, 50000000);
                fileWriter.WriteVideoFrame(video);    <------這時發生錯誤!!
}
============================================
查了很久,試了好幾次才知道原因:長寬不是自己高興多少就多少,而是要看當時frame的bitmap長寬多少,才能用WriteVideoFrame
=======以下是正確的寫法========
                 int h = video.Height;
                int w = video.Width;
                string fileName = "d:\\" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".mp4";
                fileWriter.Open(fileName, w, h, 24, VideoCodec.MPEG4, 50000000);
                fileWriter.WriteVideoFrame(video);    <------這時就過關了!!
=============================
...
...
os:應該沒人犯這樣的錯吧.網路上一直找不到相關的案例....

2018年2月12日 星期一

天啊.....localstorage 爆掉了!!

一口氣在browser 的localstorage 塞了四萬多筆資料
,在chrome遇到「Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'seq-22231' exceeded the quota」
在firefox 則遭遇到「 NS_ERROR_DOM_QUOTA_REACHED」這樣的錯誤
可是沒時間改資料來源的架構了,如何是好?

如果你做人成功,可以先請user用firefox的話,那就已經解決了,怎麼說?
請到firefox的網址列輸入「about:config」
找「storage.default_quota」這項,如圖

預設值是5210,不想試了,直接加個0免找了,
問題就解決了
如果你知道chrome有這樣設定怎麼設的話請跟我說一下,謝謝囉

2018年1月30日 星期二

for Extjs4 ,store + ajax proxy,如何在「load」事件中讀取records之外其他傳回來的json值

例, 某個store物件是長這樣的
===============================
  var store=bew Ext.data.JsonStore(
    ...
    ...
    proxy:{
      type:'ajax',
      url: .....
   }
);
  store.load({
      scope:this,
     callback:function(records,option,success){
            ...
            ...
         if(success){
                .....產生grid.....
        }
     }
  });
===============================
server side:
==================
傳回一個json,

  var jason={
      success=....,
      totalCount=....
      rows=......
      msg=...... <---如果有錯誤發生的話
 }
==================
如果是success還好,直接做grid產生的動作
可是人生不如意,十之三四五六七八九,多少會有success=false的時候
可是如果是failed的話,要怎麼接收ms的消息?明明callback 只有三個參數啊
有的人是說用這方式來接收server response的json物件....
=========================
callback: function(records, operation, success) {  

 var jsonStr = Ext.JSON.decode(operation.response.responseText);  

 alert(jsonStr.message); 

}

=======================
很不幸的,上述的程式碼是行不通的(上述的作法應該是3.x的吧?)
會出現 operation.response=null的現象

如何是好?真正的做法是:


=======================

 if (!success) {

            var jsonObj =store.proxy.reader.rawData; 

            Ext.Msg.alert('Server Failed!!', jsonObj.msg,Ext.emptyFn);                                    

           return; 

 }else{ 

   ....產生grid.....

 }

=======================

注意,「store.proxy.reader.rawData」已經是json物件了,不是text,不要再自做聰明去用Ext.JSON.decode...了,否則會出現「You're trying to decode an invalid JSON String: [object Object]」這樣的訊息,請小心
以上,大家加油了


參考來源

2017年12月25日 星期一

for xamarin ios,javascript call back to UIView

有些程式在web已經寫好了,想要xamarin UI中應用的話,
就ios而言,就可以利用"WebKit"了
今天就先討論從javascript丟回來呼叫xamarin UI怎麼做
==============某個要查看網頁的viewcontroller======
    public partial class MyMapViewController : UIViewController, IWKScriptMessageHandler {
        public MyMapViewController () : base("MyMapViewController ", null) {
        }

        public override void DidReceiveMemoryWarning() {
            base.DidReceiveMemoryWarning();
         
            // Release any cached data, images, etc that aren't in use.
        }

        public override void ViewDidLoad() {
            base.ViewDidLoad();

            var userController = new WKUserContentController();
            userController.AddScriptMessageHandler(this, "myApp");
            var config = new WKWebViewConfiguration {
                UserContentController = userController
            };
            var webkitView= new WebKit.WKWebView(viewContainScroll.Frame, config);
            webkitView.LoadRequest(new Foundation.NSUrlRequest(new NSUrl("你的web網址")));
            webkitView.ContentMode = UIViewContentMode.ScaleToFill;
            this.View.AddSubview(webkitView);
       }

public void DidReceiveScriptMessage(WKUserContentController userContentController,           WKScriptMessage message) {
            var msg = message.Body.ToString();
            System.Diagnostics.Debug.WriteLine(msg);
        }

============================================
手機端好了,再來就是看遙遠的雲端了
===============================
 <html>
   <body>
    <script type="text/javascript">
       //找個按鈕觸發這個doCallBack吧
       var doCallBack = function ( paraStr) {
            //以下的動作就會呼叫包含他的webkitview所AddScriptMessageHandler的物件的     
            //「DidReceiveScriptMessage」的函數來接受訊息了
            window.webkit.messageHandlers.myApp.postMessage("param=" + paraStr);
        }
         ...
         ...
         .....
    </script>
   </body>
</html>
================================
完整的討論來源,請參考這裡
現在的前端的工程師不只是二刀流的,
通常是剪刀菜刀剃頭刀手術刀小李飛刀都要會了

2017年12月22日 星期五

繪製半透明的png於底圖上之

正如同「身為一個汽車維修員,有個錘子在身邊,也很合邏輯」一樣
工程師嘛,圖片加工也要會是很自然不過的事了,特別是你有用到平面圖的機制時
「I am here」標示本來是不需要半透明的,基於方便參考其他地標時,還是給個半透明的版本好了
===================================================
               ...
               ...
              ...
              var Alpha=0.55f;
                Bitmap bmpIamHere = new Bitmap(imgIamHereIcon);
                Color background = bmpIamHere.GetPixel(0, 0);
                 //設定透明色為.....
                bmpIamHere.MakeTransparent(background);
                Graphics gfxMap = Graphics.FromImage(imgMap);
                //set alpha value.
                ColorMatrix cm = new ColorMatrix();
                cm.Matrix33 = Alpha;
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorMatrix(cm);
             
                //沒有 Alpha值時,直接繪製,gfxMap.DrawImage(bmpIamHere, (float)markAtX, (float)markAtY, bmpIamHere.Width, bmpIamHere.Height);
               //有alpha值時,請用以下方式
                gfxMap.DrawImage(bmpIamHere, new Rectangle((int)markAtX, (int)markAtY, bmpIamHere.Width, bmpIamHere.Height), 0, 0, bmpIamHere.Width, bmpIamHere.Height, GraphicsUnit.Pixel, ia);
                ...
               ...
               ...
=================================================
來源在此

加油了

2017年12月20日 星期三

ERROR ITMS-90502: "Invalid Bundle. Apps that only contain the arm64 slice must also have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist."

在用 application Launcher 上傳ipa到 iTunes connect  時
遇到以下的狀況:
「ERROR ITMS-90502: "Invalid Bundle. Apps that only contain the arm64 slice must also have 'arm64' in the list of UIRequiredDeviceCapabilities in Info.plist."」
這樣的問題直接就是去Info.plist去改:
==============================
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
===============================
(從原來的armv7改成arm64就可以了)
記得:就算是只做testflight,也要把media.xcassets中的 icon都指定完才可以上beta測試
還有,用application launcher上傳完ipa檔後,不要只是在  iTunes connect的web介面去看「activities/活動」看它有沒有上傳
有時.......是不會出現的, iTunes connect會把問題寄到你的email而不是在application launcher上傳驗證後就直接給你答案.
多注意點不同的資訊管道吧