發表於 程式分享

windows及linux備份指定檔案-依清單檔

一、Windows
1.清單檔: listfile.txt

assets\js\plugin\bootstrap-datepicker.min.js
assets\js\plugin\js-xlsx.min.js
WEB-INF\lib\bcprov-jdk16-146.jar
WEB-INF\lib\commons-collections-3.2.1.jar
WEB-INF\lib\commons-lang-2.4.jar

2.備份Shell: backup.cmd

set backuppath=%cd%
set dd=%date:~8,2%
set dm=%date:~5,2%
set dy=%date:~0,4%
set mydate=%dy%%dm%%dd%

D:
cd D:\GWork\Source\workspace\testtadm\WebContent
"C:\Program Files\7-Zip\7z.exe" a -ttar %backuppath%\backup_%mydate%.tar @%backuppath%\listfile.txt

二、Linux
1.清單檔: listfile.txt

assets/js/plugin/bootstrap-datepicker.min.js
assets/js/plugin/js-xlsx.min.js
WEB-INF/lib/bcprov-jdk16-146.jar
WEB-INF/lib/commons-collections-3.2.1.jar
WEB-INF/lib/commons-lang-2.4.jar

2.備份Shell: backup.sh

NOW_PATH=`pwd`
NOW_TIME=`date +'%Y%m%d%H%M%S'`

cd /usr/local/tomcat/webapps/testweb
tar -cvf ${NOW_PATH}/backup_${NOW_TIME}.tar --files-from ${NOW_PATH}/listfile.txt 

PS.執行前請記得chmod +x backup.sh,讓shell檔為可執行狀態

發表於 程式分享

javascript console

今日在facebook看到有人介紹console.dir()及console.table(),
所以趕緊筆記下來
1.https://developer.mozilla.org/en-US/docs/Web/API/Console/table
2.https://developer.mozilla.org/en-US/docs/Web/API/Console/dir
之前在debug array object或json都覺得很麻煩,
沒想到有這麼方便的工具~

PS.雖然chrome的套件也不錯用
(chrome-extension://lhkmoheomjbkfloacpgllgjcamhihfaj/index.html)

發表於 程式分享

將MySql寫log檔功能關閉(MySql5.0)

1.至/etc/my.cnf
將以log=/var/log/mysql/mysql_log
調整為#log=/var/log/mysql/mysql_log
即off掉此功能

2.mysql -u [user] -p
輸入密碼後,輸入以下指令
show variables like ‘%log%’;
會顯示log功能已關閉

+---------------------------------+------------------------------+
| Variable_name                   | Value                        |
+---------------------------------+------------------------------+
...
| log                             | OFF                          |
發表於 程式分享

Minecraft模組設計-第一步

一、建立模組工具
1.JDK
2.Minecraft forge (http://files.minecraftforge.net/, Documents: http://mcforge.readthedocs.io/en/latest/)
3.Eclipse

二、下載forge
1) http://files.minecraftforge.net/  ==> Download Mdk file

download-Mdk.png

2) 解壓縮並複製以下檔案至Eclipse workspace新創建project (Ex. minecraft)
build.gradle
gradlew (both .bat and .sh)
gradle folder

3) Command line切換至 Eclipse workspace / 新創建project (Ex. minecraft)
執行 ./gradlew setupDecompWorkspace (in Mac)

command-1.png

command-2.png

…最後會看到Build SUCCESSFUL

command-3.png

發表於 程式分享

Mysql insert大量資料(使用spring + hibernate)

原本一筆筆資料insert,52萬筆花了3小時,
改用Mysql的LOAD DATA從產生csv檔到Load Data至新table只花了5分鐘不到,
範例如下,請參考~

public boolean runByAll(String userName, String tableName) {
   boolean bSuccess = false;
   String filePath = ...; //取得暫存檔路徑
   BufferedWriter writer = null;
        
   String fileNameWithPath = filePath + File.separator + fileName;
   File file = new File(fileNameWithPath);
   if (file != null && file.exists() == true) {
      boolean bDeleteOK = file.delete();
      if (bDeleteOK == false) {
     logger.warn("刪除舊資料- " +  fileNameWithPath + " 失敗.");
      }
   }
        
   //1.將來源資料寫入暫存檔案 : csv格式
   ServiceEntry serviceEntry = new ServiceEntry();  
   Session session = null;
   int iTotalRow = 0;       
   Date startDate = new Date();
   try {
      writer = new BufferedWriter(new FileWriter(fileNameWithPath));
      session = serviceEntry.getSessionforTrf();
      ScrollableResults table1Cursor 
     = session.createQuery("FROM " + tableName)
        .setReadOnly(true)
        .setCacheable(false)
        .setFetchSize(1000)
        .scroll(ScrollMode.FORWARD_ONLY);
      while (table1Cursor.next()) {
     Table1 table1 = (Table1) table1Cursor.get(0);
     iTotalRow++;
     Table1PK table1PK = table1.getTable1PK(); 
     String bufferStr 
            = SystemDateTime.getFmtDate(table1PK.getTxDate(), 
               "yyyy-MM-dd HH:mm:ss") + "," + table1PK.getStockId() + "," +
          table1.getStockName() + "," + table1.getToUp() + "," + 
              table1.getToDown() + "," + table1.getLastPrice() + "," + 
              table1.getuB() + "," + table1.getlB() + "," + 
          table1.getAvgPrice() + "," + 
              SystemDateTime.getFmtDate(startDate, "yyyy-MM-dd HH:mm:ss") + 
               "," + userName + "\n";
     writer.write(bufferStr);
                
     if (iTotalRow % 1000 == 0) {
        logger.info("count now : " + iTotalRow);
        session.flush();
        session.clear();
        writer.flush();
     }
      }
            
      session.close();  
      bSuccess = true;
      logger.info("原始資料共:" + iTotalRow);
   } catch (Exception e) {
      logger.error(e);
   } finally {
      serviceEntry.closeSessionforTrf(session);
      if (writer != null) {
         try {
        writer.close();
     } catch (IOException e) {
        logger.error(e);
     }
       }
   }
        
   if (bSuccess == false) {
      return bSuccess;
   }
    
   //大量資料寫入另一Table  
   ServiceEntry2 serviceEntry2 = new ServiceEntry2();   
   Session session2 = null;
   int dbRowCount = 0;
   try {
      //1) truncate table
      session2 = serviceEntry2.getSessionforTrf();
      session2.createSQLQuery("truncate table " + tableName).executeUpdate();
            
      //2) Load Data from csv File
      String sHql_load = "LOAD DATA LOCAL INFILE :filename " + 
        " INTO TABLE " + tableName + 
        " FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' " + 
        " (@var_TxDate, StockID, StockName, toUp, toDown, LastPrice, " +
                "  UB, LB, AvgPrice, @var_ModifyTime, ModifyEmp) " +
        " SET TxDate = STR_TO_DATE(@var_TxDate,'%Y-%m-%d %H:%i:%S'), " +
        " ModifyTime = STR_TO_DATE(@var_ModifyTime,'%Y-%m-%d %H:%i:%S');";
      Query query_load = session2.createSQLQuery(sHql_load)
                                 .setString("filename", fileNameWithPath);
      dbRowCount = query_load.executeUpdate();
      bSuccess = (dbRowCount == iTotalRow) ? true : false;
   } catch (Exception e) {
      logger.error(e);
      bSuccess = false;
   } finally {
      serviceEntry.closeSessionforTrf(session2);
   }
        
   return bSuccess;
}       

Ref.http://www.codedata.com.tw/database/mysql-tutorial-19-outfile-dump-infile-import/