發表文章

Mac M1 Install Homebrew

## 安裝homebrew ``` /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)" ``` ## 確認安裝路徑 ``` echo $SHELL ``` 回應: ``` /bin/zsh ``` ## 設定環境變數 ``` echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" ``` ## 確認是否設置完成 ``` brew -v ``` 回應: ``` Homebrew 4.1.12 ``` 參考原文:https://medium.com/charles-%E6%B8%85%E6%BD%94%E5%B7%A5/homebrew-mac-m1%E6%99%B6%E7%89%87%E5%AE%89%E8%A3%9D-df0bdbc719f

C#WEB API 無法抓取檔名:Refused to get unsafe header “Content-Disposition”

開發檔案下載時,在測試機開發沒問題,上線後卻無法下載檔名。 開發工具顯示錯誤 Refused to get unsafe header "Content-Disposition" 看HTTP回復的資訊是有 Content-Disposition,但是前端始終抓不到,後來查了一下原來API需要增加 response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); 這樣子前端才可以抓地到這個欄位喔!!!! Ref:https://dicksonkho.com/software-road/refused-to-get-unsafe-header-content-disposition/#comment-1854

javascript JS 物件陣列 數量加總

            // 資料陣列             var array = [                 { Name : 'Apple' , Price : 300 },                 { Name : 'Orange' , Price : 180 }             ]             // es2015 計算加總             var total = array . reduce ( function ( a , b ) {                 return a + b . Price ;             },0);             // 顯示總和             console . log ( "es2015=>" + total );                         // es2016 計算加總             var total2 = array . reduce (( a , b ) => {                 re...

JS 時間格式化擴充 Date.prototype.format

/**  * 對Date的擴充套件,將 Date 轉化為指定格式的String  * 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符,  * 年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字)  * 例子:  * (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423  * (new Date()).format("yyyy-M-d hⓜ️s.S")   ==> 2006-7-2 8:9:4.18  * @param {*} fmt  * @returns  */   Date . prototype . format = function ( fmt ) {     var o = {         "M+" : this . getMonth () + 1 , //月份                 "d+" : this . getDate (), //日                 "h+" : this . getHours () % 12 == 0 ? 12 : this . getHours () % 12 , //小时                 "H+" : this . getHours (), //小时                 "m+" : this . getMinutes (), //分                 "s+" : this . ge...

C# EF 依據資料新增或是更新原有資料

關鍵在於紅色底的字。 當有產品ID相符時,則更新產品,否則新增產品 Entities entities = new Entities(); List<ProductViewModel> products = ...; // 由外部帶入資料 foreach(ProductViewModel p in products){   Product tmp = new Product();   tmp.ID = p.ID ?? GUID,NewID().toString();   tmp.Name = p.Name;   tmp.Code = p.Code;  if (entities.Product.Any(x => x.ID == tmp .ID))  {     entities.Product .Attach(tmp);     entities.Entry(tmp).State = EntityState.Modified;   }    else    {        entities.Product .Add(tmp);    } }

mssql procedure try catch

BEGIN  BEGIN TRY         -- do someting  END TRY  BEGIN CATCH   --DB查詢用   SELECT ERROR_NUMBER() AS ErrorNumber,       ERROR_MESSAGE() AS ErrorMessage,       ERROR_LINE() AS ErrorLine,       ERROR_PROCEDURE() AS ErrorProcedure,       ERROR_SEVERITY() AS ErrorSeverity,       ERROR_STATE() AS ErrorState   --系統拋回訊息用   DECLARE @ErrorMessage As NVARCHAR(1000) = N'錯誤代碼:' +CAST(ERROR_NUMBER() AS VARCHAR) + ';'             +N'錯誤程序名稱:'+ ISNULL(ERROR_PROCEDURE(),'')+ ';'             +N'錯誤行號:'+ CAST(ERROR_LINE() AS VARCHAR)+ ';'             +N'錯誤訊息:'+ ERROR_MESSAGE()   DECLARE @ErrorSeverity As Numeric = ERROR_SEVERITY()   DECLARE @ErrorState As Numeric = ERROR_STATE()   RAISERROR( @ErrorMessage, @ErrorSeverity, @ErrorState);--回傳錯誤資訊  END CATCH END

執行須Admin權限的執行檔

轉寫一個BAT內容如下 runas /profile /savecred /user:Administrator "cmd /c C:\Program\program.exe " 執行後輸入一次密碼之後,後面使用就不需要再輸入密碼了。

Javascript first day of month and end day of month

     const   today  =  new   Date ();      let   beginDate  =  new   Date ();      let   endDate  =  new   Date ();      // fist date of montg      beginDate  =  new   Date (        ` ${ today . getFullYear () } - ${ today . getMonth () +          1 } -01 00:00:00`     );      // end date of month       // set next Month first Date      endDate  =  new   Date (        ` ${ today . getFullYear () } - ${ today . getMonth () +          2 } -01 :23:59:59`   ...

HTML attributes Order

Attribute order HTML attributes should come in this particular order for easier reading of code. class id ,  name data-* src ,  for ,  type ,  href ,  value title ,  alt role ,  aria-* Classes make for great reusable components, so they come first. Ids are more specific and should be used sparingly (e.g., for in-page bookmarks), so they come second. FROM http://codeguide.co/#html-attribute-order

sqlserver 授予查詢權限

-- 授予權限 GRANT select on dbo.Table to user -- 拒絕存取  DENY select on dbo.Table to user

T-SQL 常用時間函數,第一天和最後一天

-- 取第一天 SELECT FORMAT(DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0),'yyyy-MM-dd') AS StartOfMonth; -- 取最後一天 SELECT EOMONTH ( GETDATE() ) AS EndOfMonth;

MSSQL 恢復擁有的結構描述

查詢權限狀態 SELECT * FROM INFORMATION_SCHEMA.SCHEMATA; 設定權限為預設全縣 ALTER AUTHORIZATION ON SCHEMA::db_datareader TO [db_datareader]; ALTER AUTHORIZATION ON SCHEMA::db_datawriter TO [db_datawriter]; ALTER AUTHORIZATION ON SCHEMA::db_ddladmin TO [db_ddladmin]; ALTER AUTHORIZATION ON SCHEMA::db_denydatareader TO [db_denydatareader]; ALTER AUTHORIZATION ON SCHEMA::db_denydatawriter TO [db_denydatawriter];

TSQL Cursor

如何在資料庫中使用資料庫內的資料去做相對應的處理呢? 可以使用Cursor有點類似FOR迴圈,把查詢到的資料全部列出來做你想要的處理 詳細版註解 -- 定義Cursor DECLARE @SampleCursor CURSOR; -- 名稱 DECLARE @Name nvarchar(10); -- 日期 DECLARE @Date datetime2; -- 設定Cursor內容 SET @SampleCursor = CURSOR FAST_FORWARD FOR SELECT Name = N'Wang', Date = GETDATE() -- 開啟Cursor OPEN @SampleCursor -- 讀取Cursor FETCH NEXT FROM @SampleCursor INTO @Name,@Date WHILE @@FETCH_STATUS = 0 BEGIN -- do some thing PRINT '@Name' PRINT @Name PRINT '@Date' PRINT @Date -- 取下一列的資料 FETCH NEXT FROM @SampleCursor INTO @Name,@Date END -- 關閉Cursor CLOSE @SampleCursor DEALLOCATE @SampleCursor 簡易版註解 -- 定義Cursor DECLARE @SampleCursor CURSOR; -- 名稱 DECLARE @Name nvarchar(10); -- 日期 DECLARE @Date datetime2; SET @SampleCursor = CURSOR FAST_FORWARD FOR SELECT Name = N'Wang', Date = GETDATE() OPEN @SampleCursor FETCH NEXT FROM @SampleCursor INTO @Name,@Date WHILE @@FETCH_STATUS = 0 BEGIN -- do some thing P...

MSSQL Date Format 格式化時間

主要是用FORMAT(Date,Format)的函數 另外也可以用DATEPART組,可是還是FORMAT好用 SECLCT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm')

angular directive ngEnter

宣告 angular.module('app').directive('ngEnter', function() {         return function(scope, element, attrs) {             element.bind("keydown keypress", function(event) {                 if(event.which === 13) {                         scope.$apply(function(){                                 scope.$eval(attrs.ngEnter);                         });                                               event.preventDefault();                 }             });         }; }); 使用 <input type="text" ng-mode...

javascript checkbox 至少選擇一樣

function send() {   try { //取得元素 var obj = document.getElementsByName("souese"); //狀態 var flag = false; //是否有以選取項目 for (var i = 0; i < obj.length; i++) {  if (obj [i].checked) { flag = true; break;  } } //例外處理 if (!flag) {  throw "請至少選擇一項"; }   } catch (e) { //錯誤訊息 alert(e);   } }

gem sass ssl問題及解決

若安裝gem install sass有發生SSL憑證出錯可透過更換sourse的方式解決 //增加http的來源 gem source --add http://rubygems.org/ //移除https的來源 gem source --remove https://rubygems.org/ 之後就不會再碰到SSL相關的問題了,當然還是SSL好,但若開發環境不允許,也可以透過這樣修改 ref:https://stackoverflow.com/questions/40957368/gem-install-sass-error

jersey + swagger server basic setting

本段程式碼為jersey 配置swagger的配置方式

tomcat gzip setting

tomcat/conf/web.xml 在裡面找到此行 <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/> 修改為: <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla,traviata" compressableMimeType="text/html,text/xml,application/javascript,text/javascript,application/json,text/css,image/svg+xml" useSendfile="false" /> //啟用壓縮 compression="on" //最小壓縮大小 compressionMinSize="2048" //不支援壓縮的瀏覽器不壓縮 noCompressionUserAgents="gozilla,traviata" //需要壓縮的檔案格式 compressableMimeType="text/html,text/xml,application/javascript,text/javascript,application/json,text/css,image/svg+xml" //超過48k檔案預設不壓縮,需設定此參數強制壓縮 useSendfile="false" 強制壓縮的部分 是因為用scss作成一個main.js...

jdbc tomcat pool setting

在tomcat 設定tomcat jdbc pool需要作以下這幾件事情 1.在tomcat目錄下找到lib資料夾將mysql.jar(https://mvnrepository.com/artifact/mysql/mysql-connector-java)丟進去 2.配置web.xml相關參數請看https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes 3.配置context.xml 4.設定連結資料庫的LocalhostConnection檔 另外要自己件資料庫喔不然連不上(廢話) 設置web.xml Resource需設置在GlobalNamingResources內   <GlobalNamingResources>  <Resource  auth="Container"  driverClassName="com.mysql.jdbc.Driver"  url="jdbc:mysql://localhost:3306"  connectionProperties="characterEncoding=utf8;useUnicode=true;autoReconnect=true"  name="jdbc/localhost"  username="root"  password="1234"  minIdle="1"  initialSize="1"  maxIdle="40"  maxActive="50"  maxWait="30000"  minEvictableIdleTimeMillis="30000"  factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"  jdbcInte...