Monday, April 14, 2014

shell start and stop auto kill example


#---------------------------------
#INPUT FORMAT
#---------------------------------
#export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
#JAVA_HOME=/usr/jdk/instances/jdk1.6.0
#export JAVA_HOME
#JAVA_RUN=$JAVA_HOME/bin/java

LD_LIBRARY_PATH=/oracle/lib:/usr/lib:/lib:/usr/ccs/lib:/usr/local/lib:.:/arborbpusr/arborsit/Debbie/C_test/20140212/jniso
export LD_LIBRARY_PATH

CLFYLOG=/ArbSIT_share/arborbpusr/arborsit/Debbie/C_test
export CLFYLOG

# Setting the classes path while loading
CLASSPATH=${CLASSPATH}:../lib/asm-3.3.1.jar
CLASSPATH=${CLASSPATH}:../lib/jetty-server-8.1.12.v20130726.jar
CLASSPATH=${CLASSPATH}:../lib/jetty-util-8.1.12.v20130726.jar
CLASSPATH=${CLASSPATH}:../lib/commons-logging-1.1.3.jar
CLASSPATH=${CLASSPATH}:../lib/cxf-2.7.7.jar
CLASSPATH=${CLASSPATH}:../lib/log4j-1.2.17.jar
CLASSPATH=${CLASSPATH}:../lib/geronimo-activation_1.0.2_spec-1.1.jar
CLASSPATH=${CLASSPATH}:../lib/msv-core-2011.1.jar
CLASSPATH=${CLASSPATH}:../lib/geronimo-servlet_3.0_spec-1.0.jar
CLASSPATH=${CLASSPATH}:../lib/neethi-3.0.2.jar
CLASSPATH=${CLASSPATH}:../lib/javax.annotation-api-1.2.jar
CLASSPATH=${CLASSPATH}:../lib/slf4j-api-1.7.5.jar
CLASSPATH=${CLASSPATH}:../lib/jaxb-api-2.2.6.jar
CLASSPATH=${CLASSPATH}:../lib/slf4j-log4j12-1.7.5.jar
CLASSPATH=${CLASSPATH}:../lib/jaxb-impl-2.2.6.jar
CLASSPATH=${CLASSPATH}:../lib/stax2-api-3.1.1.jar
CLASSPATH=${CLASSPATH}:../lib/jetty-continuation-8.1.12.v20130726.jar
CLASSPATH=${CLASSPATH}:../lib/woodstox-core-asl-4.2.0.jar
CLASSPATH=${CLASSPATH}:../lib/jetty-http-8.1.12.v20130726.jar
CLASSPATH=${CLASSPATH}:../lib/wsdl4j-1.6.3.jar
CLASSPATH=${CLASSPATH}:../lib/jetty-io-8.1.12.v20130726.jar
CLASSPATH=${CLASSPATH}:../lib/xmlschema-core-2.0.3.jar
CLASSPATH=${CLASSPATH}:./ArborC.jar
export CLASSPATH


start()
{
 java -Dfile.encoding=UTF8 -Djava.library.path=/ArbSIT_share/arborbpusr/arborsit/Debbie/C_test/20140212/jniso -Dlog4j.configuration=/Users/arda/Documents/SparqWorkspace-arbor/ArborC/conf/log4j.properties com.foyatech.arbor.main.startMain /Users/arda/Documents/SparqWorkspace-arbor/ArborC/conf/ServiceSetting.xml&
echo $! >$ArborCWS_PIDFILE
}

shut()
{
  # This will kill the java process AND the JBoss AS java process.

  kill `cat $ArborCWS_PIDFILE`
}


 ArborCWS_PIDFILE=PID_FILE
        USAGE="Usage : `basename $0` [stop/start]"
        if [ $# -lt 1 ]; then
                echo  "$USAGE"
                exit
        fi
        if [ $1 = "start" ]; then
                start
        fi

        if [ $1 = "stop" ]; then
                shut
        fi

Wednesday, April 9, 2014

Google 與 LEGO (樂高) 合力打造一個 HTML5 網頁應用程式

Google 與 LEGO (樂高) 合力打造一個 HTML5 網頁應用程式,可以直接在瀏覽器中打造自己的創意積木喔!
※ 畫面是 3D 的,而且支援繁體中文。



https://www.buildwithchrome.com/



Wednesday, December 11, 2013

刪除 User 下的所有 Table 的方法

刪除 User 下的所有 Table 的方法

A. 使用下面語法產生 Drop 的 sql script

select 'drop table '||table_name||' cascade constraints;' from user_tables;

B. 將Drop Script 執行

Friday, January 18, 2013

產生圖片檔以及旋轉圖片範例

請參考 Google Drive MainClass.java

產生圖片檔以及旋轉圖片範例

HTML文章橫書轉直書

需要 JS 跟 CSS (Google Drive) 


用法:



(new Taketori()).set({fontFamily:'serif',togglable:true,multiColumnEnabled:true}).element('aaaa').toVertical(); 

參考網址
http://taketori.org/js.html

Monday, July 23, 2012

Java call procedure and get cursor back


//getDBUSERCursor is a stored procedure
String getDBUSERCursorSql = "{call getDBUSERCursor(?,?)}";
callableStatement = dbConnection.prepareCall(getDBUSERCursorSql);
callableStatement.setString(1, "mkyong");
callableStatement.registerOutParameter(2, OracleTypes.CURSOR);
 
// execute getDBUSERCursor store procedure
callableStatement.executeUpdate();
 
// get cursor and cast it to ResultSet
rs = (ResultSet) callableStatement.getObject(2);
 
// loop it like normal
while (rs.next()) {
 String userid = rs.getString("USER_ID");
 String userName = rs.getString("USERNAME");
}

Wednesday, June 13, 2012

HTML5 的 cache 設定

1. Add mime type for tomcat or web server

   
manifest
text/cache-manifest
   

2. HTML file
<  ! DOCTYPE    h t m l >
< h t m l    m a n i f e s t = " " >

3. cache.manifest


CACHE MANIFEST
CACHE:
/styles/m/mobile-css.css
/js/jquery/jquery-1.4.2.min.js
/styles/m/jquery.zweatherfeed.css
/scripts/m/jquery.zweatherfeed.min.js
/images/m/logo.jpg
/images/m/pic.jpg
NETWORK:
*
FALLBACK:
index.jsp


Wednesday, March 7, 2012

SQL Server Error: 防止儲存需要資料表重建的變更

出現錯誤訊息:『防止儲存需要資料表重建的變更』 解決方法其實很簡單:工具 - 選項 - Designers;把 防止儲存需要資料表重建的變更,打勾取消掉,

就可以了 如下圖


Monday, August 8, 2011

package com.softpower.utils;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Locale;

import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageOutputStream;


public class ImageUtils {
public static final int IMAGE_UNKNOWN = -1;
public static final int IMAGE_JPEG = 0;
public static final int IMAGE_PNG = 1;
public static final int IMAGE_GIF = 2;

/**
* Resizes an image
*
* @param imgName
* The image name to resize. Must be the complet path to the file
* @param type
* int
* @param maxWidth
* The image's max width
* @param maxHeight
* The image's max height
* @return A resized BufferedImage
*/
public static BufferedImage resizeImage(String imgName, int type, int maxWidth, int maxHeight) {
try {
return resizeImage(ImageIO.read(new File(imgName)), type, maxWidth, maxHeight);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

/**
* Resizes an image.
*
* @param image
* The image to resize
* @param maxWidth
* The image's max width
* @param maxHeight
* The image's max height
* @return A resized BufferedImage
* @param type
* int
*/
public static BufferedImage resizeImage(BufferedImage image, int type, int maxWidth, int maxHeight) {
Dimension largestDimension = new Dimension(maxWidth, maxHeight);

// Original size
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);

float aspectRatio = (float) imageWidth / imageHeight;

if (imageWidth > maxWidth || imageHeight > maxHeight) {
if ((float) largestDimension.width / largestDimension.height > aspectRatio) {
largestDimension.width = (int) Math.ceil(largestDimension.height * aspectRatio);
} else {
largestDimension.height = (int) Math.ceil(largestDimension.width / aspectRatio);
}

imageWidth = largestDimension.width;
imageHeight = largestDimension.height;
}

return createHeadlessSmoothBufferedImage(image, type, imageWidth, imageHeight);
}

/**
* Saves an image to the disk.
*
* @param image
* The image to save
* @param toFileName
* The filename to use
* @param type
* The image type. Use ImageUtils.IMAGE_JPEG to save as
* JPEG images, or ImageUtils.IMAGE_PNG to save as PNG.
* @return false if no appropriate writer is found
*/
public static boolean saveImage(BufferedImage image, String toFileName, int type) {
try {
return ImageIO.write(image, type == IMAGE_JPEG ? "jpg" : "png", new File(toFileName));
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* Saves an image to the disk.
*
* @param image
* The image to save
* @param toFileName
* The filename to use
* @param type
* The image type. Use ImageUtils.IMAGE_JPEG to save as
* JPEG images, or ImageUtils.IMAGE_PNG to save as PNG.
* @return false if no appropriate writer is found
*/
public static boolean saveImage(BufferedImage image, File toFileName, int type) {
try {
return ImageIO.write(image, type == IMAGE_JPEG ? "jpg" : "png", (toFileName));
} catch (IOException e) {
e.printStackTrace();
return false;
}
}

/**
* Compress and save an image to the disk. Currently this method only supports
* JPEG images.
*
* @param image
* The image to save
* @param toFileName
* The filename to use
* @param type
* The image type. Use ImageUtils.IMAGE_JPEG to save as
* JPEG images, or ImageUtils.IMAGE_PNG to save as PNG.
*/
public static void saveCompressedImage(BufferedImage image, String toFileName, int type) {
try {
if (type == IMAGE_PNG) {
throw new UnsupportedOperationException("PNG compression not implemented");
}

Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer;
writer = (ImageWriter) iter.next();

ImageOutputStream ios = ImageIO.createImageOutputStream(new File(toFileName));
writer.setOutput(ios);

ImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());

iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwparam.setCompressionQuality(0.7F);

writer.write(null, new IIOImage(image, null, null), iwparam);

ios.flush();
writer.dispose();
ios.close();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Creates a BufferedImage from an Image. This
* method can function on a completely headless system. This especially
* includes Linux and Unix systems that do not have the X11 libraries
* installed, which are required for the AWT subsystem to operate. This method
* uses nearest neighbor approximation, so it's quite fast. Unfortunately, the
* result is nowhere near as nice looking as the
* createHeadlessSmoothBufferedImage method.
*
* @param image
* The image to convert
* @param w
* The desired image width
* @param h
* The desired image height
* @return The converted image
* @param type
* int
*/
public static BufferedImage createHeadlessBufferedImage(BufferedImage image, int type, int width,
int height) {
if (type == ImageUtils.IMAGE_PNG && hasAlpha(image)) {
type = BufferedImage.TYPE_INT_ARGB;
} else {
type = BufferedImage.TYPE_INT_RGB;
}

BufferedImage bi = new BufferedImage(width, height, type);

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
bi.setRGB(x, y, image.getRGB(x * image.getWidth() / width, y * image.getHeight() / height));
}
}

return bi;
}

/**
* Creates a BufferedImage from an Image. This
* method can function on a completely headless system. This especially
* includes Linux and Unix systems that do not have the X11 libraries
* installed, which are required for the AWT subsystem to operate. The
* resulting image will be smoothly scaled using bilinear filtering.
*
* @param source
* The image to convert
* @param w
* The desired image width
* @param h
* The desired image height
* @return The converted image
* @param type
* int
*/
public static BufferedImage createHeadlessSmoothBufferedImage(BufferedImage source, int type,
int width, int height) {
if (type == ImageUtils.IMAGE_PNG && hasAlpha(source)) {
type = BufferedImage.TYPE_INT_ARGB;
} else {
type = BufferedImage.TYPE_INT_RGB;
}

BufferedImage dest = new BufferedImage(width, height, type);

int sourcex;
int sourcey;

double scalex = (double) width / source.getWidth();
double scaley = (double) height / source.getHeight();

int x1;
int y1;

double xdiff;
double ydiff;

int rgb;
int rgb1;
int rgb2;

for (int y = 0; y < height; y++) {
sourcey = y * source.getHeight() / dest.getHeight();
ydiff = scale(y, scaley) - sourcey;

for (int x = 0; x < width; x++) {
sourcex = x * source.getWidth() / dest.getWidth();
xdiff = scale(x, scalex) - sourcex;

x1 = Math.min(source.getWidth() - 1, sourcex + 1);
y1 = Math.min(source.getHeight() - 1, sourcey + 1);

rgb1 = getRGBInterpolation(source.getRGB(sourcex, sourcey), source.getRGB(x1, sourcey),
xdiff);
rgb2 = getRGBInterpolation(source.getRGB(sourcex, y1), source.getRGB(x1, y1), xdiff);

rgb = getRGBInterpolation(rgb1, rgb2, ydiff);

dest.setRGB(x, y, rgb);
}
}

return dest;
}

private static double scale(int point, double scale) {
return point / scale;
}

private static int getRGBInterpolation(int value1, int value2, double distance) {
int alpha1 = (value1 & 0xFF000000) >>> 24;
int red1 = (value1 & 0x00FF0000) >> 16;
int green1 = (value1 & 0x0000FF00) >> 8;
int blue1 = (value1 & 0x000000FF);

int alpha2 = (value2 & 0xFF000000) >>> 24;
int red2 = (value2 & 0x00FF0000) >> 16;
int green2 = (value2 & 0x0000FF00) >> 8;
int blue2 = (value2 & 0x000000FF);

int rgb = ((int) (alpha1 * (1.0 - distance) + alpha2 * distance) << 24)
| ((int) (red1 * (1.0 - distance) + red2 * distance) << 16)
| ((int) (green1 * (1.0 - distance) + green2 * distance) << 8)
| (int) (blue1 * (1.0 - distance) + blue2 * distance);

return rgb;
}

/**
* Determines if the image has transparent pixels.
*
* @param image
* The image to check for transparent pixel.s
* @return true of false, according to the result
*/
public static boolean hasAlpha(Image image) {
try {
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
pg.grabPixels();

return pg.getColorModel().hasAlpha();
} catch (InterruptedException e) {
return false;
}
}
}

Friday, May 20, 2011

HTML5 Mobile Web 系列:小圖示請使用 Data URI

引用網址 :http://blog.ericsk.org/archives/1436/trackback


使用 Data URI 可以節省 request 的數量。


首先以一個直接的例子來說明什麼是 Data URI,假設我有一張 PNG 圖片,像是這樣:


在網頁上嵌入的語法很簡單,就是 <img src="圖片路徑" width="寬" height="高">,但是這樣一來瀏覽器便需要多送出一個 reuqest 取得這張圖片,如果一個頁面上的圖片很多,對於網頁存取的速度就會有很深的影響(尤其是手機上的瀏覽器),除了可以使用 CSS Sprites 的技巧減少圖片存取數量,也可以使用 Data URI 將圖片編碼成字串後,直接嵌入在 HTML 或 CSS 檔案內容裡,作法如下:



  1. 首先將圖片以 base64 編碼成字串,以上圖為例,編碼後的字串為:

    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
    AAAASUVORK5CYII=

  2. 嵌入圖片時,語法修改為<img src="data:image/png;base64,你的base64字串" width="" height="">,要注意 bas64 字串不能有斷行,必須要接起來,效果如下圖所示:(IE 使用者若看不到,請升級至 IE9 以上,並確定沒有按到相容模式


  3. 如果是用在 CSS 檔案裡,原本若寫成 background-image: url(/path/to/image.png),則可以修改成 background-image: url(data:image/png;base64,圖片的base64字串)

  4. 當然這個方法也可以用在 gif, jpg 等 web 上可以使用的檔案,記得將 image/png 這個 MIME-type 改成對應的


不過 Data URI 不一定在每個圖片的顯示都適用,而且太過度地使用也可能會造成 HTML 檔案或是 CSS 檔案的肥大(如果 html, css 檔案也有作快取那就還好),總之就看網站設計者如何巧妙地運用 Data URI 的方式來呈現資料,以減輕 browser 發送網路存取的負擔囉。


註: Base64 編碼器可以在網路上搜尋 base64 encoder 就有很多資源了


番外篇


如果使用了 Data URI,那還可以將圖片 cache 在用戶端的 localStorage 裡面,像是這樣:


<img src="" id="the-img">
<script src="jquery.min.js"></script>
<!-- See: http://www.webtoolkit.info/javascript-base64.html -->
<script src="base64.js"></script>
<script>
if (!localStorage.theImg) {
  $.get('/path/to/img.png', function(data) {
    var img = Base64.encode(data);
    localStorage.theImg = 'data:image/png;base64,' + img;
    $('#the-img').attr('src', localStorage.theImg);
  });
} else {
  $('#the-img').attr('src', localStorage.theImg);
}
</script>


 

歷史上的今天

Wednesday, March 16, 2011

Date Only and Time Only data types in SQL Server 2005 (without the CLR)

來源:http://weblogs.sqlteam.com/jeffs/archive/2007/10/31/sql-server-2005-date-time-only-data-types.aspx

In this post, I showed a simple way to create simple but useful Date and Time user-defined data types in SQL Server 2000. Here's how to do it in SQL Server 2005, without the need for CLR types or anything fancy.

First, we must create two user defined data types:

create type Date from dateTime
create type Time from dateTime

So, internally (and externally to our clients), these types are really just DateTime. But, we will apply some rules to these types so that the Date data type will always be constrained to a time exactly at midnight, and the the Time data type will always be at the "base date", or 1900-01-01:

create rule DateOnlyRule as
dateAdd(dd,datediff(dd,0,@DateTime),0) = @DateTime

go

create rule TimeOnlyRule as
datediff(dd,0,@DateTime) = 0

go

Finally, we call sp_bindrule to bind the rules to the data types:

EXEC sp_bindrule 'DateOnlyRule', 'Date'
EXEC sp_bindrule 'TimeOnlyRule', 'Time'

That's it! Now, we can create a table that uses our brand-new data types:

create table Trans
(
TranID int identity primary key,
TranAmount money not null,
TranDate Date not null,
TranTime Time not null
)

Notice that TranDate and TranTime are two separate columns here. If we try to insert data, our rules will ensure that our TranDate and TranTime columns only contain the appropriate data, and by doing so we can simply calculate TranDate + TranTime to get the transactions DateTime.

The following inserts will succeed:

insert into Trans (TranAmount, TranDate, TranTime)
values (200, '2005-01-01', '09:00:00 AM')

insert into Trans (TranAmount, TranDate, TranTime)
values (400, '2005-01-03', '7:50:30 PM')

But this will fail, since our rules are violated (getdate() returns the current date and the time):

insert into Trans (TranAmount, TranDate, TranTime)
values (200, getdate(), getdate())

Msg 513, Level 16, State 0, Line 1
A column insert or update conflicts with a rule imposed by a previous CREATE RULE statement. The statement was terminated. The conflict occurred in database 'PlayGround', table 'dbo.Trans', column 'TranDate'.
The statement has been terminated.

Finally, we can select from our table and simply add the two columns together to get each transaction's DateTime:

select *, TranDate + TranTime as TranDateTime
from Trans

TranID TranAmount TranDate TranTime TranDateTime
------- ----------- ------------------- ------------------- -------------------
1 200.00 2005-01-01 00:00:00 1900-01-01 09:00:00 2005-01-01 09:00:00
2 400.00 2005-01-03 00:00:00 1900-01-01 19:50:30 2005-01-03 19:50:30

(2 row(s) affected)

The nice advantage of doing this is that you can quickly and efficiently select all transactions for a single day like this:

select * from Trans
where TranDate = '2005-01-01'

If we stored the Date and Time in the same column, we'd need to use a less efficient range:

select * from Trans
where TranDate >= '2005-01-01' and TranDate < '2005-01-02'

SQL 2008 does finally implement true Date and Time data types, but until then, I hope this gives you some ideas to play with.

Notes:

* If you do wish to break apart DateTime data into two columns, another option is to simply use a single, standard DateTime column but then define two extra computed columns in your table, one that returns just the Date, another that returns just the Time. Then, you can index those computed columns and reference them easily and efficiently. If you truly wish to store just a date or just a time, however, these user defined data types are a great way to do it. At the end of this SQLTeam article there's a good example demonstrating this.

* You could also just use the expressions for the rules in CHECK constrains on individual table columns, instead of creating the user defined data types and rules. As Books On Line states, CREATE RULE will at some point be removed from future versions of SQL Server, so you may wish to avoid using it.

see also:

* Working with Time Spans and Durations in SQL Server
* Group by Month (and other time periods)
* Working with Date and/or Time values in SQL Server: Don't Format, Don't Convert -- just use DATETIME
* Data Types -- The Easiest Part of Database Design
* How to format a Date or DateTime in SQL Server
* Breaking apart the DateTime datatype -- Separating Dates from Times in your Tables
* Date Only and Time Only data types in SQL Server 2005 (without the CLR)

Thursday, February 17, 2011

轉貼:Milestone 刷非官方真正的 Android 2.2 及問題討論 (補上超頻教學)

文章來源 :http://lbear.pixnet.net/blog/post/19726924




  話說,原本讓使用者相信,會是在 Google N1 升級 2.2 後,就開放升級的 Milestone,竟然讓所有人跌破眼鏡,到了現在都還沒釋出官方的 2.2 ( HTC Desire 都正式升級 2.2 了,三星那隻悲哀的哀 9000,也即將釋出 2.2 官方版了 ) 真是讓 Milestone 的使用者淦到沒力加無言以對,

Wednesday, January 12, 2011

javascript數字Format處理

var num = 10;
var result = num.toFixed(2); // result will equal 10.00

num = 930.9805;
result = num.toFixed(3); // result will equal 930.981

num = 500.2349;
result = num.toPrecision(4); // result will equal 500.2

num = 5000.2349;
result = num.toPrecision(4); // result will equal 5000

num = 555.55;
result = num.toPrecision(2); // result will equal 5.6e+2



function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}

Thursday, October 28, 2010

Alcatel T07AW 完全破解攻略

Alcatel T07AW 完全破解攻略-不用Console連接線就可以開啟 Wireless
分類:PC
2007/11/06 10:49
Alcatel T07AW 完全破解攻略-不用Console連接線就可以開啟 Wireless
分享幾個重點

1.自己的IP必須在192.168.1.X的網域之下才進的去控管介面
2.要把DHCP模式打開
3.無線網路部分必須設成PPPOE模式且用硬體撥接
一個建議:最好用 telnet://192.168.1.1/ 的方式進去,有許多選項http是看不到的。
先說明一下http模式下DHCP打開的方法
Setup-->LAN,選Enable DHCP Server
再來是無線網路PPPOE的硬撥

Setup-->WAN,右邊選edit,第一頁沒有要改的,選next,第二頁選PPPOE,第三頁輸入帳號密碼即可
可以的話,最好把SSID改掉,並限定特定網卡才能使用你的無線網路。



破解程序:
1. 檢視 T07AW 前面板之 AP 燈號為 "熄滅" 狀態, 確認 T07AW 之 Wireless 功能尚未啟動.
2. 以 Web 連線 (網址 "http://192.168.1.1/", 帳號 "cht" & 密碼 {"chtnadsl"|"chtcadsl"|"chtsadsl"}) 方式登入 T07AW.
3. 在 Browser 網址列輸入 "http://192.168.1.1/snmpconfig.html", 將 SNMP Agent 設定為 "Disable", 按下 "Apply".
4. 使用 "Management" / "Save/Reboot" 功能儲存設定值, 在 T07AW 重新開機後, 重新以 Web 連線方式登入 T07AW.
5. 在 Browser 網址列輸入 "http://192.168.1.1/wlcfg.wl?wlEnbl=1".
6. 如果 步驟 5. 操作正確 的話, 此時 T07AW 前面板之 AP 燈號應該會轉變為 "恆亮" 狀態.
7. 在 Browser 網址列輸入 "http://192.168.1.1/", 左側的功能設定選單應該會出現 "Wireless" 選項.

註記:
1. 由於機房端是以 SNMP over AAL5 透過 PVC 0/16 (在 T07AW 開機時, 由 SNMP Agent 自動開啟) 與 T07AW 之 SNMP Agent 連線進行遠端控制, 因此只要將 SNMP Agent 設為 "Disable", 即可防止機房端利用遠端控制來關閉 Wireless 功能.
2. Wireless 功能設定("Basic"|"Security"|"Access Control"|"Association List")更改完成後, 記得使用 "Management" / "Save/Reboot" 功能儲存設定.
3. 本破解程序已在南區第一批 (P/N:T07L022.04, Software Version:T07L022.04_2.08_S) 上試驗成功.
4. 請在開啟 Wireless 功能成功後, 回報 T07AW 的 P/N (在 T07AW 底部可以看到) 與 Software Version.
5. 因為本破解程序會影響到某 ISP 業者的收入, 可能會導致本文從本站上消失... 請把握時機!

<補充>
以下是一些主頁面上找不到之其它功能設定頁面:
NAT -- Virtual Servers Setup
"http://192.168.1.1/scvrtsrv.cmd?action=view"

NAT -- DMZ Host
"http://192.168.1.1/scdmz.html"

MAC Filtering Setup
"http://192.168.1.1/scmacflt.cmd?action=view"

Outgoing IP Filtering Setup
"http://192.168.1.1/scoutflt.cmd?action=view"

Incoming IP Filtering Setup
"http://192.168.1.1/scinflt.cmd?action=view"

Quality of Service Setup
"http://192.168.1.1/qoscls.cmd?action=view"

Routing -- RIP Configuration
"http://192.168.1.1/ripcfg.cmd?action=view"

ADSL driver and PHY status
"http://192.168.1.1/adsltongdiag.cmd"

Access Control -- Services
"http://192.168.1.1/scsrvcntr.cmd?action=view"

SNMP - Configuration
"http://192.168.1.1/snmpconfig.html"

DNS Server Configuration
"http://192.168.1.1/dnscfg.html"

Tools -- Update Software
"http://192.168.1.1/upload.html"

(以 Bridge 模式為準, 部份設定頁面在 PPPoE 或是 MER 模式才會出現)

隱藏 Wireless 之 SSID
在 Browser 網址列輸入 "http://192.168.1.1/wlcfg.wl?wlHide=1", 再使用 "Management" / "Save/Reboot" 功能儲存設定.

Reset Default Settings (適用於帳號 "cht" 之密碼未知的情況)
以 Web 連線 (網址 "http://192.168.1.1/", 使用帳號 "user" & 密碼 "user") 方式登入 T07AW, 在網址列輸入 "http://192.168.1.1/defaultsettings.html", 然後按下 "Reset Default Settings".






另一個方法


中華電信黑龜破解無線開啟
中華電信黑龜破解無線開啟,如果請中華電信開1個月要加99元,家裡面中華電信數據機(黑龜)如果有1支天線的版本只要花60元左右的材料費
買幾個電子零件焊成(圖1console線 電路圖)在進入數據幾裡面開啟就可以使用無線網路了


中華電信黑龜Alcatel T07AW console線進入T07AW破解無線
需以 Console 連接線
使用 Hyper Terminal 來登入 Alcatel T07AW (115200,N,8,1) 進行下列操作.
一.
Login: cht
Password:
"chtnadsl" or "chtcadsl" or "chtsadsl"
二.
Main Menu
1. ADSL Link State
2. LAN
3. WAN
4. DNS Server
5. Route Setup
6. NAT
7. Firewall
8. Quality Of Service
9. Management
10. Passwords
11. Reset to Default
12. Save and Reboot
13. Exit
14. Wireless
-> 14
三.
Wireless Menu
1. Basic
2. Security
3. Save and Reboot
4. Exit
/Wireless -> 1
四.
Wireless Basic Menu
1. SSID
2. Channel
3. Radio Power(mW)
4. Multicast Rate
5. Basic Rate
6. Exit
/Wireless/Basic -> 7
Wireless is Disabled
五.
Enable/Disable Wireless? Confirm [1-enable,2-disable] ==> 1
br0: port 3(wl0) entering learning state
br0: topology change detected, propagating
br0: port 3(wl0) entering forwarding state
br0: port 3(wl0) entering disabled state
Setting country code "TW"
br0: port 3(wl0) entering learning state
br0: topology change detected, propagating
br0: port 3(wl0) entering forwarding state
channel selected 6
wl0: Device or resource busy
wme Set WME (Wireless Multimedia Extensions) mode (0=off, 1=on)
channel selected 6
br0: port 3(wl0) entering disabled state
br0: port 3(wl0) entering learning state
br0: topology change detected, propagating
br0: port 3(wl0) entering forwarding state
br0: port 3(wl0) entering disabled state
br0: port 3(wl0) entering learning state
br0: topology change detected, propagating
br0: port 3(wl0) entering forwarding state
device wl0 is already a member of a bridge; can't enslave it to bridge br0.
******** You must reboot after changing any setting. ********
Hit to continue

六.
Wireless Basic Menu
1. SSID
2. Channel
3. Radio Power(mW)
4. Multicast Rate
5. Basic Rate
6. Exit
/Wireless/Basic -> 6
七.
Wireless Menu
1. Basic
2. Security
3. Save and Reboot
4. Exit
/Wireless -> 3

Save current configuration and reboot? Confirm [1-yes,2-no] ==> 1
PID Uid VmSize Stat Command
1 cht 212 S init
2 cht SWN [ksoftirqd/0]
3 cht SW< [events/0]
4 cht SW< [khelper]
5 cht SW< [kblockd/0]
17 cht SW [pdflush]
18 cht SW [pdflush]
19 cht SW [kswapd0]
20 cht SW< [aio/0]
25 cht SW [mtdblockd]
34 cht 268 S -sh
58 cht 832 S cfm
102 cht 180 S pvc2684d
221 cht 752 S telnetd
222 cht 776 S sshd
223 cht 788 S snmp
224 cht 876 S httpd
389 cht 248 S sh -c ps > /var/pslist
390 cht 236 R ps
Number of processes: 19
12:01am up 1 min,
load average: 1 min:0.25, 5 min:0.08, 15 min:0.02
total used free shared buffers
Mem: 6016 5500 516 0 332
Swap: 0 0 0
Total: 6016 5500 516
kill snmp process...
iptables v1.2.11: can't initialize iptables table `nat': iptables who? (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
Remaining modules:
wl 360064 0 - Live 0xc00e9000
bcm_enet 18608 0 - Live 0xc002b000
bcmprocfs 12288 0 - Live 0xc000f000
adsldd 119472 0 - Live 0xc0054000
blaadd 5904 0 - Live 0xc000c000
atmapi 48144 2 adsldd,blaadd, Live 0xc001e000
Memory info:
Number of processes: 18
12:01am up 1 min,
load average: 1 min:0.25, 5 min:0.08, 15 min:0.02
total used free shared buffers
Mem: 6016 5588 428 0 360
Swap: 0 0 0
Total: 6016 5588 428

The system shell is being reset. Please wait...
在 Wireless 功能開啟後, 再以 Web 連線方式登入 Alcatel T07AW, 就可以看見多出一個 "Wireless" 設定選項...








......................................................................
.



破解程序:
1. 檢視 T07AW 前面板之 AP 燈號為 "熄滅" 狀態, 確認 T07AW 之 Wireless 功能尚未啟動.
2. 以 Web 連線 (網址 "http://192.168.1.1/", 帳號 "cht" & 密碼 {"chtnadsl"|"chtcadsl"|"chtsadsl"}) 方式登入 T07AW.
3. 在 Browser 網址列輸入 "http://192.168.1.1/snmpconfig.html", 將 SNMP Agent 設定為 "Disable", 按下 "Apply".
4. 使用 "Management" / "Save/Reboot" 功能儲存設定值, 在 T07AW 重新開機後, 重新以 Web 連線方式登入 T07AW.
5. 在 Browser 網址列輸入 "http://192.168.1.1/wlcfg.wl?wlEnbl=1".
6. 如果 步驟 5. 操作正確 的話, 此時 T07AW 前面板之 AP 燈號應該會轉變為 "恆亮" 狀態.
7. 在 Browser 網址列輸入 "http://192.168.1.1/", 左側的功能設定選單應該會出現 "Wireless" 選項.

註記:
1. 由於機房端是以 SNMP over AAL5 透過 PVC 0/16 (在 T07AW 開機時, 由 SNMP Agent 自動開啟) 與 T07AW 之 SNMP Agent 連線進行遠端控制, 因此只要將 SNMP Agent 設為 "Disable", 即可防止機房端利用遠端控制來關閉 Wireless 功能.
2. Wireless 功能設定("Basic"|"Security"|"Access Control"|"Association List")更改完成後, 記得使用 "Management" / "Save/Reboot" 功能儲存設定.
3. 本破解程序已在南區第一批 (P/N:T07L022.04, Software Version:T07L022.04_2.08_S) 上試驗成功.
4. 請在開啟 Wireless 功能成功後, 回報 T07AW 的 P/N (在 T07AW 底部可以看到) 與 Software Version.
5. 因為本破解程序會影響到某 ISP 業者的收入, 可能會導致本文從本站上消失... 請把握時機!

<補充>
以下是一些在 T07AW 主頁面上找不到之其它功能設定頁面:
NAT -- Virtual Servers Setup
"http://192.168.1.1/scvrtsrv.cmd?action=view"

NAT -- DMZ Host
"http://192.168.1.1/scdmz.html"

MAC Filtering Setup
"http://192.168.1.1/scmacflt.cmd?action=view"

Outgoing IP Filtering Setup
"http://192.168.1.1/scoutflt.cmd?action=view"

Incoming IP Filtering Setup
"http://192.168.1.1/scinflt.cmd?action=view"

Quality of Service Setup
"http://192.168.1.1/qoscls.cmd?action=view"

Routing -- RIP Configuration
"http://192.168.1.1/ripcfg.cmd?action=view"

ADSL driver and PHY status
"http://192.168.1.1/adsltongdiag.cmd"

Access Control -- Services
"http://192.168.1.1/scsrvcntr.cmd?action=view"

SNMP - Configuration
"http://192.168.1.1/snmpconfig.html"

DNS Server Configuration
"http://192.168.1.1/dnscfg.html"

Tools -- Update Software
"http://192.168.1.1/upload.html"

(以 Bridge 模式為準, 部份設定頁面在 PPPoE 或是 MER 模式才會出現)

隱藏 Wireless 之 SSID
在 Browser 網址列輸入 "http://192.168.1.1/wlcfg.wl?wlHide=1", 再使用 "Management" / "Save/Reboot" 功能儲存設定.

Reset Default Settings (適用於帳號 "cht" 之密碼未知的情況)
以 Web 連線 (網址 "http://192.168.1.1/", 使用帳號 "user" & 密碼 "user") 方式登入 T07AW, 在網址列輸入 "http://192.168.1.1/defaultsettings.html", 然後按下 "Reset Default Settings".

<註記>
To - 2.12 版之使用者 : 適用於 2.12 版之破解方法早已問世多時, 只因 CHT 尚未將 2.12 版大量鋪貨到市面上, 再加上未經本人同意授權使用而逕自轉貼本篇文章全文之網友甚多, 因此現階段暫時不考慮公布出來, 請各位網友不要再透過各種管道來打探消息了.
To - Foxconn 大頭們 : 既然採用 Linux 作為 T07A/T07AW 之 OS, 就應該遵循 GPL License 之規範, 多看看人家 ComTrend 是如何作的吧!

Thursday, April 8, 2010

iText將 HTML 語法轉換成 PDF 文件


<%@page import="java.io.*" %>
<%@page import="java.net.*" %>
<%@page import="java.util.ArrayList" %>
<%@page import="com.lowagie.text.*" %>
<%@page import="com.lowagie.text.pdf.*" %>
<%@page import="com.lowagie.text.html.simpleparser.*" %>
<%@page contentType="application/pdf;charset=Big5" %>

<%
Document document = document = new Document( PageSize.A4, 0, 0, 0, 0 );

try
{
PdfWriter.getInstance( document, new FileOutputStream( request.getRealPath("") + "/1.pdf" ) );
document.open();

// HTML 語法
StringBuffer simpleHtmlCode = new StringBuffer("");
simpleHtmlCode.append( "你好, 歡迎光臨
" );
simpleHtmlCode.append( "我是 昭佑.天翔
" );
simpleHtmlCode.append( "祝你 新年快樂 !!
" );
simpleHtmlCode.append( "
" );
simpleHtmlCode.append( ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ "
歡迎光臨Hello World
歡迎光臨
"
);
simpleHtmlCode.append("");

// 將 StringBuffer 轉換成 StringReader
StringReader stringReader = new StringReader(simpleHtmlCode.toString());

// 載入字型
FontFactory.register( request.getRealPath("") + "/Font/kaiu.ttf" );

// 設定 HTML 標籤樣式
StyleSheet st = new StyleSheet();
st.loadTagStyle("body", "face", "標楷體"); // 字型
st.loadTagStyle("body", "size", "8px"); // 字體大小
st.loadTagStyle("body", "encoding", "Identity-H"); // 顯示中文字

// 產生 HTML 轉換物件
HTMLWorker worker = new HTMLWorker(document);

// 輸出 HTML 到 PDF
ArrayList p = HTMLWorker.parseToList( stringReader, st );
for( int k = 0; k < p.size(); k++ )
document.add((Element)p.get(k));

document.close();

response.sendRedirect( "1.pdf" );
}
catch(Exception e)
{
out.println( "錯誤 : "+ e.toString() );
}

document.close();
%>

Wednesday, October 14, 2009

手刀是犯規的

昨晚夢見我再跟人家對打跆拳道,我做了一個起腳踢的假動作引得對手起腳,
趁勢我繞到側面打算起腳出擊但對手打算抱住我,這時我只好使出"手刀",
cow~ 怎會麼會用手刀,不幸的事發生了,
現實的我也真的使出手刀....手腕直接命中書桌的桌角,
就這樣.....比賽結束了,因為我得起床冰敷貼"痠痛好哩哩"

Wednesday, June 24, 2009

去過的職業球場-3

TOKYO Dome - 巨人

說到這就感傷了,因為…先發投手已經回台灣了,就是東京巨人姜建銘,這一場正好是他先發敗投(2006年)

對到林威助的阪神虎,我跟霸子2人站在中間的販賣區以為比賽結束,結果林威助上來代打,

日本人看球很團結即使沒有位子也會一起站一區跟野餐一樣一起看,個別球員的加油聲也都不一樣

 

東京巨蛋球票東京巨蛋-1   東京巨蛋-3

阿猴先發喔

猴子先發

 

橫濱-海灣之星

這次是(2005年)經過橫濱看到大家都一直走進去,這也是我第一次看國外的職棒,但很不幸的我沒看完

因為….自由席(就是沒座位拉)加上一半才進去,看到我的位置沒…我站在外野最後面的牆前面,再加上天氣暴熱,

剛從八景島海洋樂園回來,腳已經不行了…看了幾局就先行離場(我也對日本職棒不熟)

 

橫濱棒球場-1 橫濱棒球場-2 橫濱棒球場-3

去過的職業球場-2

New York – Yankee (老球場)

趕在老球場拆掉之前趕緊去見證一下歷史,但是沒能選在阿民先發的日子,下面是正在蓋的球場

NYY-4 NYY-5 NYY-2

派第特對到老虎還是輸球收場,再找位子的時候一位老先生幫我拿可樂結果打翻了害我很內疚,

所以7局唱God bless America 他拿出國旗我還幫他一起拿一起收;但是切記要穿夾克去看球,白天天氣很好我就以為不會冷,

外野的風吹來冷到我一直發抖

NYY-1  NYY-3

Abreu 又是我的Fantansy Player 打的不怎樣

NYY-7

Tuesday, June 23, 2009

去過的職業球場-1

Boston -Celtics 

2008 nba playoff 第一輪對上老鷹,因為不確定會打幾場,因緣際會Boston出差,感謝一起去的老闆緊急在網路上買了票,

整場滿場的觀眾,座位在最上面(整各場館沒人在我後面了),大家以為會很遠很小,其實不然看的還漫清楚的,

Celtic-1Celtic-2 Celtic-4

真的要去現場看,整個氣氛超好的; 倒數第2張那個復古的人Gino是隱藏版的人物,球隊領先主場才會出現的,

最後是結束後溜下去照的,後來發現裡面好像有KG喔

Celtic-3  Celtic-5Celtic-6

 

 

Boston –Red Sox

同場加演,也要感謝老闆緊急加演紅襪對藍鳥,這次就坐的比較近,一樣也是超多人,

投手是 AJ Burnett + BJ Ryan 整個紅襪打線被封鎖,

老球場比較有溫馨感,雖然結果輸了,但是前面的小孩一直在帶動波浪舞,後來大家都在幫他吶喊請大家站起來,

當然…波浪從我們這裡起來繞了2圈多

Fenway-1 Fenway-2 Fenway-3

著名的 綠色怪物 , 台灣都是洋基不然應該多買旗子回來插

Fenway-6 Fenway-7 Fenway-8

Fenway-rios

Alex Rios 那場打出HR,他那時還在我的 Fantansy Player,但是不能拍手拍出來

Wednesday, May 6, 2009

T-SQL判斷Table Column存不存在

IF (SELECT count(*)  FROM INFORMATION_SCHEMA.COLUMNS  WHERE TABLE_NAME = 'TableName' AND COLUMN_NAME='columnName')>0
  BEGIN
    alter table Event ADD StoreAmount [int] NOT NULL DEFAULT 0
  END