最近的再處理有關Go 時間格式的問題,覺得沒有一隻小function 可以幫忙處理時間字串很麻煩
所以寫了一隻小function來用
參數說明:
Y:2009 //Year
y:09 //Year
M:01 //Month
m:1 //Month
D:02 //Date
D:2 //Date
H:15 //Hour
I:04 //Minute
i:4 //Minute
s:03 //Second
code 位置:
https://gist.github.com/matishsiao/bf3bfa9f13c9eaff2750
2015年8月24日 星期一
2015年8月21日 星期五
產生Go API Document
因為公司的關係接觸了Go lang,現在目標每天分享一篇關於Go的資訊
第一篇就是
https://engineroom.teamwork.com/generate-api-from-annotations-in-go/?utm_source=golangweekly&utm_medium=email
這主要是可以產生API document,方便文件管理,不過我自己還沒時間測試
我也會分享在Facebook Group :Golang Gopher Taiwan
第一篇就是
https://engineroom.teamwork.com/generate-api-from-annotations-in-go/?utm_source=golangweekly&utm_medium=email
這主要是可以產生API document,方便文件管理,不過我自己還沒時間測試
我也會分享在Facebook Group :Golang Gopher Taiwan
2013年8月20日 星期二
mongo DB 用途
最近因為公司專案的需求,所以認真地看完mongoDB官方出的書(中文版的~XD)
下面是我覺得適合使用mongo DB的用途跟優缺點
mongo DB 用途
1.資料是弱關聯的
2.需要大量寫入資料
優點:
1.高效能(在弱關聯下)
2.寫入及查詢速度都不錯
3.類似SQL語法操作,但是還是function base,不過概念上是相同的
4.有(master + slave), (master + master), (replica set)備份方式
缺點:
1.需要配置大量記憶體空間
2.需要配置大量硬碟空間,資料庫會預支空間,所以有些時候會有空間浪費的狀況
下面是我覺得適合使用mongo DB的用途跟優缺點
mongo DB 用途
1.資料是弱關聯的
2.需要大量寫入資料
優點:
1.高效能(在弱關聯下)
2.寫入及查詢速度都不錯
3.類似SQL語法操作,但是還是function base,不過概念上是相同的
4.有(master + slave), (master + master), (replica set)備份方式
缺點:
1.需要配置大量記憶體空間
2.需要配置大量硬碟空間,資料庫會預支空間,所以有些時候會有空間浪費的狀況
結論:
如果要做data mining相關的處理,就不適合用mongo DB,原因是因為mongo DB的高效能只對弱關聯有用,如果用了很多關聯的功能,效能會嚴重低落~Orz
mongo DB網址:
http://docs.mongodb.org/
mongo DB網址:
http://docs.mongodb.org/
2013年7月24日 星期三
PHP 內建的樣板引擎
最近剛好在研究PHP的樣板引擎,發現到原本PHP其實就可以做樣板引擎
他主要的原理是透過輸出緩衝資料的Buffer做資料組合,轉換成HTML格式
下面是自己測試的PHP檔:
------------------------------------------------------------------
coreTemplate.php 組合樣板用的類別
------------------------------------------------------------------
<?php
class CoreTemplate{
/**組合樣板資料
* @param $template 樣板路徑
* @param $data 導入到樣板的資料變數(樣板的PHP檔須從這個變數取得所需資料)
* @return 組合完成的資料
*/
function render($template, $data) {
ob_start();
include $template;
$result = ob_get_contents();
ob_end_clean();
return $result;
}
}
?>
------------------------------------------------------------------
test.tpl.php 樣板的php程式碼
------------------------------------------------------------------
<html>
<head>
<title>Test</title>
</head>
<body>
<table>
<tr>
<td>ID</td><td>Name</td>
</tr>
<!-- PHP 樣板文字 $data為coreTemplate所設定的資料變數名稱-->
<?php foreach($data as $list): ?>
<tr>
<td><?=$list['id']?></td><td><?=$list['name']?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
------------------------------------------------------------------
test.php 程式邏輯跟輸出
------------------------------------------------------------------
<?php
include_once("coreTemplate.php");
$ct = new CoreTemplate();
$info = array();
//產生10筆資料
for($i = 0; $i < 10;$i++){
array_push($info, array('id'=>$i, 'name'=>'name'. $i));
}
//輸出HTML
echo $ct->render('test.tpl.php' , $info);
?>
----------------------------------------------------------------------
輸出結果
----------------------------------------------------------------------

結論:
這次的實驗主要只是看php做樣板引擎的方法而已,真正要自己實作應該也會需要時間
所以還是用Smarty做樣板引擎~XD!
他主要的原理是透過輸出緩衝資料的Buffer做資料組合,轉換成HTML格式
下面是自己測試的PHP檔:
------------------------------------------------------------------
coreTemplate.php 組合樣板用的類別
------------------------------------------------------------------
<?php
class CoreTemplate{
/**組合樣板資料
* @param $template 樣板路徑
* @param $data 導入到樣板的資料變數(樣板的PHP檔須從這個變數取得所需資料)
* @return 組合完成的資料
*/
function render($template, $data) {
ob_start();
include $template;
$result = ob_get_contents();
ob_end_clean();
return $result;
}
}
?>
------------------------------------------------------------------
test.tpl.php 樣板的php程式碼
------------------------------------------------------------------
<html>
<head>
<title>Test</title>
</head>
<body>
<table>
<tr>
<td>ID</td><td>Name</td>
</tr>
<!-- PHP 樣板文字 $data為coreTemplate所設定的資料變數名稱-->
<?php foreach($data as $list): ?>
<tr>
<td><?=$list['id']?></td><td><?=$list['name']?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
------------------------------------------------------------------
test.php 程式邏輯跟輸出
------------------------------------------------------------------
<?php
include_once("coreTemplate.php");
$ct = new CoreTemplate();
$info = array();
//產生10筆資料
for($i = 0; $i < 10;$i++){
array_push($info, array('id'=>$i, 'name'=>'name'. $i));
}
//輸出HTML
echo $ct->render('test.tpl.php' , $info);
?>
----------------------------------------------------------------------
輸出結果
----------------------------------------------------------------------

結論:
這次的實驗主要只是看php做樣板引擎的方法而已,真正要自己實作應該也會需要時間
所以還是用Smarty做樣板引擎~XD!
2013年6月27日 星期四
Flash Develop AS3語法檢查問題
- Syntax checking process starting: java -Duser.language=en -Duser.region=US -classpath "C:\Program Files\FlashDevelop\Tools\flexsdk\lib\asc.jar;C:\Documents and Settings\Administrator\Local Settings\Application Data\FlashDevelop\Data\AS3Context\Flex4Shells.jar" AscShell
在使用FD的時候會發生AS3語法無法檢查的警告
解決方式:
1.確認是否有安裝java
2.如果有安裝java,確定系統變數PATH有設定JDK的BIN目錄位置,沒有就補設定進去就可以!
2013年4月25日 星期四
AS3 Sound管理
自己寫的AS3 sound音效物件
用法:
// 建立音效物件,如果播放完畢要做處理的話,可以加入cbFunc
var audio:Audio = new Audio(cbFunc);
//撥放AS連結的音效檔
audio.playSound("test.mp3");
//重複播放
audio.repeat = true;
//設定音量(0~1)
audio.setSoundVolume(0.5);
程式碼
------------------------------------------------------------------------------------------------
package com.matis.media
{
import flash.events.Event;
import flash.media.*;
import flash.utils.getDefinitionByName;
public class Audio
{
private var snd:Sound = new Sound();
private var sndCh:SoundChannel;
private var audio:Object;
private var soundVolume:Number;
public var repeat:Boolean;
public var mute:Boolean;
private var parent:Sprite;
private var callback:Function;
private var sndName:String;
public function Audio(_cb:Function)
{
callback = _cb;
setSoundVolume();
}
public function setSoundVolume(_soundVolume:Number = 0.7):void{
soundVolume = _soundVolume;
if(sndCh != null){
var stf:SoundTransform = sndCh.soundTransform;
stf.volume = soundVolume;
sndCh.soundTransform = stf;
}
}
public function stop():void{
if(sndCh != null)
sndCh.stop();
}
public function play(_repeat:Boolean = false):void{
repeat = _repeat;
if(sndCh != null){
sndCh = snd.play(0,1);
sndCh.addEventListener(Event.SOUND_COMPLETE , onPlayOver);
}
}
private function onPlayOver(e:Event):void{
if(repeat){
if(sndCh != null){
sndCh = snd.play(0,1);
var stf:SoundTransform = sndCh.soundTransform;
stf.volume = soundVolume;
sndCh.soundTransform = stf;
sndCh.addEventListener(Event.SOUND_COMPLETE , onPlayOver);
}else
trace("sndCh == null");
}
if(callback != null)
callback();
}
/**撥放音效
* @param sndId 音效類別名稱
* */
public function playSound(sndId:String):void{
if(!mute){
if(sndCh != null && sndName == sndId){
sndCh.stop();
sndCh.removeEventListener(Event.SOUND_COMPLETE , onPlayOver);
sndCh = snd.play(0 , 1);
var stf:SoundTransform = sndCh.soundTransform;
stf.volume = soundVolume;
sndCh.soundTransform = stf;
sndCh.addEventListener(Event.SOUND_COMPLETE , onPlayOver);
}else
setSound(sndId);
}else{
if(sndCh != null)
sndCh.stop();
}
}
public function setSound(sndId:String):void{
var LoadClass:Class = getDefinitionByName(sndId) as Class;
sndName = sndId;
if(LoadClass != null){
var sndObj:Sound = Sound(new LoadClass());
if(sndObj != null){
snd = sndObj;
sndCh = snd.play(0,1);
sndCh.addEventListener(Event.SOUND_COMPLETE , onPlayOver);
var stf:SoundTransform = sndCh.soundTransform;
stf.volume = soundVolume;
sndCh.soundTransform = stf;
}else
trace("Audio","Not found:" + sndId + "讀取音效資源為空值.");
}else{
trace("資源名稱:" + sndId + " 讀取音效資源檔失敗.");
}
}
}
}
2013年4月3日 星期三
訂閱:
文章 (Atom)