2014年12月11日 星期四

C#頁簽-TabControl-跳到指定頁簽



設定事件:
name:tcl_LRX1
SelectedIndexChang:tcl_LRX1_SelectedIndexChanged


private void tcl_LRX1_SelectedIndexChanged(object sender, EventArgs e)
{
   ...
   this.tcl_LRX1.SelectedIndex = 1; //指定要跳到頁簽的index
}

2014年12月1日 星期一

angularJS 簡單sample


<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<script type="text/javascript" src="js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/angularJS/angular.js"></script>
<script language="JavaScript" type="text/javascript">

function fruitControl($scope) {
$scope.fruitModel = [{id:1,fruitName:'apple',fruitPrice:5},
                    {id:2,fruitName:'banana',fruitPrice:10},
                    {id:3,fruitName:'orange',fruitPrice:8},
                    {id:4,fruitName:'peach',fruitPrice:20}];

$scope.fruitList = $scope.fruitModel[0];

$scope.discount = 1;
}

</script>

</head>
<body>

<span ng-controller="fruitControl">
水果:<select ng-model="fruitList" ng-options="fruit.fruitName for fruit in fruitModel"></select>
折扣:<input type="radio" ng-model="discount" value="0.25"/>25折
<input type="radio" ng-model="discount" value="0.5"/>5折
<input type="radio" ng-model="discount" value="0.75"/>75折
<div ng-switch on="fruitList.fruitName">
<div ng-switch-when="apple">apple is {{fruitList.fruitPrice * discount}} dollars.</div>
<div ng-switch-when="banana">banana is {{fruitList.fruitPrice * discount}} dollars.</div>
<div ng-switch-when="orange">orange is {{fruitList.fruitPrice * discount}} dollars.</div>
<div ng-switch-when="peach">peach is {{fruitList.fruitPrice * discount}} dollars.</div>
</div>
</span>

</body>
</html>

2014年11月30日 星期日

struts2 + jquery ajax 簡單範例


使用版本:
jquery-1.8.2.min.js
struts2-core-2.1.8.1.jar
struts2-json-plugin-2.1.8.1.jar


JSP:

<select id="itemList" name="itemList" onchange="changeItem()">
<option value="0">請選擇</option>
<option value="1">apple</option>
<option value="2">banana</option>
<option value="3">orange</option>
<option value="4">peach</option>
</select>
<br/>
項目名稱:<input type="text" id="itemName" name="itemName" />


Javascript:

<script type="text/javascript" src="js/jquery/jquery-1.8.2.min.js"></script>
<script language="JavaScript" type="text/javascript">

function changeItem() {
var itemVal = $("#itemList").val();
var data = {"itemVal" : itemVal};

$.ajax({
        url:'index!queryItemList',
        type:'POST',
        data: data,
        dataType:'json',
        success:function (data) {
//             alert(JSON.stringify(data));
            $("#itemName").val(data.itemName);
        }
    });
}

</script>



struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="prcdefault" extends="json-default">
<action name="index" class="com.prc.action.IndexAction">
<result name="success">/pages/success.jsp</result>
<result name="jsonResult" type="json"></result>
</action>
</package>
</struts>


Action:

private String itemVal;
private String itemName;
public String getItemVal() {
return itemVal;
}
public void setItemVal(String itemVal) {
this.itemVal = itemVal;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}

public String queryItemList() {
if("1".equals(itemVal)) {
itemName = "apple";
} else if("2".equals(itemVal)) {
itemName = "banana";
} else if("3".equals(itemVal)) {
itemName = "orange";
} else if("4".equals(itemVal)) {
itemName = "peach";
} else {
itemName = "none";
}

return "jsonResult";
}


2014年11月28日 星期五

html 父網頁 子網頁溝通

1.子視窗傳值至母視窗
   <script language=javascript>
    function name(name) {
   var name;
   window.opener.document.getElementById('school_name').value = name;
     }
   </script>

2.子視窗傳值呼叫母視窗函式


 <script language=javascript>
    function name(name) {
 window.opener.outside(name);//標紅字體則為母視窗的javascript的函式
   }
</script>


------------------------------------------------------------------------------------------------

testopener.html:

<script language="JavaScript" type="text/javascript">
var subwinId;

function openTest() {
subwinId = window.open('testSub.html?msg=hi');
}

function sendValueToParent() {
var s = subwinId.document.getElementById("submsg");
s.innerHTML = "Done!";
}

function reloadSubWindow() {
subwinId.reloadSubWindow();
}

function closeSubWindow() {
subwinId.close();
}

</script>
</head>

<body >
<input type="button" id="checkButton" value="送出" onclick="openTest()">
<br/>
<input type="button" id="sendButton" value="送值給子視窗" onclick="sendValueToParent()">
<br/>
<input type="button" id="sendButton" value="reload子視窗" onclick="reloadSubWindow()">
<br/>
<input type="button" id="sendButton" value="關閉子視窗" onclick="closeSubWindow()">
<br/>
回傳值:<div id="parentMessageId"></div>
</body>





testSub.html:

<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
var msg = Request["msg"];
$("#submsg").text(msg);
alert("reloadSubWindow");
});
var url=location.search;
  var Request = new Object();
  if(url.indexOf("?")!=-1)
  {
   var str = url.substr(1) //去掉?號
   strs = str.split("&");
   for(var i=0;i<strs.length;i++)
   {
   Request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
   }
  }
  
function reloadSubWindow(){
location.reload();
}
</script>
</head>
<body >
<div id="submsg"></div>
</body>




參考網址:
http://tc.wangchao.net.cn/bbs/detail_553964.html

http://crazy.molerat.net/learner/cpuroom/homepage/reading.php?filename=97102215523.dov



2014年10月16日 星期四

java.net.SocketException: Too many open files


情況:
linux環境在沒動過任何code情況下,只有資料量變多,在執行下面程式時會噴
java.net.SocketException: Too many open files


原code:

StringBuffer sb = new StringBuffer();

String templatePath = PropertiesUtil.getProperty("MAIL_NOTICE_TEMPLATE_DONATE_PATH_IN_CLASSPATH");

InputStreamReader isr = new InputStreamReader(NoticeUtil.class.getResourceAsStream(templatePath));

BufferedReader br = new BufferedReader(isr);

String tmp = null;
try {
while((tmp = br.readLine()) != null) {
sb.append(tmp);
}
} catch (IOException e) {
log.error("讀取Notice html發生錯誤 for Award Invoic");
e.printStackTrace();          
return "";
}


Map<String, String> map = new HashMap<String, String>();
for (Iterator<AwardInvoice> it = aiList.iterator(); it.hasNext();) {
AwardInvoice ai = it.next();
map.put(ai.getPrizeType(), getPrizeInChinese(ai.getPrizeType()));
}




後來查一下之後發現可用 ulimit -a這指令查看目前系統資訊
 ulimit -a


core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 131072
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 4096
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 131072
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


可重新設定開啟檔案數
ulimit -n 8192

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 8192
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16382
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited




但想一想這或許不是解決辦法,後來又仔細看了一下code,發現下面兩行,使用完後沒有close掉,所以就試看看改成

InputStreamReader isr = new InputStreamReader(NoticeUtil.class.getResourceAsStream(templatePath));

BufferedReader br = new BufferedReader(isr);



修改後的code加了close:


StringBuffer sb = new StringBuffer();
String templatePath = PropertiesUtil.getProperty("MAIL_NOTICE_TEMPLATE_DONATE_PATH_IN_CLASSPATH");
InputStreamReader isr = new InputStreamReader(NoticeUtil.class.getResourceAsStream(templatePath));
BufferedReader br = new BufferedReader(isr);
String tmp = null;
try {
while((tmp = br.readLine()) != null) {
sb.append(tmp);
}
} catch (IOException e) {
log.error("讀取Notice html發生錯誤 for Award Invoic");
e.printStackTrace();          
return "";
} finally {
try {
br.close();
isr.close();
} catch (IOException e) {
e.printStackTrace();
}
}


再重新執行一次就沒噴了,以前學習時雖然都說要close覺得好像沒關程式也都可以run,就想
說有沒有關可能都沒差,結果在資料量大的時候沒關,果然還是有差

所以以後還是要記得close



2014年9月30日 星期二

框架本質

看到了別人寫的一篇有關"框架"的文章,看完覺得寫得很好,怕忘記所以在這邊記一些重

點。

會有框架的出現在於"為了解決在軟體開發過程中重複的流程"。

每個框架的實作必然支持某個架構與流程,這是框架要解決本質性的ˊ問題,但由於框架作為

一種工具,本身必然也會帶來也些附屬的問題。所以在使用框架必先辨識框架要解決的流程

本質,並對即將被導入框架的系統有通盤瞭解,方可評估採用後的價值,是否超越隨著框架

附屬而來的繁複設定。


Brooks書中亦談到:「軟體建構中本質的部份,指的是概念的智能創作,而附屬的部份,指

的是實作程序。」在開發軟體的過程中,有時會發現解決軟體中某些問題時,創造出的方法

概念具有某種程度的相似性或交集,若對類似概念重複進行實作,重複耗費的附屬性成本著

實是種浪費,因而在實作類似概念時考量了彈性與通用性,使得後續軟體開發中出現類似的

智能創作時,可以直接套用先前既有成品,避免一再重複的實作程序,而這個既有的成品就

是框架。



避免框架附屬困難模糊應用焦點


有些框架一開始會有組態不便或設定複雜的問題,然而,這些附屬的困難度,可隨著輔助工

具的推出、框架的改版、新的組態媒介,而降低甚至消失。

過於將學習或使用重點放在框架的附屬性困難上,會對理解框架本質造成阻礙,只是學會那

些將來可能不再適用的API組裝並不值得炫耀,也不應自認為懂得如何完成複雜組態設定而洋

洋自得,畢竟那並非框架存在的真正意義

















參考的文章來自於
http://www.ithome.com.tw/node/77201

FileZilla過濾器


當要從server上下載code時,發現裡面很多資料夾都有.svn,版本控管的東西,所以當不想把這些東西也從server上抓下來時,就可以使用FileZilla的過濾器,過濾掉這些東西,只抓需要的code。

點選檔名篩選器



勾選遠端篩選器的CVS and SVN directories,再點選編輯篩選規則




接著點選左邊的CVS and SVN directories,然後再把檔案目錄都打勾,並可以透過新增更多項目及移除所選項目去設定要過濾的規則。



接著按確認,下載code時就可以避掉.svn的東西了。




Linux常用指令

ps 指令

ps aux
觀察系統所有的程序資料

ps -l
僅列出與你的操作環境 (bash) 有關的程序而已

ps -A
ps-e
所有的process均顯示出來

ps -f
顯示更完整的process輸出


finde 指令

find /var/log -iname '*.log' -type f
指定只要搜尋「檔案」名稱

find /etc -iname 'apache2' -type d
指定只要搜尋「目錄」名稱

2014年9月18日 星期四

SQL create table

postgresql:

建立table:

CREATE TABLE PUB_CARRIER
  (
    PUBLIC_CARRIER_ID NUMERIC NOT NULL,
    CREATE_DATE DATE DEFAULT 'now',
    TRANSACTION_ID   VARCHAR(18) NOT NULL ,
    CARRIER_ID1      VARCHAR(64),
    SEQ              NUMERIC(10,0) DEFAULT 0 ,
    EMAIL            VARCHAR(100),
    PRINTMARK        NUMERIC(2,0) DEFAULT 0 ,
    PRINT_DATATIME DATE,
    PUBLIC_CARRIER_STATUS VARCHAR(10) DEFAULT '00' ,
    EMAIL_INV   VARCHAR(1),
    EMAIL_NOWIN VARCHAR(1)
  )


建立primary key:

ALTER TABLE AWARD_INVOICE ADD PRIMARY KEY (SERIAL_NUMBER);


取得當月最後一天


JAVA:

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd");
Calendar calendar = Calendar.getInstance();

        System.out.println("today="+sdf.format(calendar.getTime()));
        calendar.add(Calendar.MONTH,1); //Calendar.MONTH 加上1個月(用add    Method)
        System.out.println("nextMonthDay="+sdf.format(calendar.getTime()));
        //第一天
        System.out.println("nextMonthFrist="+sdf.format(getFirstMonthDay(calendar)));
        //最後一天
        System.out.println("nextMonthLast="+sdf.format(getLastMonthDay(calendar)));

}

//每個月的第一天日期
 public static Date getFirstMonthDay(Calendar calendar) {
        calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
        return calendar.getTime();
 }

 //每個月的最後一天日期
 public static Date getLastMonthDay(Calendar calendar) {
        calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
        return calendar.getTime();
 }




Javascript:

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


function showWeekFirstDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
alert(WeekFirstDay.Format("yyyy-MM-dd"))
}

function showWeekLastDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
alert(WeekLastDay.Format("yyyy-MM-dd"))
}

function showMonthFirstDay()
{
var Nowdate=new Date();
var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);
alert(MonthFirstDay.Format("yyyy-MM-dd"))
}

function showMonthLastDay()
{
var Nowdate=new Date();
var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth()+1,1);
var MonthLastDay=new Date(MonthNextFirstDay-86400000);
alert(MonthLastDay.Format("yyyy-MM-dd"))
}






Oracle sql:

select extract(day from last_day(sysdate)) from dual;


SELECT a.HSN_CD,
  a.ITEM_CD,
  A.Item_Nm,
  DECODE(a.ITEM_VAL,'*', to_char(extract(day from last_day(sysdate))) , A.Item_Val) ITEM_VAL,
  A.Item_Cntnt ,
  NVL(B.Hsn_Nm, '共通') Hsn_Nm
FROM TABLENAMEA a
LEFT JOIN TABLENAMEB b
On A.Hsn_Cd    = B.Hsn_Cd
Where A.Hsn_Cd = 'A';





2014年9月16日 星期二

apache Velocity 練習

練習專案的架構:


VelocityBaseTest.java:


package com.demo.test;

import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class VelocityBaseTest {

public static void main(String[] args) {
try {
   //也可使用properites設定,這邊練習不需要
//Velocity.init("properties/velocity.properties");
// 取得velocity上下文
VelocityContext context = new VelocityContext();
context.put("name", "Daniel");

Template template = Velocity.getTemplate("template/hello.vm");
StringWriter writer = new StringWriter();
template.merge(context, writer);

PrintWriter filewriter = new PrintWriter(new FileOutputStream(
"outputTemplate/hello.html"), true);
filewriter.println(writer.toString());
filewriter.close();

} catch (Exception e) {
e.printStackTrace();
}
}
}


hello.vm:

<html>
    <head></head>
    <body>
        HELLO! $name,Welcome to velocity!
    </body>
</html>


Velocity.properties:

#Velocity.properties配置示例
# 如果需要系統從WEB-INF/classes路徑載入Velocity的範本檔,取消下兩行的注釋
#resource.loader=class
#class.resource.loader.class=org.apache.Velocity.runtime.resource.loader.ClasspathResourceLoader
#如需禁止系統通過檔案系統載入範本檔,注釋如下兩行
resource.loader=file
file.resource.loader.path=D:\practice\VJ\workspace\velocitytest\template
#確定從何處載入velocity的範本檔
file.resource.loader.cache=false
input.encoding=gb2312
output.encoding=gb2312



產出的檔案:
hello.html:

<html>
    <head></head>
    <body>
        HELLO! sea,Welcome to velocity!
    </body>
</html>







2014年9月13日 星期六

JAVA Process簡單應用


*java如果要執行exe或bat可執行檔,可以利用 Runtime.getRuntime().exec("xxx.exe")來執行,如下就可以啟動jmeter。

Process process = Runtime.getRuntime().exec("D:/JMeter/apache-jmeter-2.9/bin/jmeter.bat");

*可利用下面語法看到目前作業系統
System.out.println(System.getProperty("os.name"));


練習使用JAVA 在目前正在執行 process 裡找到特定的process,並找到pid kill掉。


範例:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExcuteTest {

public static void main(String[] args) {
try {
Process process = Runtime.getRuntime().exec("tasklist");
int taskId = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(
process.getInputStream(), "MS950"));

String line = null;
while ((line = br.readLine()) != null) {
if (line.indexOf("Skype.exe") != -1) {
line = line.substring( "Skype.exe".length() );
System.out.println(line.trim());
       taskId = Integer.parseInt( (line.trim().split( " " ))[0] );

       System.out.println( "Task Id: " + taskId );
}
}
Runtime rt = Runtime.getRuntime();
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
System.out.println("taskkill......." + taskId);
rt.exec("tskill " + taskId);
} else {
System.out.println("kill -9 ......." + taskId);
rt.exec("kill -9 " + taskId);
}
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}

繼承練習-形狀(圓形繼承橢圓、橢圓繼承圓形、都不繼承或著...)



Shape.java:

public interface Shape {

public double area();

public void display();
}


RoundShape.java:

public class RoundShape implements Shape {

private int radius1;

private int radius2;

public RoundShape(int radius1,int radius2) {
this.radius1 = radius1;
this.radius2 = radius2;
}

@Override
public double area() {
return radius1 * radius2 * 3.14;
}

@Override
public void display() {
System.out.println("draw and display...");
}
}

Circle.java:

public class Circle extends RoundShape {

public Circle(int radius) {
super(radius, radius);
}
}

Ellipse.java:

public class Ellipse extends RoundShape {

public Ellipse(int radius1, int radius2) {
super(radius1, radius2);
}
}

UserTest.java:

public class UserTest {
public static void main(String[] args) {
Circle circle = new Circle(10);
System.out.println(circle.area());

Ellipse ellipse = new Ellipse(5,10);
System.out.println(ellipse.area());
}
}




2014年9月11日 星期四

安裝JDK8後 ireport 無法啟動

裝JDK8時裝好時,至cmd下java -version會發現原來的jdk版本設定會變成jdk8。


然後去環境變數看發現path多了一段"C:\ProgramData\Oracle\Java\javapath;"






將此段拿掉就可以恢復原來JDK的設定了。





安裝完JDK8時,悲劇發生了ireport(版本4.7.0)啟動不起來了,找了一下資料後,發現ireport好像還不支援JDK8,所以網路的解法是去修改ireport的設定檔,我本機的路徑是在
"E:\ireport\iReport-4.7.0\etc"底下有個ireport.conf。在設定檔新加一段 jdkhome="C:/Program Files/Java/jdk1.7.0_60",設定好之後ireport就可以正常啟動了。









將從svn check out的程式裡的.svn資料夾刪除

從svn取下的程式會有.svn這資料夾,放的是一些svn上的版本資訊,但如果不需要這些.svn這些資料夾時,一個一個刪太多了,又浪費時間,所以可利用下面範例將目錄下的.svn資料夾都刪除。


範例:

package com.prc.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DelDirTest {

private static String dirPath = "E:/fileTest";

private static String[] delDirName = { ".svn" };

/**
* @param args
*/
public static void main(String[] args) {
try {
List<File> fileList = new ArrayList<File>();
visitedDirectory(dirPath, fileList);

//列出資料夾裡的檔案及資訊
for (File file : fileList) {
System.out.println(file.getName() + "  " + new FileInputStream(file).available());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void visitedDirectory(String path, List<File> fileList) {
File file = new File(path);
File[] subFile = file.listFiles();
for (int i = 0; i < subFile.length; i++) {
if (subFile[i].isDirectory()) {
if (delDirName[0].equals(subFile[i].getName())) {
deleteDirectory(subFile[i]);
} else {
visitedDirectory(subFile[i].getAbsolutePath(), fileList);
}
} else {
fileList.add(subFile[i]);
}
}
}

public static boolean deleteDirectory(File directory) {
if (!directory.exists() || !directory.isDirectory()) {
return false;
}

String[] files = directory.list();
for (int i = 0, len = files.length; i < len; i++) {
File f = new File(directory, files[i]);
if (f.isDirectory()) {
deleteDirectory(f);
} else {
f.delete();
}
}
return directory.delete();
}
}

JAVA Vector 與 ArrayList 差異

Vector:
thread save
速度較慢


ArrayList:
not thread save
速度較快

grep 多台 server logs

當要同時grep多台server的log時,可寫一隻shell幫忙去grep每台server的log出來,集中到一個檔案上做查詢。

範例:

grepPKIOSK.sh

echo $1
grep  --color=auto  $1 -n -A50 -B50 /NODUPFILE_1/AP05/PKIOSK/logs/nohup.out /NODUPFILE_1/AP07/PKIOSK/logs/nohup.out /NODUPFILE_1/AP09/PKIOSK/logs/nohup.out /NODUPFILE_2/AP06/PKIOSK/logs/nohup.out /NODUPFILE_2/AP08/PKIOSK/logs/nohup.out /NODUPFILE_2/AP10/PKIOSK/logs/nohup.out


$1:給的參數

-A50 (After 50 查到關鍵字的後50行)

-B50(Before 50 查到關鍵字的前50行)

執行

./grepPKIOSK.sh '2014-08-04' > kiosk20140804.log

將某一天的log查出來放置到kiosk20140804.log裡。


2014年9月8日 星期一

CSS margin 外邊距合併

範例1:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<style>
#div001 {
background-color:#FF0000;
border:1px solid;
width:100px;
height:100px;
margin:100px;
}

#div002 {
background-color:#00FF00;
border:1px solid;
width:100px;
height:100px;
margin:100px;
}

#divContent {
border:1px solid;
width:300px;
height:500px;
}
</style>
</head>
<body>
<div id="divContent">
<div id="div001">this is Div Contents</div>
<div id="div002">this id Div Contents</div>
</div>
</body>
</html>




此兩個div區塊margin屬性都設為100px,加起來應該是200px,但實際上還是只有100px。
因為瀏覽器實作了外邊距合併的功能:
上下兩個相鄰的矩形之間的外邊距會合併,合併後的外邊距會以外邊距較大的數值來做為外邊距設定的值。


範例2:


                #div001 {
background-color:#FF0000;
border:1px solid;
width:100px;
height:100px;
margin:200px;
}
#div002 {
background-color:#00FF00;
border:1px solid;
width:100px;
height:100px;
margin:100px;
}
#divContent {
border:1px solid;
width:500px;
height:500px;

}



<div id="divContent">
<div id="div001">this is Div Contents</div>
<div id="div002">this id Div Contents</div>

</div>









2014年9月3日 星期三

jquery div a 與 div > a 的差異

div a : 取得div內部的所有的超連結

div > a : 取得div父元素其下的超連結


範例:

<div id="div1">
<a id="a1">a1</a>
<a id="a2">a2</a>
<div id="div11">
<a id="a11">a11</a>
</div>
</div>
<div id="div2">
<span id="s1">
<a id="b1">b1</a>
<a id="b2">b2</a>
</span>
</div>



$('div a').css('color','red');





$('div > a').css('color','red');

div id="div2"底下的子元素只有span,所以span底下的超連結就不會被選到



jquery 密碼欄位是否顯示密碼


由於type屬性不能修改所以無法使用:

$('#ban').prop('type','text')


解決辦法:

1.先建立一個新的input 欄位加在原來input位置
2.把原來的值複製過去
3.把原來的input移除

範例:

javascript:

function showPassWord() {
if($('#checkPassWord').prop('checked')) {
$('<input type="text" id="ban"/>').val($('#ban').val()).insertAfter('#ban').prev().remove();
} else {
$('<input type="password" id="ban"/>').val($('#ban').val()).insertAfter('#ban').prev().remove();
}
}


html:

password:<input type="password" id="ban" />
<input type="checkbox" id="checkPassWord" onclick="showPassWord()">是否顯示密碼

2014年9月2日 星期二

Python 讀檔寫檔

Python讀檔與寫檔

使用open這function並給參數'r'或'w'

'r' -> 讀檔 readline()
'w' -> 寫檔 write()

以下為簡單的範例

fin = open('test.txt', 'r')
fout = open('E:/python/fileTest/fileTest.txt', 'w')
while True :
 i = fin.readline()
 fout.write(i)
 if i=='': break
 print(i,end='')
fin.close()
fout.close()



with讀檔

當使用with此函數,程式在離開with區塊後會自行關檔

with open("test.txt") as f:
 for line in f:
  print(line)