星期四, 4月 17, 2014

在 Mac 遠端桌面連線到另一部 Windows 電腦

首先要釐清一點:有兩個微軟出的應用程式,「Remote Desktop Connection Client for Mac」和「Microsoft Remote Desktop」,他們是不同的。前者已經是舊物了,後者有在 Mac App Store 上架,推薦使用。
第一次使用 Microsoft Remote Desktop 遇到個算嚴重的問題,分享 Mac 的目錄竟然不會出現在 Windows 檔案總管?原來分享的名稱是有關係的,Desktop 不行,myDesktop 就可以。

星期二, 4月 15, 2014

查詢 NuGet 套件的所有可下載版本

在 Visual Studio 2010 以後,使用 NuGet 做為套件管理是比較好的做法。但官網上永遠只有一個穩定版,頂多再一個預先釋出版,有時候是不符現實需求的。其實這種一加一的版本限制只在圖形介面,若使用 Package Manager Console 下指令還是可以突破的。不過以下這招實測無效,曾有人回報過是官網的問題:

Get-Package -ListAvailable -Filter <keyword> -AllVersions

以下這個是目前可行的變通做法:

Install-Package <PackageId> -Version〔空格〕〔定位鍵〕

如果只是查詢不要安裝,最後不要按 Enter 就好了。

[2014/08/12]

過去實測無效的指令,如今試來是可以的。

IIS 7.5 虛擬帳戶問題

IIS 7.5 以後,預設使用 ApplicationPoolIdentity 這個身分執行應用程式集區。有許多文章提到將實體目錄授權給這個身分的方法:
  1. 在檔案總管對該目錄按右鍵,選「Properties」、「Security」、「Edit」、「Add」。
  2. 確認「Locations」的內容是本機電腦名稱。
  3. 假設應用程式集區名稱是 DefaultAppPool,在文字方塊內輸入 IIS AppPool\DefaultAppPool,再按「Check Names」,如果名稱解析成功,會有底線。
  4. 賦予讀取權限。
以上都完成後,還是有可能看不到網頁,此時請檢查:
  1. 伺服器、應用程式集區、網站等是否啟動。
  2. 網址不完整時,是否有匹配的預設文件。
  3. 如果接受匿名驗證,匿名使用者對應的身分是否就是 ApplicationPoolIdentity。

星期一, 3月 31, 2014

Ubuntu 12.04 OpenLDAP nodomain

依據這篇說明的做法,在 Ubuntu 12.04 安裝的 OpenLDAP 會參考 /etc/hosts 所設的網域名稱,但實際的結果卻是無效?不論怎麼設,網域名稱都是 nodomain。後來找到解法如下:
http://superuser.com/questions/470825/openldap-slapd-conf-substitutions-ubuntu

星期四, 3月 27, 2014

Minimum JNDI-JDBC requirement

在 Eclipse + Tomcat,做一個最小需求的 JNDI JDBC 連線測試環境:
  1. sqlite jdbc jar
  2. context.xml
  3. web.xml
  4. 部署位置
  5. NewFile.jsp
<%@ page import="java.util.*" %>  
<%@ page import="java.sql.*" %>  
<%@ page import="javax.sql.*" %>  
<%@ page import="javax.naming.*" %>  
<%@ page language="java" contentType="text/html;charset=UTF-8" %>  
<%
Object o = session.getAttribute("m");
HashMap<String, Connection> m = null;
if (o == null) {
m = new HashMap<String, Connection>();
}
else {
m = (HashMap<String, Connection>)o;
}
  Connection con = null;
  try {
  Context initContext = new InitialContext();
  if (initContext == null) {
  out.println("initContext null");
  } else {
  Context envContext = (Context) initContext.lookup("java:/comp/env");
  if (envContext == null) {
  out.println("envContext null");
  } else {
  DataSource ds = (DataSource) envContext.lookup("jdbc/myDataSource");
  if (ds == null) {
  out.println("ds null");
  } else {
  // get connection
  String parameterGet = request.getParameter("get");
  if (parameterGet == null) {
  }
  else {
  int newCount = m.size() + 1;
  while (true) {
  con = ds.getConnection();
    String connectionId = String.valueOf(con.hashCode());
    m.put(connectionId, con);
    if (m.size() == newCount) {
      session.setAttribute("m", m);
    break;
    }
  }
  }
  // close connection
  String parameterClose = request.getParameter("close");
  String pool = request.getParameter("pool");
  if (parameterClose == null || pool == null) {
  }
  else {
  Iterator<Map.Entry<String, Connection>> iter = m.entrySet().iterator();
  while (iter.hasNext()) {
      Map.Entry<String, Connection> entry = (Map.Entry<String, Connection>) iter.next();
      String key = entry.getKey();
if (key.equals(pool)) {
m.remove(key);
session.setAttribute("m", m);
break;
}
  }
  }
  }
  }
  }
  } catch (SQLException sqle) {
  out.println("sqle=" + sqle);
  } finally {
  if (con == null) {
  } else {
  con.close();
  con = null;
  }
  }
  %>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Insert title here</title>
</head>
<body>
<form>
<div>Connection Pool:</div>
<select name="pool" size="10">
<%
Iterator<Map.Entry<String, Connection>> iter = m.entrySet().iterator();
while (iter.hasNext()) {
    Map.Entry<String, Connection> entry = (Map.Entry<String, Connection>) iter.next();
    String key = entry.getKey();
    out.println("<option>" + key + "</option>");
}
%>
</select>
<div>
<input type="submit" name="get" value="get" />
<input type="submit" name="close" value="close" />
</div>
</form>
</body>

</html>

星期四, 2月 27, 2014

在 Eclipse 快速建立 Spring Web 專案

這件事可能很簡單,但網路上竟然也找不到類似的文章。多方嘗試後,發現這種做法最乾淨俐落:
  1. 建 Dynamic Web 專案。
  2. 轉換成 Maven 專案。
  3. 需要參考外界的 Jar 時,一律透過 Maven Repository,也就是先上網找好 Maven 的 GroupId、ArtifactId、Version 等,這裏麻煩一點,未來好處多多。
  4. 用 Maven Clean、Maven Install 取代 Build。