跳到主要內容

發表文章

目前顯示的是 12月, 2013的文章

透過Google Cloud Storage建置您的靜態網站

大家知道靜態網站的服務越來越先進,透過Github Page或是S3都可以快速的建置好可以提供服務的靜態網站,這次要介紹的是Google Cloud Storage上建置靜態網站的功能... 首先我們先準備一個美美的靜態網站,不少人可能想到用PC的網頁編輯器,我這邊是使用 Jetstrap 的雲端服務來拉出基本的版型: 左上方的 是提供下載專案的地方,下載之後可以解壓縮後看到裡面的html跟css相關檔案 接下來就是透過Google Cloud Storage來把這個些檔案變成一個網站囖,設定相當簡單... Step 1 : 在Google Cloud Storage建置您的domain bucket,並把相關檔案上傳到這個bucket裡面 這邊需要先有Cloud Platform Project,並且開通好Cloud Storage的服務,這邊不贅述這些設定... 我在這邊建立的是 gsweb.micloud.tw 這個網站,因此bucket用這個命名(這邊必須注意,Google會針對domain name進行認證,如果domain name非自己所屬,或被別人註冊了,將無法使用該domain name來建立bucket),並且將檔案上傳,主頁修改為index.html。 這邊完成後,仍需要在最右邊的"SHARED PUBLICLY"的地方勾選發佈,讓全世界的人可以看到您的網站... Step 2 : 透過gcutil將bucket變成一個網站 下面指令可以讓您設定一個bucket成為靜態網站,並且指定一個主頁,以及錯誤頁面,相關的help可以透過gsutil help setwebcfg來檢視... $ gsutil web set -m index.html -e 404.html gs:// gsweb.micloud.tw Step 3 : 設定Domain name CNAME對應 接下來您需要到您的DNS server上指定一筆CNAME記錄,將 yourdomain.com 對應到 c.storage.googleapis.com ,指定完成後,在nslookup的查詢會類似這樣: 這也表示您的網站應該已經生效了:

GCE porting recommandation

GCE是Google Cloud Platform上提供虛擬主機服務的一員,承襲了Google的強大,提供了無限量的環境與相當快速的網路, Management Portal 的操作設計也相當便捷,這邊有機會做一個PHP專案的Porting,順手針對Porting GCE上面的PHP程式做了個記錄,目標是Porting到一台CentOS主機,記錄的幾點注意事項,給大家參考: Install LAMP $ sudo yum  -y  install  httpd  php  php-mysql  mysql  mysql-server $ sudo yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt FW configure (GCE default enabled the iptables) $ sudo vi /etc/sysconfig/iptables ⇒ Add your port… link 80, 443... SELinux setting (GCE default enable the SELinux) $ sudo vi /etc/sysconfig/selinux ⇒ SELINUX=disabled Create persistence disk (GCE default root disk is only 10GB) $ df -h Filesystem      Size  Used Avail Use% Mounted on /dev/sda1       9.9G  9.9G     0 100% / tmpfs           1.8G     0  1.8G   0% /dev/shm $ sudo mkdir -p /mnt/pd0 $ ls -l /dev/disk/by-id/google-* lrwxrwxrwx. 1 root root  9 2013-12

開始建立一個Google Cloud Platform專案

預先準備:建立Google帳號 Step1: 連線到Google Cloud Platform Console https://cloud.google.com/console Step2: 建立Project Step3: 進入Project 進入Project後,就可以看到Google Cloud Platform的相關專案了唷∼

GAE using Objectify

Objectify是GAE Java的一個lightware IoC framework 透過Objectify可以達到與Spring相似的IoC功能 下面是操作Objectify的一些過程: Step1: Download Objectify library 下載網址: https://code.google.com/p/objectify-appengine/downloads/list 本文下載的是objectify 3.1版本的 Step2: Create Entity class Objectify是針對Entity Object來進行資料的存取動作,因此需要先建立Car的Entity類別 package com.mitac.objectify; import javax.persistence.Entity; import javax.persistence.Id ; @Entity public class Car {     @Id      String idx; // Can be Long, long, or String          String name;          public Car(String idx, String name) {     this.idx = idx;     this.name = name;     } }    Step3: Create service middleware 建立static class的middleware來作為呼叫Objectify的中介 package com.mitac.objectify; import com.googlecode.objectify.Objectify; import com.googlecode.objectify.ObjectifyFactory; import com.googlecode.objectify.ObjectifyService; public class OfyService {     static {         factory().register(Car.class);         //... etc     }     public stat

Apps Script取出Calendar API中的htmlLink

不死心的過客,一定覺得Apps Script怎麼可能做不到呢... 既然是加密的eid...那可能可以解密 透過Apps Script的Utilities類別,我們將上篇的htmlLink後面的eid欄位取出來分析 因為比較像Base64...我們採用Base64來做解密...(可以參考: https://developers.google.com/apps-script/reference/utilities/utilities#base64Decode(String,Charset) ) 下面試測試function... function test123(){   var o = 'ZTc0Mjk4OHVicHRrdHNjM.....RhYy5jb20udHc';   Logger.log(o);   var e = Utilities.base64Decode(o, Utilities.Charset.UTF_8);   Logger.log(Utilities.newBlob(e).getDataAsString()); } 執行後,果如預期... 分析如下: 透過分析,我們可以新增build htmlLink的function如下: function getHtmlLink(id, user) {   var ori = id.split('@')[0] + ' ' + user;   var enc = Utilities.base64Encode(ori, Utilities.Charset.UTF_8);   return ' https://www.google.com/calendar/render?action=VIEW&eid='+enc.replace('= ',''); } 然後call法可以向下面這樣... function getEvents(calId, startTime, endTime) {   if(!calId || !startTime || !endTime)     return {"error":"parameter error"};

透過Calendar API取得Calendar URI進入Calendar Event頁面

Google的Calendar API搭配Apps Script的使用如先前所介紹,非常方便... 但是如果想要透過Apps Script來建置可以提供點選後重導到特定Google Event的功能則有先天上的限制... 這是由於Google的Calendar頁面在點選Event時候,會在同一個視窗中動作 開啟Event是透過javascript的方式使用ajax非同步load Event資訊到頁面上呈現 而load這個資訊的重要關鍵資訊就是Calendar Event中的"htmlLink"欄位 如果透過之前介紹的Apps Script取出event物件來做應用的話 目前無法取出"htmlLink"欄位... 但是Google所發送的Calendar Remind信件中 卻使用了一個快速進入特定Event的方式的鏈結 下面文章在解密這個鏈結的資訊... 相信下面的信件不陌生吧 是Google Calendar提醒開會的資訊... 注意到框起來的地方了嘛... 他是一個這樣格式的URL: https://www.google.com/calendar/event?action=VIEW&eid= ZTc0Mjk4OHV...zdUBtaXRhYy5jb20udHc 而其中紅色的地方就是目前Apps Script取不到的欄位... 如何得到htmlLink呢?可以透過 Google API Explore 來查詢 在API Explore中,Calendar API提供了一個event list的function 填入您的calendar id就可以查得該calendar的所有行事曆事項 而calendar id可以在calendar的設定中找到 如果是account的預設行事曆,則會是使用account email作為calendar id... 送出查詢之後會得到下面的結果... 其中可以看到items中有所有的event列表 而event中有個htmlLink可以作為行事曆事件的代表網頁 點選該Link則可以直接轉址到該行事曆事件頁面 如下所示: 至於Apps Script無法取出htmlLink部分...只好提供意見給Google參考啦...

Google Cloud Platform 換了新 Logo...

Google Cloud Platform換了新的logo... 新的logo看起來更有提供大量主機運算的風味... 加上稍早Google Cloud Platform Blog所釋出的資訊:  "Google Compute Engine is now Generally Available with expanded OS support, transparent maintenance, and lower prices" 這次Google做足了十足的準備,想要在雲端的世界大展身手啦! 想要了解Google Cloud Platform的,可以趁這個機會好好研究一下唷!

批次匯入Google行事曆

在Google Apps的架構中,要透過App Script做到行事曆的批次匯入是相當簡單的事情 尤其以Admin帳號作批次import不同user的行事曆資訊 通常在第一次轉入時後相當重要... 下面展是透過Google Sheet統計好需要匯入的行事曆資訊 然後透過建立Sheet binding的Apps Script開發匯入的程式... 程式碼大約如下: /* 主程式,將會讀取sheet的資料,然後進行建立行事曆動作 */ function main() {   var sheet = SpreadsheetApp.getActiveSheet();   var rows = sheet.getDataRange();   var numRows = rows.getNumRows();   var values = rows.getValues();   for (var i = 1; i <= numRows - 1; i++) {     var row = values[i];     Logger.log(row);     createEvent(row[0], new Date(row[1]), new Date(row[2]), row[3], row[4], row[5])   } }; /* 建立行事曆'主程式,需要針對行事曆作subscribe,避免新進人員資訊無法閱讀出錯 */ function createEvent(calendarId, start, end, title, desc, loc) {   CalendarApp.subscribeToCalendar(calendarId);   var cal = CalendarApp.getCalendarById(calendarId);   var event = cal.createEvent(title, start, end, {       description : desc,       location : loc   });   cal.setHidden(true); }; Scrip